Search in sources :

Example 16 with SOAPMessage

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

the class SAAJMessageWrapperTest method testMTOM_riSaaj.

public void testMTOM_riSaaj() throws Exception {
    // client creates request
    MessageContext clientRequest = databinding.serializeRequest(clientCall);
    // client writes request to OutputStream
    ByteArrayOutputStream clientOut = new ByteArrayOutputStream();
    ContentType cliCt = clientRequest.writeTo(clientOut);
    // com.sun.xml.ws.api.pipe.ContentType cliCt = ((com.sun.xml.ws.api.databinding.Databinding)databinding).
    // encode((Packet)clientRequest, clientOut);
    // System.out.println("==== Client Request " + cliCt.getContentType() + " " + cliCt.getSOAPActionHeader() );
    // System.out.println(new String(clientOut.toByteArray()) + "\r\n\r\n");
    // client sends request to server
    ByteArrayInputStream serverIn = new ByteArrayInputStream(clientOut.toByteArray());
    // server decodes request to Packet
    MessageContext serverRequest = mcf.createContext(serverIn, cliCt.getContentType());
    // deprecated way to create/decode MC/Packet from inputStream
    // com.sun.xml.ws.api.message.Packet serverRequest = new com.sun.xml.ws.api.message.Packet();
    // ((com.sun.xml.ws.api.databinding.Databinding)databinding).decode(serverIn, cliCt.getContentType(), serverRequest);
    // setup JRF env ...
    // ContainerResolver.setInstance(new JRFContainerResolver());
    // server coverts request to saaj SOAPMessage
    SOAPMessage saajReq1 = serverRequest.getAsSOAPMessage();
    assertEquals("wrong attachment count", 1, saajReq1.countAttachments());
    // System.out.println("==== serverRequest.getSOAPMessage() 1 " + saajReq1);
    // Write the SOAPMessage multiple times result in different message boundary -
    // {
    // saajReq1 = serverRequest.getSOAPMessage();
    // System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + saajReq1);
    // ByteArrayOutputStream saajReq1Out = new ByteArrayOutputStream();
    // saajReq1.writeTo(saajReq1Out);
    // System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + new String(saajReq1Out.toByteArray()));
    // }
    // {
    // saajReq1 = serverRequest.getSOAPMessage();
    // System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + saajReq1);
    // ByteArrayOutputStream saajReq1Out = new ByteArrayOutputStream();
    // saajReq1.writeTo(saajReq1Out);
    // System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + new String(saajReq1Out.toByteArray()));
    // }
    // {
    // saajReq1 = serverRequest.getSOAPMessage();
    // System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + saajReq1);
    // ByteArrayOutputStream saajReq1Out = new ByteArrayOutputStream();
    // saajReq1.writeTo(saajReq1Out);
    // System.out.println("\r\n==== serverRequest.getSOAPMessage() 1 " + new String(saajReq1Out.toByteArray()));
    // }
    // !! NPE if the following line of serverRequest.setMessage(...) is removed
    // ((Packet)serverRequest).setMessage(new com.sun.xml.ws.message.saaj.SAAJMessage(saajReq1));
    SOAPMessage saajReq2 = ((Packet) serverRequest).getMessage().readAsSOAPMessage();
    SOAPMessage saajReq3 = serverRequest.getAsSOAPMessage();
    SOAPMessage saajReq4 = ((Packet) serverRequest).getMessage().readAsSOAPMessage();
    // System.out.println("==== serverRequest.getSOAPMessage() 2 " + saajReq2);
    assertTrue(saajReq1 == saajReq2);
    assertTrue(saajReq3 == saajReq2);
    assertTrue(saajReq4 == saajReq3);
    // !! Do we need orassaj-XMLStreamReaderEx if the databinding can descerialize orasaaj SOAPMessagae as inline?
    JavaCallInfo serverCall = databinding.deserializeRequest(serverRequest);
    serverCall.setReturnValue(serverCall.getParameters()[0]);
    // server creates response
    MessageContext serverResponse = databinding.serializeResponse(serverCall);
    // server coverts response to saaj SOAPMessage
    SOAPMessage saajRes1 = serverResponse.getAsSOAPMessage();
    // System.out.println("==== serverResponse.getSOAPMessage() 1 " + saajRes1);
    // !! server coverts response to saaj SOAPMessage again but get another new saaj SOAPMessage
    SOAPMessage saajRes2 = ((Packet) serverResponse).getMessage().readAsSOAPMessage();
    SOAPMessage saajRes3 = serverResponse.getAsSOAPMessage();
    SOAPMessage saajRes4 = ((Packet) serverResponse).getMessage().readAsSOAPMessage();
    // System.out.println("==== serverResponse.getSOAPMessage() 2 " + saajRes2);
    assertTrue(saajRes1 == saajRes2);
    // !! Following line keeps the same saaj message but removes mtom effect on response
    // ((Packet)serverResponse).setMessage(new com.sun.xml.ws.message.saaj.SAAJMessage(saajRes1));
    SOAPMessage saajRes5 = serverResponse.getAsSOAPMessage();
    assertTrue(saajRes3 == saajRes2);
    assertTrue(saajRes3 == saajRes4);
    assertTrue(saajRes4 == saajRes5);
    // System.out.println("==== serverResponse.getSOAPMessage() 3 " + saajRes3);
    // {
    // ByteArrayOutputStream serverOut = new ByteArrayOutputStream();
    // //TODO serverResponse.writeTo(serverOut);
    // com.sun.xml.ws.api.pipe.ContentType resCt = ((com.sun.xml.ws.api.databinding.Databinding)databinding).
    // encode((com.sun.xml.ws.api.message.Packet)serverResponse, serverOut);
    // System.out.println("==== Server Response 1 " + resCt.getContentType() + " " + resCt.getSOAPActionHeader() );
    // System.out.println(new String(serverOut.toByteArray()) + "\r\n\r\n");
    // }
    // {
    // ByteArrayOutputStream serverOut = new ByteArrayOutputStream();
    // //TODO serverResponse.writeTo(serverOut);
    // com.sun.xml.ws.api.pipe.ContentType resCt = ((com.sun.xml.ws.api.databinding.Databinding)databinding).
    // encode((com.sun.xml.ws.api.message.Packet)serverResponse, serverOut);
    // System.out.println("==== Server Response 2 " + resCt.getContentType() + " " + resCt.getSOAPActionHeader() );
    // System.out.println(new String(serverOut.toByteArray()) + "\r\n\r\n");
    // }
    ByteArrayOutputStream serverOut = new ByteArrayOutputStream();
    ContentType resCt = serverResponse.writeTo(serverOut);
    // com.sun.xml.ws.api.pipe.ContentType resCt = ((com.sun.xml.ws.api.databinding.Databinding)databinding).
    // encode((com.sun.xml.ws.api.message.Packet)serverResponse, serverOut);
    // System.out.println("==== Server Response x " + resCt.getContentType() + " " + resCt.getSOAPActionHeader() );
    // System.out.println(new String(serverOut.toByteArray()) + "\r\n\r\n");
    // server sends response to client
    ByteArrayInputStream clientIn = new ByteArrayInputStream(serverOut.toByteArray());
    MessageContext clientResponse = mcf.createContext(clientIn, resCt.getContentType());
    // com.sun.xml.ws.api.message.Packet clientResponse = new com.sun.xml.ws.api.message.Packet();
    // ((com.sun.xml.ws.api.databinding.Databinding)databinding).decode(clientIn, resCt.getContentType(), clientResponse);
    clientCall = databinding.deserializeResponse(clientResponse, clientCall);
    String res = new String((byte[]) clientCall.getReturnValue());
    // System.out.println("response " + res);
    assertEquals(res, reqStr);
}
Also used : ContentType(com.oracle.webservices.api.message.ContentType) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageContext(com.oracle.webservices.api.message.MessageContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JavaCallInfo(com.oracle.webservices.api.databinding.JavaCallInfo) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 17 with SOAPMessage

use of jakarta.xml.soap.SOAPMessage 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 18 with SOAPMessage

use of jakarta.xml.soap.SOAPMessage 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 19 with SOAPMessage

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

the class jaxws413Test method test1.

public void test1() throws SOAPException, IOException {
    SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault();
    fault.setFaultCode(new QName("http://foo/bar", "mycode", "myprefix"));
    fault.setFaultString("Some exception");
    Detail detail = fault.addDetail();
    detail.addDetailEntry(new QName("http://foo/bar", "soap11detail"));
    Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_11, fault);
    SOAPMessage sm = faultMsg.readAsSOAPMessage();
    Detail det = sm.getSOAPBody().getFault().getDetail();
    Iterator iter = det.getDetailEntries();
    assertTrue(iter.hasNext());
    Element item = (Element) iter.next();
    assertEquals(item.getNamespaceURI(), "http://foo/bar");
    assertEquals(item.getLocalName(), "soap11detail");
}
Also used : Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPMessage(jakarta.xml.soap.SOAPMessage) Detail(jakarta.xml.soap.Detail)

Example 20 with SOAPMessage

use of jakarta.xml.soap.SOAPMessage 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)

Aggregations

SOAPMessage (jakarta.xml.soap.SOAPMessage)181 MessageFactory (jakarta.xml.soap.MessageFactory)66 ByteArrayInputStream (java.io.ByteArrayInputStream)51 SOAPBody (jakarta.xml.soap.SOAPBody)37 SOAPException (jakarta.xml.soap.SOAPException)36 QName (javax.xml.namespace.QName)31 MimeHeaders (jakarta.xml.soap.MimeHeaders)27 Source (javax.xml.transform.Source)25 StreamSource (javax.xml.transform.stream.StreamSource)25 WebServiceException (jakarta.xml.ws.WebServiceException)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)19 Element (org.w3c.dom.Element)18 Node (org.w3c.dom.Node)18 Packet (com.sun.xml.ws.api.message.Packet)17 Message (com.sun.xml.ws.api.message.Message)16 Iterator (java.util.Iterator)14 SOAPElement (jakarta.xml.soap.SOAPElement)12 AttachmentPart (jakarta.xml.soap.AttachmentPart)11 Dispatch (jakarta.xml.ws.Dispatch)10