Search in sources :

Example 1 with XMLStreamBuffer

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

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

the class WSEndpointReference method parseEPRExtensions.

private void parseEPRExtensions() throws XMLStreamException {
    rootEprExtensions = new HashMap<>();
    StreamReaderBufferProcessor xsr = infoset.readAsXMLStreamReader();
    // parser should be either at the start element or the start document
    if (xsr.getEventType() == XMLStreamReader.START_DOCUMENT) {
        xsr.nextTag();
    }
    assert xsr.getEventType() == XMLStreamReader.START_ELEMENT;
    if (!xsr.getNamespaceURI().equals(version.nsUri)) {
        throw new WebServiceException(AddressingMessages.WRONG_ADDRESSING_VERSION(version.nsUri, xsr.getNamespaceURI()));
    }
    // since often EPR doesn't have extensions, create array lazily
    XMLStreamBuffer mark;
    String localName;
    String ns;
    while ((mark = xsr.nextTagAndMark()) != null) {
        localName = xsr.getLocalName();
        ns = xsr.getNamespaceURI();
        if (version.nsUri.equals(ns)) {
            // EPR extensions do not use the same namespace of the Addressing Version.
            // Not an extension -  SKIP
            XMLStreamReaderUtil.skipElement(xsr);
        } else {
            QName qn = new QName(ns, localName);
            rootEprExtensions.put(qn, new WSEPRExtension(mark, qn));
            XMLStreamReaderUtil.skipElement(xsr);
        }
    }
// hit to </EndpointReference> by now
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamBuffer(com.sun.xml.stream.buffer.XMLStreamBuffer) StreamReaderBufferProcessor(com.sun.xml.stream.buffer.stax.StreamReaderBufferProcessor) WSEPRExtension(com.sun.xml.ws.addressing.WSEPRExtension)

Example 3 with XMLStreamBuffer

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

the class WSEndpointReferenceTest method creaateSubtreeEPR.

/**
 * This creates {@link WSEndpointReference} that uses a fragment infoset.
 * We should really fix this in XMLStreamBuffer.
 */
private WSEndpointReference creaateSubtreeEPR() throws XMLStreamException {
    XMLStreamBuffer xsb = XMLStreamBuffer.createNewBufferFromXMLStreamReader(XMLInputFactory.newInstance().createXMLStreamReader(getClass().getClassLoader().getResourceAsStream("test-epr.xml")));
    StreamReaderBufferProcessor p = xsb.readAsXMLStreamReader();
    XMLStreamBuffer mark = p.nextTagAndMark();
    return new WSEndpointReference(mark, W3C);
}
Also used : WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) XMLStreamBuffer(com.sun.xml.stream.buffer.XMLStreamBuffer) StreamReaderBufferProcessor(com.sun.xml.stream.buffer.stax.StreamReaderBufferProcessor)

Example 4 with XMLStreamBuffer

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

the class JAXBTest method testJAXBElementMarshalling.

public void testJAXBElementMarshalling() throws Exception {
    JAXBRIContext jc = (JAXBRIContext) JAXBContext.newInstance(whitebox.jaxb.client.DetailType.class);
    DetailType dt = new DetailType();
    SOAPFault sf = createFault();
    dt.getDetails().add(sf.getDetail());
    Marshaller m = jc.createMarshaller();
    m.marshal(dt, System.out);
    XMLStreamBufferResult sbr = new XMLStreamBufferResult();
    m.setProperty(Marshaller.JAXB_FRAGMENT, true);
    m.marshal(dt, sbr);
    XMLStreamBuffer infoset = sbr.getXMLStreamBuffer();
    XMLStreamReader reader = infoset.readAsXMLStreamReader();
    if (reader.getEventType() == START_DOCUMENT)
        XMLStreamReaderUtil.nextElementContent(reader);
    verifyDetail(reader);
}
Also used : Marshaller(jakarta.xml.bind.Marshaller) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamBuffer(com.sun.xml.stream.buffer.XMLStreamBuffer) SOAPFault(jakarta.xml.soap.SOAPFault) XMLStreamBufferResult(com.sun.xml.stream.buffer.XMLStreamBufferResult) JAXBRIContext(org.glassfish.jaxb.runtime.api.JAXBRIContext)

