コード例 #1
0
 public static String[] getNSServiceNameAndMessageNameArray(
     Definition wsdlDefinition,
     String serviceName,
     String portName,
     String bindingName,
     String opName) {
   Map<?, ?> services = wsdlDefinition.getServices();
   Set<?> serviceKeys = services.keySet();
   for (Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) {
     QName serviceKey = (QName) it.next();
     if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) {
       Service service = (Service) services.get(serviceKey);
       Map<?, ?> ports = service.getPorts();
       Set<?> portKeys = ports.keySet();
       for (Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) {
         String portKey = (String) it2.next();
         if (portName != null && portKey.contentEquals(portName)) {
           Port port = (Port) ports.get(portKey);
           Binding wsdlBinding = port.getBinding();
           PortType portType = wsdlBinding.getPortType();
           String ns = portType.getQName().getNamespaceURI();
           List<?> operations = portType.getOperations();
           for (Iterator<?> it3 = operations.iterator(); it3.hasNext(); ) {
             Operation operation = (Operation) it3.next();
             if (opName != null && operation.getName().contentEquals(opName)) {
               return new String[] {ns, serviceName, portName};
             }
           }
         }
       }
     }
   }
   return null;
 }
コード例 #2
0
ファイル: WSDLRefValidator.java プロジェクト: noshlin/cxf
  private XNode getXNode(Binding binding) {
    XDef xdef = new XDef();
    xdef.setTargetNamespace(binding.getQName().getNamespaceURI());

    XBinding bNode = new XBinding();
    bNode.setName(binding.getQName().getLocalPart());
    bNode.setParentNode(xdef);
    return bNode;
  }
コード例 #3
0
ファイル: BuilderTest.java プロジェクト: KenCloud2013/soap-ws
 @Test
 public void testLoadSnowboard_Bug_OP_851() throws WSDLException {
   URL wsdlUrl = ResourceUtils.getResourceWithAbsolutePackagePath("builder", "snowboard.wsdl");
   SoapBuilder builder = new SoapBuilder(wsdlUrl);
   for (Object b : builder.getDefinition().getAllBindings().values()) {
     Binding binding = (Binding) b;
     for (BindingOperation op : (List<BindingOperation>) binding.getBindingOperations()) {
       OperationWrapper wrapper = SoapBuilder.getOperation(binding, op);
       assertNotNull(wrapper);
     }
   }
 }
