Search in sources :

Example 1 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders in project spring-integration by spring-projects.

the class DefaultSoapHeaderMapperTests method testDoNotOverriderSoapAction.

@Test
public void testDoNotOverriderSoapAction() throws Exception {
    MimeHeaders mimeHeaders = new MimeHeaders();
    String testSoapAction = "fooAction";
    mimeHeaders.setHeader(TransportConstants.HEADER_SOAP_ACTION, testSoapAction);
    String soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"></soapenv:Envelope>";
    SOAPMessage message = MessageFactory.newInstance().createMessage(mimeHeaders, new ByteArrayInputStream(soap.getBytes()));
    SaajSoapMessage soapMessage = new SaajSoapMessage(message);
    DefaultSoapHeaderMapper headerMapper = new DefaultSoapHeaderMapper();
    headerMapper.fromHeadersToRequest(new MessageHeaders(null), soapMessage);
    assertThat(soapMessage.getSoapAction()).isEqualTo(testSoapAction);
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageHeaders(org.springframework.messaging.MessageHeaders) SOAPMessage(jakarta.xml.soap.SOAPMessage) Test(org.junit.Test)

Example 2 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders in project spring-integration by spring-projects.

the class DefaultSoapHeaderMapperTests method testRealSoapHeader.

@Test
public void testRealSoapHeader() throws Exception {
    String soap = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soapenv:Header>" + "<auth>" + "<username>user</username>" + "<password>pass</password>" + "</auth>" + "<bar>BAR</bar>" + "<baz>BAZ</baz>" + "<qux>qux</qux>" + "</soapenv:Header>" + "<soapenv:Body>" + "<foo>foo</foo>" + "</soapenv:Body>" + "</soapenv:Envelope>";
    SOAPMessage message = MessageFactory.newInstance().createMessage(new MimeHeaders(), new ByteArrayInputStream(soap.getBytes("UTF-8")));
    SoapMessage soapMessage = new SaajSoapMessage(message);
    DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
    String authHeader = "auth";
    mapper.setRequestHeaderNames(authHeader, "ba*");
    Map<String, Object> headers = mapper.toHeadersFromRequest(soapMessage);
    assertThat(headers.get(authHeader)).isNotNull();
    assertThat(headers.get(authHeader)).isInstanceOf(SoapHeaderElement.class);
    SoapHeaderElement header = (SoapHeaderElement) headers.get(authHeader);
    DOMSource source = (DOMSource) header.getSource();
    NodeList nodeList = source.getNode().getChildNodes();
    assertThat(nodeList.item(0).getNodeName()).isEqualTo("username");
    assertThat(nodeList.item(0).getFirstChild().getNodeValue()).isEqualTo("user");
    assertThat(nodeList.item(1).getNodeName()).isEqualTo("password");
    assertThat(nodeList.item(1).getFirstChild().getNodeValue()).isEqualTo("pass");
    header = (SoapHeaderElement) headers.get("bar");
    assertThat(header).isNotNull();
    source = (DOMSource) header.getSource();
    nodeList = source.getNode().getChildNodes();
    assertThat(nodeList.item(0).getNodeValue()).isEqualTo("BAR");
    header = (SoapHeaderElement) headers.get("baz");
    assertThat(header).isNotNull();
    source = (DOMSource) header.getSource();
    nodeList = source.getNode().getChildNodes();
    assertThat(nodeList.item(0).getNodeValue()).isEqualTo("BAZ");
    assertThat(headers.get("qux")).isNull();
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) DOMSource(javax.xml.transform.dom.DOMSource) SoapHeaderElement(org.springframework.ws.soap.SoapHeaderElement) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeList(org.w3c.dom.NodeList) SOAPMessage(jakarta.xml.soap.SOAPMessage) SoapMessage(org.springframework.ws.soap.SoapMessage) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) Test(org.junit.Test)

Example 3 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders in project metro-jax-ws by eclipse-ee4j.

