public void createSoapBody(
      org.apache.axiom.soap.SOAPBody sb,
      SOAPBody soapBody,
      Message msgDef,
      Element message,
      String rpcWrapper)
      throws AxisFault {
    OMElement partHolder =
        isRPC
            ? soapFactory.createOMElement(
                new QName(soapBody.getNamespaceURI(), rpcWrapper, "odens"), sb)
            : sb;
    List<Part> parts = msgDef.getOrderedParts(soapBody.getParts());

    for (Part part : parts) {
      Element srcPartEl = DOMUtils.findChildByName(message, new QName(null, part.getName()));
      if (srcPartEl == null) {
        throw new AxisFault("Missing required part in ODE Message");
      }

      OMElement omPart = OMUtils.toOM(srcPartEl, soapFactory);
      if (isRPC) {
        partHolder.addChild(omPart);
      } else {
        for (Iterator<OMNode> i = omPart.getChildren(); i.hasNext(); ) {
          partHolder.addChild(i.next());
        }
      }
    }
  }
  public ExtensibilityElement unmarshall(
      Class parentType, QName elementType, Element el, Definition def, ExtensionRegistry extReg)
      throws WSDLException {
    SOAPBody soapBody = (SOAPBody) extReg.createExtension(parentType, elementType);
    String partsStr = DOMUtils.getAttribute(el, SOAPConstants.ATTR_PARTS);
    String use = DOMUtils.getAttribute(el, SOAPConstants.ATTR_USE);
    String encStyleStr = DOMUtils.getAttribute(el, SOAPConstants.ATTR_ENCODING_STYLE);
    String namespaceURI = DOMUtils.getAttribute(el, Constants.ATTR_NAMESPACE);
    String requiredStr =
        DOMUtils.getAttributeNS(el, Constants.NS_URI_WSDL, Constants.ATTR_REQUIRED);

    if (partsStr != null) {
      soapBody.setParts(StringUtils.parseNMTokens(partsStr));
    }

    if (use != null) {
      soapBody.setUse(use);
    }

    if (encStyleStr != null) {
      soapBody.setEncodingStyles(StringUtils.parseNMTokens(encStyleStr));
    }

    if (namespaceURI != null) {
      soapBody.setNamespaceURI(namespaceURI);
    }

    if (requiredStr != null) {
      soapBody.setRequired(new Boolean(requiredStr));
    }

    return soapBody;
  }
  public void marshall(
      Class parentType,
      QName elementType,
      ExtensibilityElement extension,
      PrintWriter pw,
      Definition def,
      ExtensionRegistry extReg)
      throws WSDLException {
    SOAPBody soapBody = (SOAPBody) extension;

    if (soapBody != null) {
      String tagName = DOMUtils.getQualifiedValue(SOAPConstants.NS_URI_SOAP, "body", def);

      if (parentType != null && MIMEPart.class.isAssignableFrom(parentType)) {
        pw.print("    ");
      }

      pw.print("        <" + tagName);

      DOMUtils.printAttribute(
          SOAPConstants.ATTR_PARTS, StringUtils.getNMTokens(soapBody.getParts()), pw);
      DOMUtils.printAttribute(SOAPConstants.ATTR_USE, soapBody.getUse(), pw);
      DOMUtils.printAttribute(
          SOAPConstants.ATTR_ENCODING_STYLE,
          StringUtils.getNMTokens(soapBody.getEncodingStyles()),
          pw);
      DOMUtils.printAttribute(Constants.ATTR_NAMESPACE, soapBody.getNamespaceURI(), pw);

      Boolean required = soapBody.getRequired();

      if (required != null) {
        DOMUtils.printQualifiedAttribute(Constants.Q_ATTR_REQUIRED, required.toString(), def, pw);
      }

      pw.println("/>");
    }
  }