コード例 #4
0
ファイル: WSDLConverter.java プロジェクト: Zannabis/jolie
  private void convertPort(Port port) throws IOException {
    String comment = "";
    String name = port.getName();
    String protocol = "soap";
    String location = "socket://localhost:80/";
    if (port.getDocumentationElement() != null) {
      comment = port.getDocumentationElement().getNodeValue();
    }
    List<ExtensibilityElement> extElements = port.getExtensibilityElements();
    for (ExtensibilityElement element : extElements) {
      if (element instanceof SOAPAddress) {
        location = ((SOAPAddress) element).getLocationURI().toString();
        StringBuilder builder = new StringBuilder();
        builder
            .append("soap {\n")
            .append("\t.wsdl = \"")
            .append(definition.getDocumentBaseURI())
            .append("\";\n")
            .append("\t.wsdl.port = \"")
            .append(port.getName())
            .append("\"\n}");
        protocol = builder.toString();

      } else if (element instanceof HTTPAddress) {
        location = ((HTTPAddress) element).getLocationURI().toString();
        protocol = "http";
      }
    }
    try {
      URI uri = new URI(location);
      uri =
          new URI(
              "socket",
              uri.getUserInfo(),
              uri.getHost(),
              (uri.getPort() < 1) ? 80 : uri.getPort(),
              uri.getPath(),
              uri.getQuery(),
              uri.getFragment());
      location = uri.toString();
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
    Binding binding = port.getBinding();
    PortType portType = binding.getPortType();
    convertPortType(portType, binding);
    outputPorts.put(
        name,
        new OutputPort(name, location, protocol, portType.getQName().getLocalPart(), comment));
  }
コード例 #5
0
 public static ExtensibilityElement getBindingExtension(Binding binding) {
   Collection bindings = new ArrayList();
   CollectionsX.filter(bindings, binding.getExtensibilityElements(), HTTPBinding.class);
   CollectionsX.filter(bindings, binding.getExtensibilityElements(), SOAPBinding.class);
   CollectionsX.filter(bindings, binding.getExtensibilityElements(), SOAP12Binding.class);
   if (bindings.size() == 0) {
     return null;
   } else if (bindings.size() > 1) {
     // exception if multiple bindings found
     throw new IllegalArgumentException("Multiple bindings: " + binding.getQName());
   } else {
     // retrieve the single element
     return (ExtensibilityElement) bindings.iterator().next();
   }
 }
コード例 #6
0
ファイル: WSDLConverter.java プロジェクト: Zannabis/jolie
  private void convertPortType(PortType portType, Binding binding) throws IOException {
    String comment = "";
    if (portType.getDocumentationElement() != null) {
      comment = portType.getDocumentationElement().getNodeValue();
    }

    Style style = Style.DOCUMENT;
    for (ExtensibilityElement element :
        (List<ExtensibilityElement>) binding.getExtensibilityElements()) {
      if (element instanceof SOAPBinding) {
        if ("rpc".equals(((SOAPBinding) element).getStyle())) {
          style = Style.RPC;
        }
      } else if (element instanceof HTTPBinding) {
        style = Style.HTTP;
      }
    }
    Interface iface = new Interface(portType.getQName().getLocalPart(), comment);
    List<Operation> operations = portType.getOperations();
    for (Operation operation : operations) {
      if (operation.getOutput() == null) {
        iface.addOneWayOperation(convertOperation(operation, style));
      } else {
        iface.addRequestResponseOperation(convertOperation(operation, style));
      }
    }
    interfaces.put(iface.name(), iface);
  }
コード例 #7
0
ファイル: WSDLRefValidator.java プロジェクト: noshlin/cxf
  private Map<QName, XNode> getBindings(Service service) {
    Map<QName, XNode> bindings = new HashMap<QName, XNode>();

    if (service.getPorts().values().size() == 0) {
      throw new ToolException(
          "Service " + service.getQName() + " does not contain any usable ports");
    }
    Collection<Port> ports = CastUtils.cast(service.getPorts().values());
    for (Port port : ports) {
      Binding binding = port.getBinding();
      bindings.put(binding.getQName(), getXNode(service, port));
      if (WSDLConstants.NS_WSDL11.equals(binding.getQName().getNamespaceURI())) {
        throw new ToolException(
            "Binding " + binding.getQName().getLocalPart() + " namespace set improperly.");
      }
    }

    return bindings;
  }
コード例 #8
0
  public static EprMetaData getBindingForTypeId(String repId, Definition wsdlDef) {
    LOG.log(
        Level.FINE, "RepositoryId " + repId + ", wsdl namespace " + wsdlDef.getTargetNamespace());
    EprMetaData ret = new EprMetaData();
    Collection<Binding> bindings = CastUtils.cast(wsdlDef.getBindings().values());
    for (Binding b : bindings) {
      List<?> extElements = b.getExtensibilityElements();

      // Get the list of all extensibility elements
      for (Iterator<?> extIter = extElements.iterator(); extIter.hasNext(); ) {
        java.lang.Object element = extIter.next();

        // Find a binding type so we can check against its repository ID
        if (element instanceof BindingType) {
          BindingType type = (BindingType) element;
          if (repId.equals(type.getRepositoryID())) {
            ret.setCandidateWsdlDef(wsdlDef);
            ret.setBinding(b);
            return ret;
          }
        }
      }
    }

    if (!ret.isValid()) {
      // recursivly check imports
      Iterator<?> importLists = wsdlDef.getImports().values().iterator();
      while (importLists.hasNext()) {
        List<?> imports = (List<?>) importLists.next();
        for (java.lang.Object imp : imports) {
          if (imp instanceof Import) {
            Definition importDef = ((Import) imp).getDefinition();
            LOG.log(Level.INFO, "Following import " + importDef.getDocumentBaseURI());
            ret = getBindingForTypeId(repId, importDef);
            if (ret.isValid()) {
              return ret;
            }
          }
        }
      }
    }
    return ret;
  }
コード例 #9
0
 public static String getActionURL(
     Definition wsdlDefinition,
     String serviceName,
     String portName,
     String bindingName,
     String opName) {
   Map<?, ?> services = wsdlDefinition.getServices();
   Set<?> serviceKeys = services.keySet();
   for (Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) {
     QName serviceKey = (QName) it.next();
     if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) {
       Service service = (Service) services.get(serviceKey);
       Map<?, ?> ports = service.getPorts();
       Set<?> portKeys = ports.keySet();
       for (Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) {
         String portKey = (String) it2.next();
         if (portName != null && portKey.contentEquals(portName)) {
           Port port = (Port) ports.get(portKey);
           Binding wsdlBinding = port.getBinding();
           List<?> operations = wsdlBinding.getBindingOperations();
           for (Iterator<?> it3 = operations.iterator(); it3.hasNext(); ) {
             BindingOperation operation = (BindingOperation) it3.next();
             if (opName != null && operation.getName().contentEquals(opName)) {
               List<?> attributesList = operation.getExtensibilityElements();
               for (Iterator<?> it4 = attributesList.iterator(); it4.hasNext(); ) {
                 Object test = it4.next();
                 if (test instanceof SOAPOperation) {
                   SOAPOperation soapOp = (SOAPOperation) test;
                   return soapOp.getSoapActionURI();
                 } else if (test instanceof SOAP12Operation) {
                   SOAP12Operation soapOp = (SOAP12Operation) test;
                   return soapOp.getSoapActionURI();
                 }
               }
             }
           }
         }
       }
     }
   }
   return null;
 }
