Search in sources :

Example 1 with HeaderList

use of com.sun.xml.ws.api.message.HeaderList in project metro-jax-ws by eclipse-ee4j.

the class StreamMessage method readEnvelope.

private static void readEnvelope(StreamMessage message) {
    if (message.envelopeReader == null)
        return;
    XMLStreamReader reader = message.envelopeReader;
    message.envelopeReader = null;
    SOAPVersion soapVersion = message.soapVersion;
    // Move to soap:Envelope and verify
    if (reader.getEventType() != XMLStreamConstants.START_ELEMENT)
        XMLStreamReaderUtil.nextElementContent(reader);
    XMLStreamReaderUtil.verifyReaderState(reader, XMLStreamConstants.START_ELEMENT);
    if (SOAP_ENVELOPE.equals(reader.getLocalName()) && !soapVersion.nsUri.equals(reader.getNamespaceURI())) {
        throw new VersionMismatchException(soapVersion, soapVersion.nsUri, reader.getNamespaceURI());
    }
    XMLStreamReaderUtil.verifyTag(reader, soapVersion.nsUri, SOAP_ENVELOPE);
    TagInfoset envelopeTag = new TagInfoset(reader);
    // Collect namespaces on soap:Envelope
    Map<String, String> namespaces = new HashMap<>();
    for (int i = 0; i < reader.getNamespaceCount(); i++) {
        namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
    }
    // Move to next element
    XMLStreamReaderUtil.nextElementContent(reader);
    XMLStreamReaderUtil.verifyReaderState(reader, javax.xml.stream.XMLStreamConstants.START_ELEMENT);
    HeaderList headers = null;
    TagInfoset headerTag = null;
    if (reader.getLocalName().equals(SOAP_HEADER) && reader.getNamespaceURI().equals(soapVersion.nsUri)) {
        headerTag = new TagInfoset(reader);
        // Collect namespaces on soap:Header
        for (int i = 0; i < reader.getNamespaceCount(); i++) {
            namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
        }
        // skip <soap:Header>
        XMLStreamReaderUtil.nextElementContent(reader);
        // If SOAP header blocks are present (i.e. not <soap:Header/>)
        if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
            headers = new HeaderList(soapVersion);
            try {
                // Cache SOAP header blocks
                StreamHeaderDecoder headerDecoder = SOAPVersion.SOAP_11.equals(soapVersion) ? SOAP11StreamHeaderDecoder : SOAP12StreamHeaderDecoder;
                cacheHeaders(reader, namespaces, headers, headerDecoder);
            } catch (XMLStreamException e) {
                // TODO need to throw more meaningful exception
                throw new WebServiceException(e);
            }
        }
        // Move to soap:Body
        XMLStreamReaderUtil.nextElementContent(reader);
    }
    // Verify that <soap:Body> is present
    XMLStreamReaderUtil.verifyTag(reader, soapVersion.nsUri, SOAP_BODY);
    TagInfoset bodyTag = new TagInfoset(reader);
    String bodyPrologue = XMLStreamReaderUtil.nextWhiteSpaceContent(reader);
    message.init(envelopeTag, headerTag, message.attachmentSet, headers, bodyPrologue, bodyTag, null, reader, soapVersion);
// when there's no payload,
// it's tempting to use EmptyMessageImpl, but it doesn't preserve the infoset
// of <envelope>,<header>, and <body>, so we need to stick to StreamMessage.
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) HashMap(java.util.HashMap) SOAPVersion(com.sun.xml.ws.api.SOAPVersion) TagInfoset(com.sun.xml.ws.encoding.TagInfoset) HeaderList(com.sun.xml.ws.api.message.HeaderList) VersionMismatchException(com.sun.xml.ws.protocol.soap.VersionMismatchException)

Example 2 with HeaderList

use of com.sun.xml.ws.api.message.HeaderList in project metro-jax-ws by eclipse-ee4j.

the class SAAJMessageTester method testSOAP11MessageAsJAXB.

