Search in sources :

Example 1 with StreamMessage

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

the class SAAJFactoryTest method testResetDefaultNamespaceToGlobalWithJDK.

/**
 * Test whether SAAJFactory.readAsSOAPMessage can handle default namespace reset correctly.
 *
 * <p>
 * This test emulates JDK-8159058 issue. The issue is that the default namespace reset was not respected
 * with built-in JDK XML input factory (it worked well with woodstax).
 * </p>
 *
 * <p>
 * This test operates against JDK XMLInputFactory.
 * </p>
 */
public void testResetDefaultNamespaceToGlobalWithJDK() throws Exception {
    XMLInputFactory inputFactory = getBuiltInJdkXmlInputFactory();
    XMLStreamReader envelope = inputFactory.createXMLStreamReader(new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<s:Body>" + "<SampleServiceRequest xmlns=\"http://sample.ex.org/\">" + "<RequestParams xmlns=\"\">" + "<Param1>hogehoge</Param1>" + "<Param2>fugafuga</Param2>" + "</RequestParams>" + "</SampleServiceRequest>" + "</s:Body>" + "</s:Envelope>"));
    StreamMessage streamMessage = new StreamMessage(SOAPVersion.SOAP_11, envelope, null);
    SAAJFactory saajFac = new SAAJFactory();
    SOAPMessage soapMessage = saajFac.readAsSOAPMessage(SOAPVersion.SOAP_11, streamMessage);
    // check object model
    SOAPElement request = (SOAPElement) soapMessage.getSOAPBody().getFirstChild();
    assertEquals("SampleServiceRequest", request.getLocalName());
    assertEquals("http://sample.ex.org/", request.getNamespaceURI());
    SOAPElement params = (SOAPElement) request.getFirstChild();
    assertEquals("RequestParams", params.getLocalName());
    assertNull(params.getNamespaceURI());
    SOAPElement param1 = (SOAPElement) params.getFirstChild();
    assertEquals("Param1", param1.getLocalName());
    assertNull(param1.getNamespaceURI());
    Element param2 = (Element) params.getChildNodes().item(1);
    assertEquals("Param2", param2.getLocalName());
    assertNull(param2.getNamespaceURI());
    // check the message as string
    assertEquals("<SampleServiceRequest xmlns=\"http://sample.ex.org/\">" + "<RequestParams xmlns=\"\">" + "<Param1>hogehoge</Param1>" + "<Param2>fugafuga</Param2>" + "</RequestParams>" + "</SampleServiceRequest>", nodeToText(request));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) SAAJFactory(com.sun.xml.ws.api.message.saaj.SAAJFactory) SOAPElement(jakarta.xml.soap.SOAPElement) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) SOAPElement(jakarta.xml.soap.SOAPElement) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage) SOAPMessage(jakarta.xml.soap.SOAPMessage) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 2 with StreamMessage

use of com.sun.xml.ws.message.stream.StreamMessage 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 3 with StreamMessage

use of com.sun.xml.ws.message.stream.StreamMessage 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)

Example 4 with StreamMessage

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

the class StreamMessageTest method createSOAP11StreamMessage.

private StreamMessage createSOAP11StreamMessage(String msg) throws IOException {
    Codec codec = Codecs.createSOAPEnvelopeXmlCodec(SOAPVersion.SOAP_11);
    Packet packet = new Packet();
    ByteArrayInputStream in = new ByteArrayInputStream(msg.getBytes());
    codec.decode(in, "text/xml", packet);
    return (StreamMessage) packet.getMessage();
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Codec(com.sun.xml.ws.api.pipe.Codec) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage)

Example 5 with StreamMessage

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

the class StreamMessageCopyTest method testEmptyPayload.

public void testEmptyPayload() throws Exception {
    String soapMsg = "<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'><S:Body/></S:Envelope>";
    StringBuilder sb = new StringBuilder(soapMsg);
    StreamMessage msg = createSOAP11StreamMessage(sb.toString());
    Message msg1 = msg.copy();
    msg.consume();
    msg1.consume();
}
Also used : Message(com.sun.xml.ws.api.message.Message) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage)

Aggregations

StreamMessage (com.sun.xml.ws.message.stream.StreamMessage)10 Message (com.sun.xml.ws.api.message.Message)3 SAAJFactory (com.sun.xml.ws.api.message.saaj.SAAJFactory)3 SOAPMessage (jakarta.xml.soap.SOAPMessage)3 StringReader (java.io.StringReader)3 XMLInputFactory (javax.xml.stream.XMLInputFactory)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 MutableXMLStreamBuffer (com.sun.xml.stream.buffer.MutableXMLStreamBuffer)2 Packet (com.sun.xml.ws.api.message.Packet)2 Codec (com.sun.xml.ws.api.pipe.Codec)2 JAXBException (jakarta.xml.bind.JAXBException)2 SOAPElement (jakarta.xml.soap.SOAPElement)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 Element (org.w3c.dom.Element)2 AttachmentSetImpl (com.sun.xml.ws.message.AttachmentSetImpl)1 Marshaller (jakarta.xml.bind.Marshaller)1 AttachmentMarshaller (jakarta.xml.bind.attachment.AttachmentMarshaller)1