コード例 #10
0
  public static Binding getDefaultBinding(Object obj, Definition wsdlDef) {
    LOG.log(Level.FINEST, "Getting binding for a default object reference");
    Collection<Binding> bindings = CastUtils.cast(wsdlDef.getBindings().values());
    for (Binding b : bindings) {
      List<?> extElements = b.getExtensibilityElements();
      // Get the list of all extensibility elements
      for (Iterator<?> extIter = extElements.iterator(); extIter.hasNext(); ) {
        java.lang.Object element = extIter.next();

        // Find a binding type so we can check against its repository ID
        if (element instanceof BindingType) {
          BindingType type = (BindingType) element;
          if (obj._is_a(type.getRepositoryID())) {
            return b;
          }
        }
      }
    }
    return null;
  }
コード例 #11
0
ファイル: WSIBPValidator.java プロジェクト: Jutten/cxf
  // TODO: Should also check SoapHeader/SoapHeaderFault
  public boolean checkR2205() {
    Collection<Binding> bindings = CastUtils.cast(def.getBindings().values());
    for (Binding binding : bindings) {

      if (!SOAPBindingUtil.isSOAPBinding(binding)) {
        System.err.println(
            "WSIBP Validator found <" + binding.getQName() + "> is NOT a SOAP binding");
        continue;
      }
      if (binding.getPortType() == null) {
        // will error later
        continue;
      }

      for (Iterator<?> ite2 = binding.getPortType().getOperations().iterator(); ite2.hasNext(); ) {
        Operation operation = (Operation) ite2.next();
        Collection<Fault> faults = CastUtils.cast(operation.getFaults().values());
        if (CollectionUtils.isEmpty(faults)) {
          continue;
        }

        for (Fault fault : faults) {
          Message message = fault.getMessage();
          Collection<Part> parts = CastUtils.cast(message.getParts().values());
          for (Part part : parts) {
            if (part.getElementName() == null) {
              addErrorMessage(
                  getErrorPrefix("WSI-BP-1.0 R2205")
                      + "In Message "
                      + message.getQName()
                      + ", part "
                      + part.getName()
                      + " must specify a 'element' attribute");
              return false;
            }
          }
        }
      }
    }
    return true;
  }
コード例 #12
0
  public void createSoapRequest(MessageContext msgCtx, Element message, Operation op)
      throws AxisFault {
    if (op == null) {
      throw new NullPointerException("Null operation");
    }
    // The message can be null if the input message has no part
    if (op.getInput().getMessage().getParts().size() > 0 && message == null) {
      throw new NullPointerException("Null message.");
    }
    if (msgCtx == null) {
      throw new NullPointerException("Null msgCtx");
    }

    BindingOperation bop = binding.getBindingOperation(op.getName(), null, null);

    if (bop == null) {
      throw new OdeFault("BindingOperation not found.");
    }

    BindingInput bi = bop.getBindingInput();
    if (bi == null) {
      throw new OdeFault("BindingInput not found.");
    }

    SOAPEnvelope soapEnv = msgCtx.getEnvelope();
    if (soapEnv == null) {
      soapEnv = soapFactory.getDefaultEnvelope();
      msgCtx.setEnvelope(soapEnv);
    }

    //        createSoapHeaders(soapEnv, getSOAPHeaders(bi), op.getInput().getMessage(), message);

    SOAPBody soapBody = getSOAPBody(bi);
    if (soapBody != null) {
      org.apache.axiom.soap.SOAPBody sb =
          soapEnv.getBody() == null ? soapFactory.createSOAPBody(soapEnv) : soapEnv.getBody();
      createSoapBody(sb, soapBody, op.getInput().getMessage(), message, op.getName());
    }
  }
