Search in sources :

Example 1 with ContentType

use of com.oracle.webservices.api.message.ContentType 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 2 with ContentType

use of com.oracle.webservices.api.message.ContentType in project metro-jax-ws by eclipse-ee4j.

the class SAAJMessageTest method testMtomMessageReload.

public void testMtomMessageReload() throws Exception {
    String testMtomMessageReload_01 = "multipart/related;type=\"application/xop+xml\";boundary=\"----=_Part_0_1145105632.1353005695468\";start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
    String testMtomMessageReload_02 = "multipart/related;type=\"application/xop+xml\";boundary=\"----=_Part_0_1145105632.1353005695468\";start=\"<6e1e30fe-9874-43ff-a9d1-c02af3969f04>\";start-info=\"text/xml\"";
    {
        MessageContext m1 = mcf.createContext(getResource("testMtomMessageReload_01.msg"), testMtomMessageReload_01);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ContentType disiContentType = m1.writeTo(baos);
        byte[] bytes = baos.toByteArray();
        String strMsg = new String(bytes);
        assertFalse(strMsg.startsWith("--null"));
    }
    {
        MessageContext m2 = mcf.createContext(getResource("testMtomMessageReload_02.msg"), testMtomMessageReload_02);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ContentType disiContentType = m2.writeTo(baos);
        byte[] bytes = baos.toByteArray();
        String strMsg = new String(bytes);
        assertFalse(strMsg.startsWith("--null"));
    }
}
Also used : ContentType(com.oracle.webservices.api.message.ContentType) MessageContext(com.oracle.webservices.api.message.MessageContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with ContentType

use of com.oracle.webservices.api.message.ContentType 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)

Aggregations

ContentType (com.oracle.webservices.api.message.ContentType)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 MessageContext (com.oracle.webservices.api.message.MessageContext)2 SOAPMessage (jakarta.xml.soap.SOAPMessage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 JavaCallInfo (com.oracle.webservices.api.databinding.JavaCallInfo)1 MessageContextFactory (com.oracle.webservices.api.message.MessageContextFactory)1 Message (com.sun.xml.ws.api.message.Message)1 Packet (com.sun.xml.ws.api.message.Packet)1 AttachmentPart (jakarta.xml.soap.AttachmentPart)1 MessageFactory (jakarta.xml.soap.MessageFactory)1 MimeHeaders (jakarta.xml.soap.MimeHeaders)1 MTOMFeature (jakarta.xml.ws.soap.MTOMFeature)1 InputStream (java.io.InputStream)1