Search in sources :

Example 1 with MutableXMLStreamBuffer

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

the class StreamMessage method cacheHeaders.

private static XMLStreamBuffer cacheHeaders(XMLStreamReader reader, Map<String, String> namespaces, HeaderList headers, StreamHeaderDecoder headerDecoder) throws XMLStreamException {
    MutableXMLStreamBuffer buffer = createXMLStreamBuffer();
    StreamReaderBufferCreator creator = new StreamReaderBufferCreator();
    creator.setXMLStreamBuffer(buffer);
    // Reader is positioned at the first header block
    while (reader.getEventType() == javax.xml.stream.XMLStreamConstants.START_ELEMENT) {
        Map<String, String> headerBlockNamespaces = namespaces;
        // Collect namespaces on SOAP header block
        if (reader.getNamespaceCount() > 0) {
            headerBlockNamespaces = new HashMap<>(namespaces);
            for (int i = 0; i < reader.getNamespaceCount(); i++) {
                headerBlockNamespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
            }
        }
        // Mark
        XMLStreamBuffer mark = new XMLStreamBufferMark(headerBlockNamespaces, creator);
        // Create Header
        headers.add(headerDecoder.decodeHeader(reader, mark));
        // Cache the header block
        // After caching Reader will be positioned at next header block or
        // the end of the </soap:header>
        creator.createElementFragment(reader, false);
        if (reader.getEventType() != XMLStreamConstants.START_ELEMENT && reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
            XMLStreamReaderUtil.nextElementContent(reader);
        }
    }
    return buffer;
}
Also used : StreamReaderBufferCreator(com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator) MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamBuffer(com.sun.xml.stream.buffer.XMLStreamBuffer) XMLStreamBufferMark(com.sun.xml.stream.buffer.XMLStreamBufferMark)

Example 2 with MutableXMLStreamBuffer

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

the class WSDLGenResolver method getAbstractWSDL.

/**
 * Updates filename if the suggested filename need to be changed in
 * wsdl:import. If the metadata already contains abstract wsdl(i.e. a WSDL
 * which has the porttype), then the abstract wsdl shouldn't be generated
 *
 * return null if abstract WSDL need not be generated
 *        Result the abstract WSDL
 */
public Result getAbstractWSDL(Holder<String> filename) {
    if (abstractWsdl != null) {
        filename.value = abstractWsdl.getURL().toString();
        // Don't generate abstract WSDL
        return null;
    }
    URL url = createURL(filename.value);
    MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
    xsb.setSystemId(url.toExternalForm());
    SDDocumentSource abstractWsdlSource = SDDocumentSource.create(url, xsb);
    newDocs.add(abstractWsdlSource);
    XMLStreamBufferResult r = new XMLStreamBufferResult(xsb);
    r.setSystemId(filename.value);
    return r;
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) XMLStreamBufferResult(com.sun.xml.stream.buffer.XMLStreamBufferResult) URL(java.net.URL)

Example 3 with MutableXMLStreamBuffer

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

the class JAXBHeader method readHeader.

public XMLStreamReader readHeader() throws XMLStreamException {
    if (infoset == null) {
        MutableXMLStreamBuffer buffer = new MutableXMLStreamBuffer();
        writeTo(buffer.createFromXMLStreamWriter());
        infoset = buffer;
    }
    return infoset.readAsXMLStreamReader();
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer)

Example 4 with MutableXMLStreamBuffer

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

the class JAXBMessage method create.

public static Message create(BindingContext context, Object jaxbObject, SOAPVersion soapVersion, MessageHeaders headers, AttachmentSet attachments) {
    if (!context.hasSwaRef()) {
        return new JAXBMessage(context, jaxbObject, soapVersion, headers, attachments);
    }
    try {
        MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
        Marshaller m = context.createMarshaller();
        AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachments);
        m.setAttachmentMarshaller(am);
        am.cleanup();
        m.marshal(jaxbObject, xsb.createFromXMLStreamWriter());
        // any way to reuse this XMLStreamBuffer in StreamMessage?
        return new StreamMessage(headers, attachments, xsb.readAsXMLStreamReader(), soapVersion);
    } catch (JAXBException | XMLStreamException e) {
        throw new WebServiceException(e);
    }
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) Marshaller(jakarta.xml.bind.Marshaller) AttachmentMarshaller(jakarta.xml.bind.attachment.AttachmentMarshaller) XMLStreamException(javax.xml.stream.XMLStreamException) WebServiceException(jakarta.xml.ws.WebServiceException) JAXBException(jakarta.xml.bind.JAXBException) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage)

Example 5 with MutableXMLStreamBuffer

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

the class JAXBMessage method create.

/**
 * Creates a {@link Message} backed by a JAXB bean.
 *
 * @param bridge
 *      Specify the payload tag name and how {@code jaxbObject} is bound.
 */
public static Message create(XMLBridge bridge, Object jaxbObject, SOAPVersion soapVer) {
    if (!bridge.context().hasSwaRef()) {
        return new JAXBMessage(bridge, jaxbObject, soapVer);
    }
    try {
        MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
        AttachmentSetImpl attachments = new AttachmentSetImpl();
        AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachments);
        bridge.marshal(jaxbObject, xsb.createFromXMLStreamWriter(), am);
        am.cleanup();
        // any way to reuse this XMLStreamBuffer in StreamMessage?
        return new StreamMessage(null, attachments, xsb.readAsXMLStreamReader(), soapVer);
    } catch (JAXBException | XMLStreamException e) {
        throw new WebServiceException(e);
    }
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamException(javax.xml.stream.XMLStreamException) WebServiceException(jakarta.xml.ws.WebServiceException) JAXBException(jakarta.xml.bind.JAXBException) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage) AttachmentSetImpl(com.sun.xml.ws.message.AttachmentSetImpl)

Aggregations

MutableXMLStreamBuffer (com.sun.xml.stream.buffer.MutableXMLStreamBuffer)17 WebServiceException (jakarta.xml.ws.WebServiceException)6 XMLStreamBufferResult (com.sun.xml.stream.buffer.XMLStreamBufferResult)4 URL (java.net.URL)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)4 StreamReaderBufferCreator (com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator)3 SDDocumentSource (com.sun.xml.ws.api.server.SDDocumentSource)3 JAXBException (jakarta.xml.bind.JAXBException)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 XMLStreamBuffer (com.sun.xml.stream.buffer.XMLStreamBuffer)2 XMLStreamBufferMark (com.sun.xml.stream.buffer.XMLStreamBufferMark)2 StreamMessage (com.sun.xml.ws.message.stream.StreamMessage)2 Marshaller (jakarta.xml.bind.Marshaller)2 AttachmentMarshaller (jakarta.xml.bind.attachment.AttachmentMarshaller)2 NotNull (com.sun.istack.NotNull)1 StreamWriterBufferCreator (com.sun.xml.stream.buffer.stax.StreamWriterBufferCreator)1 EndpointAddress (com.sun.xml.ws.api.EndpointAddress)1 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)1 EditableWSDLPort (com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLPort)1