Search in sources :

Example 11 with MutableXMLStreamBuffer

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

the class StreamMessage method copy.

// TODO: this method should be probably rewritten to respect spaces between elements; is it used at all?
@Override
public Message copy() {
    if (envelopeReader != null)
        readEnvelope(this);
    try {
        assert unconsumed();
        // but we don't want to mark it as consumed
        consumedAt = null;
        MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
        StreamReaderBufferCreator c = new StreamReaderBufferCreator(xsb);
        // preserving inscope namespaces from envelope, and body. Other option
        // would be to create a filtering XMLStreamReader from reader+envelopeTag+bodyTag
        c.storeElement(envelopeTag.nsUri, envelopeTag.localName, envelopeTag.prefix, envelopeTag.ns);
        c.storeElement(bodyTag.nsUri, bodyTag.localName, bodyTag.prefix, bodyTag.ns);
        if (hasPayload()) {
            // Loop all the way for multi payload case
            while (reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
                String name = reader.getLocalName();
                String nsUri = reader.getNamespaceURI();
                if (isBodyElement(name, nsUri) || (reader.getEventType() == XMLStreamConstants.END_DOCUMENT))
                    break;
                c.create(reader);
                // those won't be in the message itself, but we store them in field bodyEpilogue
                if (reader.isWhiteSpace()) {
                    bodyEpilogue = XMLStreamReaderUtil.currentWhiteSpaceContent(reader);
                } else {
                    // clear it in case the existing was not the last one
                    // (we are interested only in the last one?)
                    bodyEpilogue = null;
                }
            }
        }
        // create structure element for </Body>
        c.storeEndElement();
        // create structure element for </Envelope>
        c.storeEndElement();
        // create structure element for END_DOCUMENT
        c.storeEndElement();
        XMLStreamReaderUtil.readRest(reader);
        XMLStreamReaderUtil.close(reader);
        XMLStreamReaderFactory.recycle(reader);
        reader = xsb.readAsXMLStreamReader();
        XMLStreamReader clone = xsb.readAsXMLStreamReader();
        // advance to the start tag of the <Body> first child element
        proceedToRootElement(reader);
        proceedToRootElement(clone);
        return new StreamMessage(envelopeTag, headerTag, attachmentSet, HeaderList.copy(headers), bodyPrologue, bodyTag, bodyEpilogue, clone, soapVersion).copyFrom(this);
    } catch (XMLStreamException e) {
        throw new WebServiceException("Failed to copy a message", e);
    }
}
Also used : StreamReaderBufferCreator(com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator) MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) WebServiceException(jakarta.xml.ws.WebServiceException)

Example 12 with MutableXMLStreamBuffer

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

the class ProblemActionHeader method readHeader.

public XMLStreamReader readHeader() throws XMLStreamException {
    MutableXMLStreamBuffer buf = new MutableXMLStreamBuffer();
    XMLStreamWriter w = buf.createFromXMLStreamWriter();
    writeTo(w);
    return buf.readAsXMLStreamReader();
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 13 with MutableXMLStreamBuffer

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

the class StringHeader method readHeader.

public XMLStreamReader readHeader() throws XMLStreamException {
    MutableXMLStreamBuffer buf = new MutableXMLStreamBuffer();
    XMLStreamWriter w = buf.createFromXMLStreamWriter();
    writeTo(w);
    return buf.readAsXMLStreamReader();
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 14 with MutableXMLStreamBuffer

use of com.sun.xml.stream.buffer.MutableXMLStreamBuffer 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 15 with MutableXMLStreamBuffer

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

the class WSEndpointReference method createWithAddress.

/**
 * Creates a new {@link WSEndpointReference} by replacing the address of this EPR
 * to the new one.
 *
 * <p>
 * The following example shows how you can use this to force an HTTPS EPR,
 * when the endpoint can serve both HTTP and HTTPS requests.
 * <pre>
 * if(epr.getAddress().startsWith("http:"))
 *   epr = epr.createWithAddress("https:"+epr.getAddress().substring(5));
 * </pre>
 *
 * @param newAddress
 *      This is a complete URL to be written inside &lt;Address&gt; element of the EPR,
 *      such as "http://foo.bar/abc/def"
 */
@NotNull
public WSEndpointReference createWithAddress(@NotNull final String newAddress) {
    MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
    XMLFilterImpl filter = new XMLFilterImpl() {

        private boolean inAddress = false;

        @Override
        public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
            if (localName.equals("Address") && uri.equals(version.nsUri)) {
                inAddress = true;
            }
            super.startElement(uri, localName, qName, atts);
        }

        @Override
        public void characters(char[] ch, int start, int length) throws SAXException {
            if (!inAddress) {
                super.characters(ch, start, length);
            }
        }

        @Override
        public void endElement(String uri, String localName, String qName) throws SAXException {
            if (inAddress) {
                super.characters(newAddress.toCharArray(), 0, newAddress.length());
            }
            inAddress = false;
            super.endElement(uri, localName, qName);
        }
    };
    filter.setContentHandler(xsb.createFromSAXBufferCreator());
    try {
        infoset.writeTo(filter, false);
    } catch (SAXException e) {
        // impossible since we are writing from XSB to XSB.
        throw new AssertionError(e);
    }
    return new WSEndpointReference(xsb, version);
}
Also used : MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLFilterImpl(org.xml.sax.helpers.XMLFilterImpl) NotNull(com.sun.istack.NotNull)

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