コード例 #13
0
ファイル: WSDLRefValidator.java プロジェクト: noshlin/cxf
  private void collectValidationPointsForBindings() throws Exception {
    Map<QName, XNode> vBindingNodes = new HashMap<QName, XNode>();
    for (Service service : services.values()) {
      vBindingNodes.putAll(getBindings(service));
    }

    for (Map.Entry<QName, XNode> entry : vBindingNodes.entrySet()) {
      QName bName = entry.getKey();
      Binding binding = this.definition.getBinding(bName);
      if (binding == null) {
        LOG.log(
            Level.SEVERE,
            bName.toString()
                + " is not correct, please check that the correct namespace is being used");
        throw new Exception(
            bName.toString()
                + " is not correct, please check that the correct namespace is being used");
      }
      XNode vBindingNode = getXNode(binding);
      vBindingNode.setFailurePoint(entry.getValue());
      vNodes.add(vBindingNode);

      if (binding.getPortType() == null) {
        continue;
      }
      portTypeRefNames.add(binding.getPortType().getQName());

      XNode vPortTypeNode = getXNode(binding.getPortType());
      vPortTypeNode.setFailurePoint(vBindingNode);
      vNodes.add(vPortTypeNode);
      Collection<BindingOperation> bops = CastUtils.cast(binding.getBindingOperations());
      for (BindingOperation bop : bops) {
        XNode vOpNode = getOperationXNode(vPortTypeNode, bop.getName());
        XNode vBopNode = getOperationXNode(vBindingNode, bop.getName());
        vOpNode.setFailurePoint(vBopNode);
        vNodes.add(vOpNode);
        if (bop.getBindingInput() != null) {
          String inName = bop.getBindingInput().getName();
          if (!StringUtils.isEmpty(inName)) {
            XNode vInputNode = getInputXNode(vOpNode, inName);
            vInputNode.setFailurePoint(getInputXNode(vBopNode, inName));
            vNodes.add(vInputNode);
          }
        }
        if (bop.getBindingOutput() != null) {
          String outName = bop.getBindingOutput().getName();
          if (!StringUtils.isEmpty(outName)) {
            XNode vOutputNode = getOutputXNode(vOpNode, outName);
            vOutputNode.setFailurePoint(getOutputXNode(vBopNode, outName));
            vNodes.add(vOutputNode);
          }
        }
        for (Iterator<?> iter1 = bop.getBindingFaults().keySet().iterator(); iter1.hasNext(); ) {
          String faultName = (String) iter1.next();
          XNode vFaultNode = getFaultXNode(vOpNode, faultName);
          vFaultNode.setFailurePoint(getFaultXNode(vBopNode, faultName));
          vNodes.add(vFaultNode);
        }
      }
    }
  }
コード例 #14
0
ファイル: WSIBPValidator.java プロジェクト: Jutten/cxf
  public boolean checkR2203And2204() {

    Collection<Binding> bindings = CastUtils.cast(def.getBindings().values());
    for (Binding binding : bindings) {

      String style = SOAPBindingUtil.getCanonicalBindingStyle(binding);

      if (binding.getPortType() == null) {
        return true;
      }

      //

      for (Iterator<?> ite2 = binding.getPortType().getOperations().iterator(); ite2.hasNext(); ) {
        Operation operation = (Operation) ite2.next();
        BindingOperation bop = wsdlHelper.getBindingOperation(def, operation.getName());
        if (operation.getInput() != null && operation.getInput().getMessage() != null) {
          Message inMess = operation.getInput().getMessage();

          for (Iterator<?> ite3 = inMess.getParts().values().iterator(); ite3.hasNext(); ) {
            Part p = (Part) ite3.next();
            if (SOAPBinding.Style.RPC.name().equalsIgnoreCase(style)
                && p.getTypeName() == null
                && !isHeaderPart(bop, p)) {
              addErrorMessage(
                  "An rpc-literal binding in a DESCRIPTION MUST refer, "
                      + "in its soapbind:body element(s), only to "
                      + "wsdl:part element(s) that have been defined "
                      + "using the type attribute.");
              return false;
            }

            if (SOAPBinding.Style.DOCUMENT.name().equalsIgnoreCase(style)
                && p.getElementName() == null) {
              addErrorMessage(
                  "A document-literal binding in a DESCRIPTION MUST refer, "
                      + "in each of its soapbind:body element(s),"
                      + "only to wsdl:part element(s)"
                      + " that have been defined using the element attribute.");
              return false;
            }
          }
        }
        if (operation.getOutput() != null && operation.getOutput().getMessage() != null) {
          Message outMess = operation.getOutput().getMessage();
          for (Iterator<?> ite3 = outMess.getParts().values().iterator(); ite3.hasNext(); ) {
            Part p = (Part) ite3.next();
            if (style.equalsIgnoreCase(SOAPBinding.Style.RPC.name())
                && p.getTypeName() == null
                && !isHeaderPart(bop, p)) {
              addErrorMessage(
                  "An rpc-literal binding in a DESCRIPTION MUST refer, "
                      + "in its soapbind:body element(s), only to "
                      + "wsdl:part element(s) that have been defined "
                      + "using the type attribute.");
              return false;
            }

            if (style.equalsIgnoreCase(SOAPBinding.Style.DOCUMENT.name())
                && p.getElementName() == null) {
              addErrorMessage(
                  "A document-literal binding in a DESCRIPTION MUST refer, "
                      + "in each of its soapbind:body element(s),"
                      + "only to wsdl:part element(s)"
                      + " that have been defined using the element attribute.");
              return false;
            }
          }
        }
      }
    }
    return true;
  }