public void testSOAP11MessageAsJAXB() {
    try {
        HeaderList hl = msg.getHeaders();
        JAXBContext ctxt = null;
        Unmarshaller unmarshaller = null;
        try {
            ctxt = JAXBContext.newInstance("whitebox.message.saaj.types");
            unmarshaller = ctxt.createUnmarshaller();
        } catch (JAXBException e) {
            e.printStackTrace();
            assertTrue(false);
        }
        int i = 0;
        // validate the headers form unmarshalled jaxb bean
        for (Header h : hl) {
            assertTrue(validateHeader(h, unmarshaller, headers[i++], SOAPVersion.SOAP_11));
        }
        // validate body
        assertTrue(msg.getPayloadLocalPart().equals("Body") && msg.getPayloadNamespaceURI().equals("urn:test:types"));
        JAXBElement<ValueType> body = msg.readPayloadAsJAXB(unmarshaller);
        assertTrue(body.getValue().getValue().equals("Its Body"));
    } catch (JAXBException e) {
        e.printStackTrace();
        assertTrue(false);
    }
}
Also used : Header(com.sun.xml.ws.api.message.Header) ValueType(whitebox.message.saaj.types.ValueType) HeaderList(com.sun.xml.ws.api.message.HeaderList) JAXBException(jakarta.xml.bind.JAXBException) JAXBContext(jakarta.xml.bind.JAXBContext) Unmarshaller(jakarta.xml.bind.Unmarshaller)

Example 3 with HeaderList

use of com.sun.xml.ws.api.message.HeaderList in project metro-jax-ws by eclipse-ee4j.

the class SourceMessageTester method testSOAP11MessageAsJAXB.

public void testSOAP11MessageAsJAXB() {
    try {
        Message msg = createPayloadSourceMessage();
        HeaderList hl = msg.getHeaders();
        JAXBContext ctxt = null;
        Unmarshaller unmarshaller = null;
        try {
            ctxt = JAXBContext.newInstance("whitebox.message.source.types");
            unmarshaller = ctxt.createUnmarshaller();
        } catch (JAXBException e) {
            e.printStackTrace();
            assertTrue(false);
        }
        int i = 0;
        // validate the headers form unmarshalled jaxb bean
        for (Header h : hl) {
            assertTrue(validateHeader(h, unmarshaller, headers[i++], SOAPVersion.SOAP_11));
        }
        // validate body
        assertTrue(msg.getPayloadLocalPart().equals("Body") && msg.getPayloadNamespaceURI().equals("urn:test:types"));
        JAXBElement<ValueType> body = msg.readPayloadAsJAXB(unmarshaller);
        assertTrue(body.getValue().getValue().equals("Its Body"));
    } catch (JAXBException e) {
        e.printStackTrace();
        assertTrue(false);
    }
}
Also used : Message(com.sun.xml.ws.api.message.Message) PayloadSourceMessage(com.sun.xml.ws.message.source.PayloadSourceMessage) Header(com.sun.xml.ws.api.message.Header) ValueType(whitebox.message.source.types.ValueType) HeaderList(com.sun.xml.ws.api.message.HeaderList) JAXBException(jakarta.xml.bind.JAXBException) JAXBContext(jakarta.xml.bind.JAXBContext) Unmarshaller(jakarta.xml.bind.Unmarshaller)

Aggregations

HeaderList (com.sun.xml.ws.api.message.HeaderList)3 Header (com.sun.xml.ws.api.message.Header)2 JAXBContext (jakarta.xml.bind.JAXBContext)2 JAXBException (jakarta.xml.bind.JAXBException)2 Unmarshaller (jakarta.xml.bind.Unmarshaller)2 SOAPVersion (com.sun.xml.ws.api.SOAPVersion)1 Message (com.sun.xml.ws.api.message.Message)1 TagInfoset (com.sun.xml.ws.encoding.TagInfoset)1 PayloadSourceMessage (com.sun.xml.ws.message.source.PayloadSourceMessage)1 VersionMismatchException (com.sun.xml.ws.protocol.soap.VersionMismatchException)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 HashMap (java.util.HashMap)1 ValueType (whitebox.message.saaj.types.ValueType)1 ValueType (whitebox.message.source.types.ValueType)1