Example 5 with XMLStreamBuffer

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

the class WSEndpointReference method parse.

/**
 * Parses inside EPR and mark all reference parameters.
 */
private void parse() throws XMLStreamException {
    // TODO: validate the EPR structure.
    // check for non-existent Address, that sort of things.
    StreamReaderBufferProcessor xsr = infoset.readAsXMLStreamReader();
    // parser should be either at the start element or the start document
    if (xsr.getEventType() == XMLStreamReader.START_DOCUMENT) {
        xsr.nextTag();
    }
    assert xsr.getEventType() == XMLStreamReader.START_ELEMENT;
    String rootLocalName = xsr.getLocalName();
    if (!xsr.getNamespaceURI().equals(version.nsUri)) {
        throw new WebServiceException(AddressingMessages.WRONG_ADDRESSING_VERSION(version.nsUri, xsr.getNamespaceURI()));
    }
    this.rootElement = new QName(xsr.getNamespaceURI(), rootLocalName);
    // since often EPR doesn't have a reference parameter, create array lazily
    List<Header> marks = null;
    while (xsr.nextTag() == XMLStreamReader.START_ELEMENT) {
        String localName = xsr.getLocalName();
        if (version.isReferenceParameter(localName)) {
            XMLStreamBuffer mark;
            while ((mark = xsr.nextTagAndMark()) != null) {
                if (marks == null) {
                    marks = new ArrayList<>();
                }
                // TODO: need a different header for member submission version
                marks.add(version.createReferenceParameterHeader(mark, xsr.getNamespaceURI(), xsr.getLocalName()));
                XMLStreamReaderUtil.skipElement(xsr);
            }
        } else if (localName.equals("Address")) {
            if (address != null) {
                throw new InvalidAddressingHeaderException(new QName(version.nsUri, rootLocalName), AddressingVersion.fault_duplicateAddressInEpr);
            }
            address = xsr.getElementText().trim();
        } else {
            XMLStreamReaderUtil.skipElement(xsr);
        }
    }
    if (marks == null) {
        this.referenceParameters = EMPTY_ARRAY;
    } else {
        this.referenceParameters = marks.toArray(new Header[0]);
    }
    if (address == null) {
        throw new InvalidAddressingHeaderException(new QName(version.nsUri, rootLocalName), version.fault_missingAddressInEpr);
    }
}
Also used : InvalidAddressingHeaderException(com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException) WebServiceException(jakarta.xml.ws.WebServiceException) Header(com.sun.xml.ws.api.message.Header) QName(javax.xml.namespace.QName) MutableXMLStreamBuffer(com.sun.xml.stream.buffer.MutableXMLStreamBuffer) XMLStreamBuffer(com.sun.xml.stream.buffer.XMLStreamBuffer) StreamReaderBufferProcessor(com.sun.xml.stream.buffer.stax.StreamReaderBufferProcessor)

Aggregations

XMLStreamBuffer (com.sun.xml.stream.buffer.XMLStreamBuffer)7 MutableXMLStreamBuffer (com.sun.xml.stream.buffer.MutableXMLStreamBuffer)4 StreamReaderBufferProcessor (com.sun.xml.stream.buffer.stax.StreamReaderBufferProcessor)4 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)3 WebServiceException (jakarta.xml.ws.WebServiceException)3 QName (javax.xml.namespace.QName)3 XMLStreamBufferMark (com.sun.xml.stream.buffer.XMLStreamBufferMark)2 StreamReaderBufferCreator (com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator)2 XMLStreamBufferResult (com.sun.xml.stream.buffer.XMLStreamBufferResult)1 WSEPRExtension (com.sun.xml.ws.addressing.WSEPRExtension)1 InvalidAddressingHeaderException (com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException)1 EndpointAddress (com.sun.xml.ws.api.EndpointAddress)1 Header (com.sun.xml.ws.api.message.Header)1 EditableWSDLPort (com.sun.xml.ws.api.model.wsdl.editable.EditableWSDLPort)1 Marshaller (jakarta.xml.bind.Marshaller)1 SOAPFault (jakarta.xml.soap.SOAPFault)1 URISyntaxException (java.net.URISyntaxException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 JAXBRIContext (org.glassfish.jaxb.runtime.api.JAXBRIContext)1