Search in sources :

Example 1 with StreamWriterBufferCreator

use of com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator in project metro-jax-ws by eclipse-ee4j.

the class WSEndpointReference method createBufferFromData.

private static XMLStreamBuffer createBufferFromData(AddressingVersion version, String address, List<Element> referenceParameters, QName service, QName port, QName portType, List<Element> metadata, String wsdlAddress, String wsdlTargetNamespace, @Nullable List<Element> elements, @Nullable Map<QName, String> attributes) {
    StreamWriterBufferCreator writer = new StreamWriterBufferCreator();
    try {
        writer.writeStartDocument();
        writer.writeStartElement(version.getPrefix(), "EndpointReference", version.nsUri);
        writer.writeNamespace(version.getPrefix(), version.nsUri);
        writePartialEPRInfoset(writer, version, address, referenceParameters, service, port, portType, metadata, wsdlAddress, wsdlTargetNamespace, attributes);
        // write extensibility elements in the EPR element
        if (elements != null) {
            for (Element e : elements) {
                DOMUtil.serializeNode(e, writer);
            }
        }
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
        return writer.getXMLStreamBuffer();
    } catch (XMLStreamException e) {
        throw new WebServiceException(e);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) WebServiceException(jakarta.xml.ws.WebServiceException) Element(org.w3c.dom.Element) StreamWriterBufferCreator(com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator)

Example 2 with StreamWriterBufferCreator

use of com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator in project metro-jax-ws by eclipse-ee4j.

the class WSEndpointReference method createBufferFromData.

private static XMLStreamBuffer createBufferFromData(AddressingVersion version, String address, List<Element> referenceParameters, QName service, QName port, QName portType, List<Element> metadata, String wsdlAddress, String wsdlTargetNamespace, @Nullable Collection<EPRExtension> extns, @Nullable Map<QName, String> attributes) {
    StreamWriterBufferCreator writer = new StreamWriterBufferCreator();
    try {
        writer.writeStartDocument();
        writer.writeStartElement(version.getPrefix(), "EndpointReference", version.nsUri);
        writer.writeNamespace(version.getPrefix(), version.nsUri);
        writePartialEPRInfoset(writer, version, address, referenceParameters, service, port, portType, metadata, wsdlAddress, wsdlTargetNamespace, attributes);
        // write extensibility elements in the EPR element
        if (extns != null) {
            for (EPRExtension e : extns) {
                XMLStreamReaderToXMLStreamWriter c = new XMLStreamReaderToXMLStreamWriter();
                XMLStreamReader r = e.readAsXMLStreamReader();
                c.bridge(r, writer);
                XMLStreamReaderFactory.recycle(r);
            }
        }
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
        return writer.getXMLStreamBuffer();
    } catch (XMLStreamException e) {
        throw new WebServiceException(e);
    }
}
Also used : XMLStreamReaderToXMLStreamWriter(org.jvnet.staxex.util.XMLStreamReaderToXMLStreamWriter) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) WebServiceException(jakarta.xml.ws.WebServiceException) WSEPRExtension(com.sun.xml.ws.addressing.WSEPRExtension) StreamWriterBufferCreator(com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator)

Example 3 with StreamWriterBufferCreator

use of com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator in project metro-jax-ws by eclipse-ee4j.

the class WSEndpointReference method createBufferFromAddress.