コード例 #15
0
ファイル: WSDLBuilder.java プロジェクト: kemlg/owls2wsdl
  /**
   * Build the WSDL model.
   *
   * @param abstractService collected Service information
   * @param prebuild XSD generator for type section
   * @return WSDL definition
   */
  public Definition buildDefinition(AbstractService abstractService, XsdSchemaGenerator xsdgen)
      throws WSDLException, java.lang.Exception {
    String serviceName = helper.reformatOWLSSupportedByString(abstractService.getID());
    String serviceDescription = abstractService.getDescription();
    Map<String, Vector<AbstractServiceParameter>> mapInputs =
        new HashMap<String, Vector<AbstractServiceParameter>>();
    Map<String, Vector<AbstractServiceParameter>> mapOutputs =
        new HashMap<String, Vector<AbstractServiceParameter>>();
    Map<String, AtomicProcess> mapProcesses = new HashMap<String, AtomicProcess>();

    System.out.println("[BUILD] Servicename: " + serviceName);
    System.out.println("[BUILD] description: " + serviceDescription);

    if (!this.validateServiceParameterTypes(abstractService)) {
      throw new Exception("Error in parameter list. Datatype not found.");
    }

    Vector<AtomicProcess> processes = abstractService.getProcesses();
    Iterator<AtomicProcess> itA = processes.iterator();
    while (itA.hasNext()) {
      AtomicProcess ap = itA.next();
      Vector<AbstractServiceParameter> inputParameter = ap.getInputParameter();
      Vector<AbstractServiceParameter> outputParameter = ap.getOutputParameter();
      String operationName = ap.getName();
      //			for (int i = 0; i < ap.getOutputParameter().size(); i++) {
      //				String operationName = "get"
      //						+ ((AbstractServiceParameter) ap
      //								.getOutputParameter().get(i)).getID();
      System.out.println("[BUILD] Operation  : " + operationName);
      //			}
      mapInputs.put(operationName, inputParameter);
      mapOutputs.put(operationName, outputParameter);
      mapProcesses.put(operationName, ap);
    }

    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    ExtensionRegistry extensionRegistry = wsdlFactory.newPopulatedExtensionRegistry();
    Definition def = wsdlFactory.newDefinition();

    SchemaSerializer schemaSer = new SchemaSerializer();
    extensionRegistry.setDefaultSerializer(schemaSer);

    //
    // NAMESPACE
    //
    // e.g. "http://dmas.dfki.de/axis/services/"

    int index = abstractService.getBase().lastIndexOf(".");

    String targetNS = abstractService.getBase().substring(0, index);

    if (OWLS2WSDLSettings.getInstance().getProperty("CHANGE_TNS").equals("yes")) {
      String tns_basepath = OWLS2WSDLSettings.getInstance().getProperty("TNS_BASEPATH");
      targetNS = tns_basepath + serviceName;
      def.setQName(new QName(tns_basepath, serviceName)); // +"Service"));
    } else {
      def.setQName(
          new QName(abstractService.getBasePath(), serviceName)); // abstractService.getID()));
    }

    System.out.println("abstractService.getBase    : " + abstractService.getBase());
    System.out.println("abstractService.getBasePath: " + abstractService.getBasePath());

    // def.setDocumentBaseURI("http://document/base");
    def.setTargetNamespace(targetNS);
    def.addNamespace("tns", targetNS);
    def.addNamespace("intf", targetNS);
    def.addNamespace("impl", targetNS + "-impl");
    def.addNamespace("", targetNS);

    def.addNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
    def.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    def.addNamespace("wsdlsoap", "http://schemas.xmlsoap.org/wsdl/soap/");
    def.addNamespace("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/");
    def.addNamespace("apachesoap", "http://xml.apache.org/xml-soap");

    System.out.println("INFO: " + def.getQName().toString());
    System.out.println("tns : " + def.getNamespace("tns" + serviceName));

    // WA: xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    // WA: xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"

    //
    // IMPORTS AND TYPES
    //
    /*
     * Import importsec = def.createImport(); importsec.setDefinition(def);
     * importsec.setLocationURI("locationURI");
     * importsec.setNamespaceURI("nsURI"); def.addImport(importsec);
     */

    // LESEN DES SCHEMAS AUS DATEISYSTEM
    // ===========================================
    // DOMParser domp = new DOMParser();
    // try {
    // //domp.parse("file:/D:/development/xsd/generated.xsd");
    // domp.parse("file:/D:/tmp/StEmilion.xsd");
    // }
    // catch(Exception e) { e.printStackTrace(); }
    //
    // Document doc = domp.getDocument();
    // Element element = doc.getDocumentElement();
    // =============================================================================

    Element element = null;

    try {
      // construct schema model for all parameter
      Iterator<Entry<String, Vector<AbstractServiceParameter>>> itAp =
          mapInputs.entrySet().iterator();
      while (itAp.hasNext()) {
        for (Iterator<AbstractServiceParameter> it = itAp.next().getValue().iterator();
            it.hasNext(); ) {
          AbstractServiceParameter param = it.next();
          System.out.println("[BUILD] IN         :" + param.getUri());
          if (!this.isPrimitiveType(param.getUri())) {
            xsdgen.appendToSchema(
                AbstractDatatypeKB.getInstance().getAbstractDatatypeKBData().get(param.getUri()));
            System.out.println("[BUILD] added to type section.");
          }
        }
      }

      itAp = mapOutputs.entrySet().iterator();
      while (itAp.hasNext()) {
        for (Iterator<AbstractServiceParameter> it = itAp.next().getValue().iterator();
            it.hasNext(); ) {
          AbstractServiceParameter param = it.next();
          System.out.println("[BUILD] OUT        :" + param.getUri());
          if (!this.isPrimitiveType(param.getUri())) {
            xsdgen.appendToSchema(
                AbstractDatatypeKB.getInstance().getAbstractDatatypeKBData().get(param.getUri()));
            System.out.println("[BUILD] added to type section.");
          }
        }
      }

      xsdgen.deleteObsoleteTypesFromSchema();

      // org.jdom.Document jdoc =
      // XMLUtils.convertSchemaToElement(AbstractDatatypeKB.getInstance().getXmlSchemaElement("http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#StEmilion",
      // false, -1)).getDocument();
      org.jdom.Document jdoc = XMLUtils.convertSchemaToElement(xsdgen.getSchema()).getDocument();

      DOMOutputter w3cOutputter = new DOMOutputter();
      Document doc = w3cOutputter.output(jdoc);
      element = doc.getDocumentElement();

      NamedNodeMap attList = element.getAttributes();
      for (int i = 0; i < attList.getLength(); i++) {
        Node n = element.getAttributes().item(i);
        if (n.getTextContent().equals("http://www.w3.org/2001/XMLSchema")) {
          element.removeAttributeNode((Attr) n);
        }
      }

      element.setAttribute("targetNamespace", targetNS);
      element.setAttribute("xmlns", targetNS);
    } catch (org.jdom.JDOMException jdome) {
      jdome.printStackTrace();
    } catch (org.xml.sax.SAXException saxe) {
      saxe.printStackTrace();
    } catch (java.io.IOException ioe) {
      ioe.printStackTrace();
    } catch (java.lang.Exception e) {
      e.printStackTrace();
    }

    UnknownExtensibilityElement extensibilityElement = new UnknownExtensibilityElement();
    extensibilityElement.setElement(element);
    extensibilityElement.setElementType(new QName(element.getNamespaceURI()));
    extensibilityElement.setRequired(Boolean.TRUE);
    // System.out.println("EXENSIBILITYELEMENT: "+extensibilityElement);

    Types types = def.getTypes();
    types = def.createTypes();
    types.addExtensibilityElement(extensibilityElement);
    def.setTypes(types);

    // Schema schema = new SchemaImpl();
    // DOMParser domp = new DOMParser();
    // try {
    // domp.parse("file:/D:/development/xsd/generated.xsd");
    // Document doc = domp.getDocument();
    // NodeList nodes = doc.getElementsByTagName("xsd:schema");
    // for(int i=0; i<nodes.getLength();i++) {
    // schema.setElement(doc.getDocumentElement());
    // schema.setElementType(new QName(nodes.item(i).getNamespaceURI()));
    // schema.setDocumentBaseURI(nodes.item(i).getNamespaceURI());
    // types.addExtensibilityElement(schema);
    // def.setTypes(types);
    // }
    // System.out.println("DOC1:"+doc.toString());
    // System.out.println("NODES:"+nodes.getLength());
    // }
    // catch(Exception e) {
    // e.printStackTrace();
    // }
    // //UnknownExtensibilityElement extensibilityElement = new
    // UnknownExtensibilityElement();

    // // org.jdom.Element jdelem = XMLUtils.convertSchemaToElement(schema);
    // // System.out.println("JDOM ELEMENT: "+jdelem.toString());

    // http://mail-archives.apache.org/mod_mbox/ws-axis-dev/200406.mbox/%[email protected]%3e
    //
    // Schema schema = (Schema)
    // extensionRegistry.createExtension(javax.wsdl.Types, new
    // QName("http://www.w3.org/2001/XMLSchema", "schema"));
    // DocumentBuilderFactory factory =
    // DocumentBuilderFactory.newInstance();
    // DocumentBuilder builder = factory.newDocumentBuilder();
    // Document schemaDeclaration = builder.newDocument();
    // //... (populate schemaDeclaration with elements and types)
    // schema.setDeclaration(schemaDeclaration);
    // types.addExtensibilityElement(schema);

    // (get-) Operation name
    //		String operationName = "get";
    //		for (int i = 0; i < outputParameter.size(); i++) {
    //			AbstractServiceParameter param = (AbstractServiceParameter) outputParameter
    //					.get(i);
    //			operationName += param.getID();
    //		}

    //
    // MESSAGES, PARTS
    // =================================================================
    // description fehlt noch

    Service service = def.createService();
    // service.setDocumentationElement()
    service.setQName(new QName(targetNS, serviceName + "Service"));
    SOAPBinding soapBinding =
        (SOAPBinding)
            extensionRegistry.createExtension(
                Binding.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/", "binding"));
    soapBinding.setTransportURI("http://schemas.xmlsoap.org/soap/http");
    soapBinding.setStyle("rpc");

    SOAPBody body =
        (SOAPBody)
            extensionRegistry.createExtension(
                BindingInput.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/", "body"));
    body.setUse("literal");
    ArrayList<String> listOfStyles = new ArrayList<String>();
    listOfStyles.add("http://schemas.xmlsoap.org/soap/encoding/");
    body.setEncodingStyles(listOfStyles);
    body.setNamespaceURI(targetNS);

    Binding binding = def.createBinding();

    // == add PortType and Binding to WSDL defintion

    PortType portType = def.createPortType();
    portType.setQName(new QName(targetNS, serviceName + "PortType"));

    // == Binding section

    binding.setQName(new QName(targetNS, serviceName + "Binding"));
    binding.addExtensibilityElement(soapBinding);

    BindingInput binding_input = def.createBindingInput();
    // binding_input.setName("BINDING IN");
    binding_input.addExtensibilityElement(body);
    BindingOutput binding_out = def.createBindingOutput();
    // binding_out.setName("BINDING OUT");
    binding_out.addExtensibilityElement(body);
    Iterator<Entry<String, Vector<AbstractServiceParameter>>> itOps =
        mapInputs.entrySet().iterator();
    while (itOps.hasNext()) {
      Entry<String, Vector<AbstractServiceParameter>> op = itOps.next();
      String operationName = op.getKey();
      AtomicProcess ap = mapProcesses.get(operationName);
      Vector<AbstractServiceParameter> inputParameter = mapInputs.get(operationName);
      Vector<AbstractServiceParameter> outputParameter = mapOutputs.get(operationName);

      Message request = def.createMessage();
      request.setQName(new QName(targetNS, operationName + "Request"));

      boolean duplicateInputs = false;
      boolean duplicateOutputs = false;
      if (ap.hasDuplicateInputParameter()) {
        duplicateInputs = true;
      }
      if (ap.hasDuplicateOutputParameter()) {
        duplicateOutputs = true;
      }

      for (int ipi = 0; ipi < inputParameter.size(); ipi++) {
        AbstractServiceParameter param = (AbstractServiceParameter) inputParameter.get(ipi);
        Part part = def.createPart();
        if (duplicateInputs) {
          part.setName(param.getID() + String.valueOf(param.getPos()));
        } else {
          part.setName(param.getID());
        }
        System.out.println("SET TYPE OF PART: " + param.toString());
        if (param.isPrimitiveXsdType()) {
          part.setTypeName(new QName("http://www.w3.org/2001/XMLSchema", param.getTypeLocal()));
        } else {
          part.setTypeName(new QName(targetNS, param.getTypeRemote()));
        }
        request.addPart(part);
      }
      request.setUndefined(false);
      def.addMessage(request);

      Message response = def.createMessage();
      response.setQName(new QName(targetNS, operationName + "Response"));
      for (int opi = 0; opi < outputParameter.size(); opi++) {
        AbstractServiceParameter param = (AbstractServiceParameter) outputParameter.get(opi);
        Part part = def.createPart();
        if (duplicateOutputs) {
          part.setName(param.getID() + String.valueOf(param.getPos()));
        } else {
          part.setName(param.getID());
        }
        System.out.println("SET TYPE OF PART: " + param.toString());
        if (param.isPrimitiveXsdType()) {
          part.setTypeName(new QName("http://www.w3.org/2001/XMLSchema", param.getTypeLocal()));
        } else {
          part.setTypeName(new QName(targetNS, param.getTypeRemote()));
        }
        response.addPart(part);
      }
      response.setUndefined(false);
      def.addMessage(response);

      //
      // PORTTYPE, OPERATION
      //
      Input input = def.createInput();
      input.setMessage(request);
      Output output = def.createOutput();
      output.setMessage(response);

      // == build the wsdl operation + bindings for each owls output parameter

      Operation operation = def.createOperation();
      //			operation.setName(operationName);
      operation.setName(ap.getOperationName());
      operation.setInput(input);
      operation.setOutput(output);
      operation.setUndefined(false);

      portType.addOperation(operation);
      portType.setUndefined(false);

      SOAPOperation soapOperation =
          (SOAPOperation)
              extensionRegistry.createExtension(
                  BindingOperation.class,
                  new QName("http://schemas.xmlsoap.org/wsdl/soap/", "operation"));
      soapOperation.setSoapActionURI("");
      // soapOperation.setStyle("document");

      BindingOperation binding_op = def.createBindingOperation();
      //			binding_op.setName(operationName);
      binding_op.setName(ap.getOperationName());
      binding_op.addExtensibilityElement(soapOperation);
      binding_op.setOperation(operation);
      binding_op.setBindingInput(binding_input);
      binding_op.setBindingOutput(binding_out);
      binding.addBindingOperation(binding_op);

      binding.setPortType(portType);

      binding.setUndefined(false);
      def.addBinding(binding);
    }

    def.addPortType(portType);

    //
    // SERVICE
    //
    SOAPAddress soapAddress =
        (SOAPAddress)
            extensionRegistry.createExtension(
                Port.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/", "address"));
    soapAddress.setLocationURI(targetNS);
    Port port = def.createPort();
    port.setName(serviceName + "Port");
    port.setBinding(binding);
    port.addExtensibilityElement(soapAddress);

    service.addPort(port);
    def.addService(service);

    return def;
  }
コード例 #16
0
ファイル: WsdlInterface.java プロジェクト: thamuz/soapui
  @SuppressWarnings("unchecked")
  public void transferOperations(Binding binding, boolean createRequests) {
    // prepare for transfer of operations/requests
    List<BindingOperation> newOperations =
        new ArrayList<BindingOperation>(binding.getBindingOperations());
    Map<String, WsdlOperation> oldOperations = new HashMap<String, WsdlOperation>();
    for (int c = 0; c < operations.size(); c++)
      oldOperations.put(operations.get(c).getBindingOperationName(), operations.get(c));

    // clear existing from both collections
    for (int c = 0; c < newOperations.size(); c++) {
      BindingOperation newOperation = newOperations.get(c);
      String bindingOperationName = newOperation.getName();
      if (oldOperations.containsKey(bindingOperationName)) {
        log.info("Synchronizing existing operation [" + bindingOperationName + "]");
        WsdlOperation wsdlOperation = oldOperations.get(bindingOperationName);
        WsdlUtils.getAnonymous(wsdlOperation);
        wsdlOperation.initFromBindingOperation(newOperation);
        fireOperationUpdated(wsdlOperation);

        oldOperations.remove(bindingOperationName);
        newOperations.remove(c);
        c--;
      }
    }

    // remove leftover operations
    Iterator<String> i = oldOperations.keySet().iterator();
    while (i.hasNext()) {
      String name = i.next();

      if (newOperations.size() > 0) {
        List<String> list = new ArrayList<String>();
        list.add("none - delete operation");
        for (int c = 0; c < newOperations.size(); c++) list.add(newOperations.get(c).getName());

        String retval =
            (String)
                UISupport.prompt(
                    "Binding operation ["
                        + name
                        + "] not found in new interface, select new\nbinding operation to map to",
                    "Map Operation",
                    list.toArray(),
                    "none/cancel - delete operation");

        int ix = retval == null ? -1 : list.indexOf(retval) - 1;

        // delete operation?
        if (ix < 0) {
          deleteOperation(name);
        }
        // change operation?
        else {
          BindingOperation newOperation = newOperations.get(ix);
          WsdlOperation wsdlOperation = oldOperations.get(name);
          wsdlOperation.initFromBindingOperation(newOperation);
          fireOperationUpdated(wsdlOperation);
          newOperations.remove(ix);
        }

        oldOperations.remove(name);
      } else {
        deleteOperation(name);
        oldOperations.remove(name);
      }

      i = oldOperations.keySet().iterator();
    }

    // add leftover new operations
    if (newOperations.size() > 0) {
      for (int c = 0; c < newOperations.size(); c++) {
        BindingOperation newOperation = newOperations.get(c);
        WsdlOperation wsdlOperation = addNewOperation(newOperation);

        if (createRequests) {
          WsdlRequest request = wsdlOperation.addNewRequest("Request 1");
          try {
            request.setRequestContent(wsdlOperation.createRequest(true));
          } catch (Exception e) {
            SoapUI.logError(e);
          }
        }
      }
    }
  }