Example #1
0
  private static void writeW3CMetaData(
      StreamWriterBufferCreator writer,
      QName service,
      QName port,
      QName portType,
      List<Element> metadata,
      String wsdlAddress)
      throws XMLStreamException {

    writer.writeStartElement(
        AddressingVersion.W3C.getPrefix(),
        W3CAddressingConstants.WSA_METADATA_NAME,
        AddressingVersion.W3C.nsUri);
    writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(), AddressingVersion.W3C.wsdlNsUri);

    // Write Interface info
    if (portType != null) {
      writer.writeStartElement(
          AddressingVersion.W3C.getWsdlPrefix(),
          W3CAddressingConstants.WSAW_INTERFACENAME_NAME,
          AddressingVersion.W3C.wsdlNsUri);
      String portTypePrefix = portType.getPrefix();
      if (portTypePrefix == null || portTypePrefix.equals("")) {
        // TODO check prefix again
        portTypePrefix = "wsns";
      }
      writer.writeNamespace(portTypePrefix, portType.getNamespaceURI());
      writer.writeCharacters(portTypePrefix + ":" + portType.getLocalPart());
      writer.writeEndElement();
    }
    if (service != null) {
      // Write service and Port info
      if (!(service.getNamespaceURI().equals("") || service.getLocalPart().equals(""))) {
        writer.writeStartElement(
            AddressingVersion.W3C.getWsdlPrefix(),
            W3CAddressingConstants.WSAW_SERVICENAME_NAME,
            AddressingVersion.W3C.wsdlNsUri);
        String servicePrefix = service.getPrefix();
        if (servicePrefix == null || servicePrefix.equals("")) {
          // TODO check prefix again
          servicePrefix = "wsns";
        }
        writer.writeNamespace(servicePrefix, service.getNamespaceURI());
        if (port != null) {
          writer.writeAttribute(W3CAddressingConstants.WSAW_ENDPOINTNAME_NAME, port.getLocalPart());
        }
        writer.writeCharacters(servicePrefix + ":" + service.getLocalPart());
        writer.writeEndElement();
      }
    }
    // Inline the wsdl
    if (wsdlAddress != null) {
      writeWsdl(writer, service, wsdlAddress);
    }
    // Add the extra metadata Elements
    if (metadata != null)
      for (Element e : metadata) {
        DOMUtil.serializeNode(e, writer);
      }
    writer.writeEndElement();
  }
Example #2
0
  private static XMLStreamBuffer createBufferFromData(
      AddressingVersion version,
      String address,
      List<Element> referenceParameters,
      QName service,
      QName port,
      QName portType,
      List<Element> metadata,
      String wsdlAddress) {

    StreamWriterBufferCreator writer = new StreamWriterBufferCreator();

    try {
      writer.writeStartDocument();
      writer.writeStartElement(version.getPrefix(), "EndpointReference", version.nsUri);
      writer.writeNamespace(version.getPrefix(), version.nsUri);
      writer.writeStartElement(version.getPrefix(), "Address", version.nsUri);
      writer.writeCharacters(address);
      writer.writeEndElement();
      if (referenceParameters != null) {
        writer.writeStartElement(version.getPrefix(), "ReferenceParameters", version.nsUri);
        for (Element e : referenceParameters) DOMUtil.serializeNode(e, writer);
        writer.writeEndElement();
      }

      switch (version) {
        case W3C:
          writeW3CMetaData(writer, service, port, portType, metadata, wsdlAddress);
          break;

        case MEMBER:
          writeMSMetaData(writer, service, port, portType, metadata);
          if (wsdlAddress != null) {
            // Inline the wsdl as extensibility element
            // Write mex:Metadata wrapper
            writer.writeStartElement(
                MemberSubmissionAddressingConstants.MEX_METADATA.getPrefix(),
                MemberSubmissionAddressingConstants.MEX_METADATA.getLocalPart(),
                MemberSubmissionAddressingConstants.MEX_METADATA.getNamespaceURI());
            writer.writeStartElement(
                MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getPrefix(),
                MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getLocalPart(),
                MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getNamespaceURI());
            writer.writeAttribute(
                MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_ATTRIBUTE,
                MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_VALUE);

            writeWsdl(writer, service, wsdlAddress);

            writer.writeEndElement();
            writer.writeEndElement();
          }

          break;
      }
      writer.writeEndElement();
      writer.writeEndDocument();
      writer.flush();

      return writer.getXMLStreamBuffer();
    } catch (XMLStreamException e) {
      throw new WebServiceException(e);
    }
  }