Example #4
0
  /**
   * 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;
  }
 /*      */ public static QName getOperationQName(
     BindingOperation bindingOper, BindingEntry bEntry, SymbolTable symbolTable)
       /*      */ {
   /*  813 */ Operation operation = bindingOper.getOperation();
   /*  814 */ String operationName = operation.getName();
   /*      */
   /*  821 */ if ((bEntry.getBindingStyle() == Style.DOCUMENT) && (symbolTable.isWrapped()))
   /*      */ {
     /*  823 */ Input input = operation.getInput();
     /*      */
     /*  825 */ if (input != null) {
       /*  826 */ Map parts = input.getMessage().getParts();
       /*      */
       /*  828 */ if ((parts != null) && (!parts.isEmpty())) {
         /*  829 */ Iterator i = parts.values().iterator();
         /*  830 */ Part p = (Part) i.next();
         /*      */
         /*  832 */ return p.getElementName();
         /*      */ }
       /*      */ }
     /*      */ }
   /*      */
   /*  837 */ String ns = null;
   /*      */
   /*  842 */ BindingInput bindInput = bindingOper.getBindingInput();
   /*      */
   /*  844 */ if (bindInput != null) {
     /*  845 */ Iterator it = bindInput.getExtensibilityElements().iterator();
     /*      */
     /*  847 */ while (it.hasNext()) {
       /*  848 */ ExtensibilityElement elem = (ExtensibilityElement) it.next();
       /*      */
       /*  850 */ if ((elem instanceof SOAPBody)) {
         /*  851 */ SOAPBody body = (SOAPBody) elem;
         /*      */
         /*  853 */ ns = body.getNamespaceURI();
         /*  854 */ if ((bEntry.getInputBodyType(operation) != Use.ENCODED)
             || ((ns != null) && (ns.length() != 0))) break;
         /*  855 */ log.warn(
             Messages.getMessage(
                 "badNamespaceForOperation00", bEntry.getName(), operation.getName()));
         break;
         /*      */ }
       /*      */
       /*  861 */ if ((elem instanceof MIMEMultipartRelated)) {
         /*  862 */ Object part = null;
         /*  863 */ MIMEMultipartRelated mpr = (MIMEMultipartRelated) elem;
         /*      */
         /*  865 */ List l = mpr.getMIMEParts();
         /*      */
         /*  868 */ int j = 0;
         /*  869 */ while ((l != null) && (j < l.size()) && (part == null))
         /*      */ {
           /*  871 */ MIMEPart mp = (MIMEPart) l.get(j);
           /*      */
           /*  873 */ List ll = mp.getExtensibilityElements();
           /*      */
           /*  876 */ int k = 0;
           /*  877 */ for (; (ll != null) && (k < ll.size()) && (part == null); k++) {
             /*  878 */ part = ll.get(k);
             /*      */
             /*  880 */ if ((part instanceof SOAPBody)) {
               /*  881 */ SOAPBody body = (SOAPBody) part;
               /*      */
               /*  883 */ ns = body.getNamespaceURI();
               /*  884 */ if ((bEntry.getInputBodyType(operation) != Use.ENCODED)
                   || ((ns != null) && (ns.length() != 0))) break;
               /*  885 */ log.warn(
                   Messages.getMessage(
                       "badNamespaceForOperation00", bEntry.getName(), operation.getName()));
               break;
               /*      */ }
             /*      */
             /*  892 */ part = null;
             /*      */ }
           /*  870 */ j++;
           /*      */ }
         /*      */
         /*      */ }
       /*  896 */ else if ((elem instanceof UnknownExtensibilityElement))
       /*      */ {
         /*  899 */ UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) elem;
         /*      */
         /*  901 */ QName name = unkElement.getElementType();
         /*      */
         /*  904 */ if ((name.getNamespaceURI().equals("http://schemas.xmlsoap.org/wsdl/soap12/"))
             && (name.getLocalPart().equals("body")))
         /*      */ {
           /*  906 */ ns = unkElement.getElement().getAttribute("namespace");
           /*      */ }
         /*      */
         /*      */ }
       /*      */
       /*      */ }
     /*      */
     /*      */ }
   /*      */
   /*  916 */ if (ns == null) {
     /*  917 */ ns = "";
     /*      */ }
   /*      */
   /*  920 */ return new QName(ns, operationName);
   /*      */ }