the class StreamMessageTest method testWriteMtomToStreamClientRequest.

public void testWriteMtomToStreamClientRequest() throws Exception {
    // DISI may set the packet.state to State.ClientRequest
    // ((Packet)mc).setState(State.ClientRequest)
    InputStream is = null;
    ByteArrayOutputStream baos = null;
    ByteArrayInputStream bais = null;
    try {
        String ctype = "multipart/related; boundary=MIME_Boundary; " + "start=\"<ff2b0fb4-9bcf-4ff5-ba16-d3436c78c3fd>\"; " + "type=\"application/xop+xml\"; start-info=\"text/xml\"";
        MessageContextFactory mcf = MessageContextFactory.createFactory(new MTOMFeature(true));
        is = getClass().getClassLoader().getResourceAsStream("etc/testMtomMessage_osb_disi.msg");
        MessageContext mc = mcf.createContext(is, ctype);
        Packet packet = (Packet) mc;
        Message message = packet.getInternalMessage();
        assertTrue("StreamMessage not found, got : " + message.getClass(), StreamMessage.class.isAssignableFrom(message.getClass()));
        baos = new ByteArrayOutputStream();
        ((Packet) mc).setState(State.ClientRequest);
        mc.writeTo(baos);
        bais = new ByteArrayInputStream(baos.toByteArray());
        MessageFactory mf = MessageFactory.newInstance();
        MimeHeaders mh = new MimeHeaders();
        mh.addHeader("Content-Type", ctype);
        SOAPMessage sm = mf.createMessage(mh, bais);
        assertEquals("wrong attachment count", 1, sm.countAttachments());
        AttachmentPart ap = (AttachmentPart) sm.getAttachments().next();
        assertEquals("wrong attachemnt Content-Id", "<testAttachmentContentId>", ap.getContentId());
        NodeList nl = sm.getSOAPBody().getElementsByTagNameNS(MtomCodec.XOP_NAMESPACEURI, MtomCodec.XOP_LOCALNAME);
        assertEquals(MtomCodec.XOP_NAMESPACEURI + ":" + MtomCodec.XOP_LOCALNAME + " not found", 1, nl.getLength());
        Element elt = (Element) nl.item(0);
        assertEquals("wrong href value", "cid:testAttachmentContentId", elt.getAttribute("href"));
    } finally {
        Exception e = null;
        try {
            if (is != null)
                is.close();
        } catch (IOException e1) {
            e = e1;
        }
        try {
            if (baos != null)
                baos.close();
        } catch (IOException e2) {
            e = e2;
        }
        try {
            if (bais != null)
                bais.close();
        } catch (Exception e3) {
            e = e3;
        }
        if (e != null)
            throw e;
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) AttachmentPart(jakarta.xml.soap.AttachmentPart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SOAPMessage(jakarta.xml.soap.SOAPMessage) IOException(java.io.IOException) MimeHeaders(jakarta.xml.soap.MimeHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageContextFactory(com.oracle.webservices.api.message.MessageContextFactory) MessageContext(com.oracle.webservices.api.message.MessageContext)

Example 4 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders in project metro-jax-ws by eclipse-ee4j.

the class StreamMessageTest method testWriteMtomToStream.

public void testWriteMtomToStream() throws Exception {
    // Ensure writing StreamMessage to OutputputStream preserves CID and
    // does not create duplicate attachment.  We check this by re-parsing
    // as a SOAP message and verifying the contents.
    InputStream is = null;
    ByteArrayOutputStream baos = null;
    ByteArrayInputStream bais = null;
    try {
        String ctype = "multipart/related;type=\"application/xop+xml\";" + "boundary=\"----=_Part_0_1145105632.1353005695468\";" + "start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
        MessageContextFactory mcf = MessageContextFactory.createFactory(new MTOMFeature(true));
        is = getClass().getClassLoader().getResourceAsStream("etc/testMtomMessageReload_01.msg");
        MessageContext mc = mcf.createContext(is, ctype);
        Packet packet = (Packet) mc;
        Message message = packet.getInternalMessage();
        assertTrue("StreamMessage not found, got : " + message.getClass(), StreamMessage.class.isAssignableFrom(message.getClass()));
        baos = new ByteArrayOutputStream();
        mc.writeTo(baos);
        bais = new ByteArrayInputStream(baos.toByteArray());
        MessageFactory mf = MessageFactory.newInstance();
        MimeHeaders mh = new MimeHeaders();
        mh.addHeader("Content-Type", ctype);
        SOAPMessage sm = mf.createMessage(mh, bais);
        assertEquals("wrong attachment count", 1, sm.countAttachments());
        AttachmentPart ap = (AttachmentPart) sm.getAttachments().next();
        assertEquals("wrong attachemnt Content-Id", "<534475ae-bdab-4594-9f97-c09908bacfbd>", ap.getContentId());
        NodeList nl = sm.getSOAPBody().getElementsByTagNameNS(MtomCodec.XOP_NAMESPACEURI, MtomCodec.XOP_LOCALNAME);
        assertEquals(MtomCodec.XOP_NAMESPACEURI + ":" + MtomCodec.XOP_LOCALNAME + " not found", 1, nl.getLength());
        Element elt = (Element) nl.item(0);
        assertEquals("wrong href value", "cid:534475ae-bdab-4594-9f97-c09908bacfbd", elt.getAttribute("href"));
    } finally {
        Exception e = null;
        try {
            if (is != null)
                is.close();
        } catch (IOException e1) {
            e = e1;
        }
        try {
            if (baos != null)
                baos.close();
        } catch (IOException e2) {
            e = e2;
        }
        try {
            if (bais != null)
                bais.close();
        } catch (Exception e3) {
            e = e3;
        }
        if (e != null)
            throw e;
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) AttachmentPart(jakarta.xml.soap.AttachmentPart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SOAPMessage(jakarta.xml.soap.SOAPMessage) IOException(java.io.IOException) MimeHeaders(jakarta.xml.soap.MimeHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageContextFactory(com.oracle.webservices.api.message.MessageContextFactory) MessageContext(com.oracle.webservices.api.message.MessageContext)

Example 5 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders in project metro-jax-ws by eclipse-ee4j.

the class Client method testUsingAxisMsg.

public void testUsingAxisMsg() throws IOException, SOAPException {
    TestServiceService service = new TestServiceService();
    Dispatch<SOAPMessage> disp = service.createDispatch(new QName("http://server.jaxws195.fromjava/", "TestServicePort"), SOAPMessage.class, Service.Mode.MESSAGE);
    MimeHeaders mhs = new MimeHeaders();
    mhs.addHeader("Content-Type", "text/xml");
    SOAPMessage msg = SOAPVersion.SOAP_11.saajMessageFactory.createMessage(mhs, new ByteArrayInputStream(axisMsg.getBytes()));
    disp.invoke(msg);
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Aggregations

MimeHeaders (jakarta.xml.soap.MimeHeaders)30 SOAPMessage (jakarta.xml.soap.SOAPMessage)27 ByteArrayInputStream (java.io.ByteArrayInputStream)24 MessageFactory (jakarta.xml.soap.MessageFactory)19 Packet (com.sun.xml.ws.api.message.Packet)13 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)12 Element (org.w3c.dom.Element)12 Message (com.sun.xml.ws.api.message.Message)7 QName (javax.xml.namespace.QName)7 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)6 BindingProvider (jakarta.xml.ws.BindingProvider)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 Node (org.w3c.dom.Node)4 MessageContextFactory (com.oracle.webservices.api.message.MessageContextFactory)3 AttachmentPart (jakarta.xml.soap.AttachmentPart)3 SOAPException (jakarta.xml.soap.SOAPException)3 MTOMFeature (jakarta.xml.ws.soap.MTOMFeature)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3