private static XMLStreamBuffer createBufferFromAddress(String address, AddressingVersion version) {
    try {
        MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
        StreamWriterBufferCreator w = new StreamWriterBufferCreator(xsb);
        w.writeStartDocument();
        w.writeStartElement(version.getPrefix(), "EndpointReference", version.nsUri);
        w.writeNamespace(version.getPrefix(), version.nsUri);
        w.writeStartElement(version.getPrefix(), version.eprType.address, version.nsUri);
        w.writeCharacters(address);
        w.writeEndElement();
        w.writeEndElement();
        w.writeEndDocument();
        w.close();
        return xsb;
    } catch (XMLStreamException e) {
        // can never happen because we are writing to XSB
        throw new AssertionError(e);
    }
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamException(javax.xml.stream.XMLStreamException) StreamWriterBufferCreator(com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator)

Example 4 with StreamWriterBufferCreator

use of com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator in project metro-jax-ws by eclipse-ee4j.

the class EndpointReferenceUtil method toW3CEpr.

// TODO: bit of redundency on writes of w3c epr, should modularize it
private static W3CEndpointReference toW3CEpr(MemberSubmissionEndpointReference msEpr) {
    StreamWriterBufferCreator writer = new StreamWriterBufferCreator();
    w3cMetadataWritten = false;
    try {
        writer.writeStartDocument();
        writer.writeStartElement(AddressingVersion.W3C.getPrefix(), "EndpointReference", AddressingVersion.W3C.nsUri);
        writer.writeNamespace(AddressingVersion.W3C.getPrefix(), AddressingVersion.W3C.nsUri);
        // write wsa:Address
        writer.writeStartElement(AddressingVersion.W3C.getPrefix(), AddressingVersion.W3C.eprType.address, AddressingVersion.W3C.nsUri);
        writer.writeCharacters(msEpr.addr.uri);
        writer.writeEndElement();
        // TODO: write extension attributes on wsa:Address
        if ((msEpr.referenceProperties != null && msEpr.referenceProperties.elements.size() > 0) || (msEpr.referenceParameters != null && msEpr.referenceParameters.elements.size() > 0)) {
            writer.writeStartElement(AddressingVersion.W3C.getPrefix(), "ReferenceParameters", AddressingVersion.W3C.nsUri);
            // write ReferenceProperties
            if (msEpr.referenceProperties != null) {
                for (Element e : msEpr.referenceProperties.elements) {
                    DOMUtil.serializeNode(e, writer);
                }
            }
            // write referenceParameters
            if (msEpr.referenceParameters != null) {
                for (Element e : msEpr.referenceParameters.elements) {
                    DOMUtil.serializeNode(e, writer);
                }
            }
            writer.writeEndElement();
        }
        // Supress writing ServiceName and EndpointName in W3CEPR,
        // Until the ns for those metadata elements is resolved.
        /*
            //Write Interface info
            if (msEpr.portTypeName != null) {
                writeW3CMetadata(writer);
                writer.writeStartElement(AddressingVersion.W3C.getWsdlPrefix(),
                        AddressingVersion.W3C.eprType.portTypeName ,
                        AddressingVersion.W3C.wsdlNsUri);
                writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(),
                        AddressingVersion.W3C.wsdlNsUri);
                String portTypePrefix = fixNull(msEpr.portTypeName.name.getPrefix());
                writer.writeNamespace(portTypePrefix, msEpr.portTypeName.name.getNamespaceURI());
                if (portTypePrefix.equals(""))
                    writer.writeCharacters(msEpr.portTypeName.name.getLocalPart());
                else
                    writer.writeCharacters(portTypePrefix + ":" + msEpr.portTypeName.name.getLocalPart());
                writer.writeEndElement();
            }
            if (msEpr.serviceName != null) {
                writeW3CMetadata(writer);
                //Write service and Port info
                writer.writeStartElement(AddressingVersion.W3C.getWsdlPrefix(),
                        AddressingVersion.W3C.eprType.serviceName ,
                        AddressingVersion.W3C.wsdlNsUri);
                writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(),
                        AddressingVersion.W3C.wsdlNsUri);

                String servicePrefix = fixNull(msEpr.serviceName.name.getPrefix());
                if (msEpr.serviceName.portName != null)
                    writer.writeAttribute(AddressingVersion.W3C.eprType.portName,
                            msEpr.serviceName.portName);

                writer.writeNamespace(servicePrefix, msEpr.serviceName.name.getNamespaceURI());
                if (servicePrefix.length() > 0)
                    writer.writeCharacters(servicePrefix + ":" + msEpr.serviceName.name.getLocalPart());
                else
                    writer.writeCharacters(msEpr.serviceName.name.getLocalPart());
                writer.writeEndElement();
            }
            */
        // TODO: revisit this
        Element wsdlElement = null;
        // Check for wsdl in extension elements
        if ((msEpr.elements != null) && (msEpr.elements.size() > 0)) {
            for (Element e : msEpr.elements) {
                if (e.getNamespaceURI().equals(MemberSubmissionAddressingConstants.MEX_METADATA.getNamespaceURI()) && e.getLocalName().equals(MemberSubmissionAddressingConstants.MEX_METADATA.getLocalPart())) {
                    NodeList nl = e.getElementsByTagNameNS(WSDLConstants.NS_WSDL, WSDLConstants.QNAME_DEFINITIONS.getLocalPart());
                    if (nl != null) {
                        wsdlElement = (Element) nl.item(0);
                    }
                }
            }
        }
        // write WSDL
        if (wsdlElement != null) {
            DOMUtil.serializeNode(wsdlElement, writer);
        }
        if (w3cMetadataWritten) {
            writer.writeEndElement();
        }
        // write extension elements
        if ((msEpr.elements != null) && (msEpr.elements.size() > 0)) {
            for (Element e : msEpr.elements) {
                if (e.getNamespaceURI().equals(WSDLConstants.NS_WSDL) && e.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
                // Don't write it as this is written already in Metadata
                }
                DOMUtil.serializeNode(e, writer);
            }
        }
        // TODO:write extension attributes
        // </EndpointReference>
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
    } catch (XMLStreamException e) {
        throw new WebServiceException(e);
    }
    return new W3CEndpointReference(new XMLStreamBufferSource(writer.getXMLStreamBuffer()));
}
Also used : XMLStreamBufferSource(com.sun.xml.stream.buffer.XMLStreamBufferSource) XMLStreamException(javax.xml.stream.XMLStreamException) WebServiceException(jakarta.xml.ws.WebServiceException) W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference) StreamWriterBufferCreator(com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator)

Aggregations

StreamWriterBufferCreator (com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 WebServiceException (jakarta.xml.ws.WebServiceException)3 MutableXMLStreamBuffer (com.sun.xml.stream.buffer.MutableXMLStreamBuffer)1 XMLStreamBufferSource (com.sun.xml.stream.buffer.XMLStreamBufferSource)1 WSEPRExtension (com.sun.xml.ws.addressing.WSEPRExtension)1 W3CEndpointReference (jakarta.xml.ws.wsaddressing.W3CEndpointReference)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 XMLStreamReaderToXMLStreamWriter (org.jvnet.staxex.util.XMLStreamReaderToXMLStreamWriter)1 Element (org.w3c.dom.Element)1