Search in sources :

Example 16 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 17 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders in project openmq by eclipse-ee4j.

the class UMSServlet method getHeaders.

/**
 * Returns a <code>MimeHeaders</code> object that contains the headers in the given <code>HttpServletRequest</code>
 * object.
 *
 * @param req the <code>HttpServletRequest</code> object that a messaging provider sent to the servlet
 * @return a new <code>MimeHeaders</code> object containing the headers in the message sent to the servlet
 */
protected static MimeHeaders getHeaders(HttpServletRequest req) {
    Enumeration enum2 = req.getHeaderNames();
    MimeHeaders headers = new MimeHeaders();
    while (enum2.hasMoreElements()) {
        String headerName = (String) enum2.nextElement();
        String headerValue = req.getHeader(headerName);
        StringTokenizer values = new StringTokenizer(headerValue, ",");
        while (values.hasMoreTokens()) {
            headers.addHeader(headerName, values.nextToken().trim());
        }
    }
    return headers;
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) StringTokenizer(java.util.StringTokenizer) Enumeration(java.util.Enumeration)

Example 18 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders in project openmq by eclipse-ee4j.

the class UMSServlet method doXmlMessaging.

/**
 * Http request services. HTTP requests are transformed into SOAP messages and dispated to the appropriate services.
 */
public void doXmlMessaging(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    SOAPMessage msg = null;
    try {
        // Get all the headers from the HTTP request.
        MimeHeaders headers = getHeaders(req);
        // Get the body of the HTTP request.
        InputStream is = req.getInputStream();
        // Now internalize the contents of a HTTP request and
        // create a SOAPMessage
        msg = mfactory.createMessage(headers, is);
        SOAPMessage reply = null;
        /**
         * Dispatch message to mq soap service.
         */
        reply = onMessage(msg);
        if (reply != null) {
            if (reply.saveRequired()) {
                reply.saveChanges();
            }
            if (isSOAPFault(reply)) {
                resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            } else {
                resp.setStatus(HttpServletResponse.SC_OK);
            }
            // remove content-length header field
            reply.getMimeHeaders().removeHeader(CONTENT_LENGTH);
            putHeaders(reply.getMimeHeaders(), resp);
            String[] sa = reply.getMimeHeaders().getHeader(CONTENT_TYPE);
            if (sa == null || sa.length == 0) {
                // XXX:
                // int acount = reply.countAttachments();
                resp.setHeader(CONTENT_TYPE, TEXT_XML);
            }
            // Write out the message on the response stream.
            OutputStream os = resp.getOutputStream();
            reply.writeTo(os);
            os.flush();
        } else {
            resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
        }
    } catch (Throwable ex) {
        /**
         * Log exception.
         */
        logger.log(Level.WARNING, ex.getMessage(), ex);
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 19 with MimeHeaders

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

the class StreamMessageTest method testWriteSwaToStreamClientRequest.

// Bug 17367334
public void testWriteSwaToStreamClientRequest() throws Exception {
    String ctype = "multipart/related; boundary=MIME_Boundary; " + "start=\"<6232425701115978772--54bee05.140acdf4f8a.-7f3f>\"; " + "type=\"text/xml\"; start-info=\"text/xml\"";
    MessageContextFactory mcf = MessageContextFactory.createFactory(new MTOMFeature(true));
    InputStream is = getClass().getClassLoader().getResourceAsStream("etc/bug17367334InputMsg.txt");
    Packet packet = (Packet) mcf.createContext(is, ctype);
    Message message = packet.getInternalMessage();
    assertTrue("StreamMessage not found, got : " + message.getClass(), StreamMessage.class.isAssignableFrom(message.getClass()));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    packet.setState(State.ClientRequest);
    // System.out.println("SWA packet.getContentType(): " + packet.getContentType().getContentType() );
    ContentType contentType = packet.writeTo(baos);
    // System.out.println("etc/bug17367334InputMsg.txt\r\n" + contentType.getContentType() + "\r\n" + new String(baos.toByteArray()));
    ByteArrayInputStream 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);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) ContentType(com.oracle.webservices.api.message.ContentType) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) AttachmentPart(jakarta.xml.soap.AttachmentPart) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage) MimeHeaders(jakarta.xml.soap.MimeHeaders) MessageContextFactory(com.oracle.webservices.api.message.MessageContextFactory) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 20 with MimeHeaders

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

the class Client method testUsingJaxwsMsg.

public void testUsingJaxwsMsg() 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(jaxwsMsg.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