Search in sources :

Example 6 with MessageContext

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

the class WrapperNSTest method testWrapperNS.

public void testWrapperNS() throws Exception {
    Class<?> sei = MyHelloRPC.class;
    DatabindingFactory fac = DatabindingFactory.newInstance();
    Databinding.Builder b = fac.createBuilder(sei, null);
    DatabindingModeFeature dbf = new DatabindingModeFeature("eclipselink.jaxb");
    WebServiceFeature[] f = { dbf };
    b.feature(f);
    b.serviceName(new QName("http://echo.org/", "helloService"));
    b.portName(new QName("http://echo.org/", "helloPort"));
    Databinding db = b.build();
    {
        Method method = findMethod(sei, "echoString");
        Object[] args = { "test" };
        JavaCallInfo call = db.createJavaCallInfo(method, args);
        MessageContext mc = db.serializeRequest(call);
        SOAPMessage msg = mc.getSOAPMessage();
        // System.out.println("------------------ eclipselink");
        // msg.writeTo(System.out);
        // System.out.println();
        Node n = msg.getSOAPBody().getChildNodes().item(0);
        // System.out.println("num of attributes is: "+
        // n.getAttributes().getLength());
        assertTrue(n.getAttributes().getLength() == 1);
    }
}
Also used : DatabindingFactory(com.oracle.webservices.api.databinding.DatabindingFactory) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) DatabindingModeFeature(com.oracle.webservices.api.databinding.DatabindingModeFeature) Method(java.lang.reflect.Method) SOAPMessage(jakarta.xml.soap.SOAPMessage) Databinding(com.oracle.webservices.api.databinding.Databinding) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) JavaCallInfo(com.oracle.webservices.api.databinding.JavaCallInfo) MessageContext(com.oracle.webservices.api.message.MessageContext)

Example 7 with MessageContext

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

the class WrapperNSTest method testWrapperNS_JAXBRI.

public void testWrapperNS_JAXBRI() throws Exception {
    Class<?> sei = MyHelloRPC.class;
    DatabindingFactory fac = DatabindingFactory.newInstance();
    Databinding.Builder b = fac.createBuilder(sei, null);
    DatabindingModeFeature dbf = new DatabindingModeFeature("glassfish.jaxb");
    WebServiceFeature[] f = { dbf };
    b.feature(f);
    b.serviceName(new QName("http://echo.org/", "helloService"));
    b.portName(new QName("http://echo.org/", "helloPort"));
    Databinding db = b.build();
    {
        Method method = findMethod(sei, "echoString");
        Object[] args = { "test" };
        JavaCallInfo call = db.createJavaCallInfo(method, args);
        MessageContext mc = db.serializeRequest(call);
        SOAPMessage msg = mc.getSOAPMessage();
        // System.out.println("------------------ glassfish");
        // msg.writeTo(System.out);
        // System.out.println();
        Node n = msg.getSOAPBody().getChildNodes().item(0);
        // System.out.println("num of attributes is: "+
        // n.getAttributes().getLength());
        assertTrue(n.getAttributes().getLength() == 1);
    }
}
Also used : DatabindingFactory(com.oracle.webservices.api.databinding.DatabindingFactory) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) DatabindingModeFeature(com.oracle.webservices.api.databinding.DatabindingModeFeature) Method(java.lang.reflect.Method) SOAPMessage(jakarta.xml.soap.SOAPMessage) Databinding(com.oracle.webservices.api.databinding.Databinding) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) JavaCallInfo(com.oracle.webservices.api.databinding.JavaCallInfo) MessageContext(com.oracle.webservices.api.message.MessageContext)

Example 8 with MessageContext

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

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

the class SAAJMessageWrapperTest method XtestMTOM_oraSaaj.

public void XtestMTOM_oraSaaj() throws Exception {
    // client creates request
    MessageContext clientRequest = databinding.serializeRequest(clientCall);
    // client writes request to OutputStream
    // TODO databinding bug - fixed
    // clientRequest.writeTo(clientOut);
    ByteArrayOutputStream clientOut = new ByteArrayOutputStream();
    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());
    // setup JRF env ...
    // ContainerResolver.setInstance(new JRFContainerResolver());
    // server coverts request to saaj SOAPMessage
    SOAPMessage saajReq1 = serverRequest.getSOAPMessage();
    System.out.println("==== serverRequest.getSOAPMessage() 1 " + saajReq1);
    // !! NPE if getSOAPMessage() more than one time
    // SOAPMessage saajReq2 = serverRequest.getSOAPMessage();
    // System.out.println("==== serverRequest.getSOAPMessage() 2 " + saajReq2);
    // !! NPE if the following line of serverRequest.setMessage(...) is removed
    ((Packet) serverRequest).setMessage(new com.sun.xml.ws.message.saaj.SAAJMessage(saajReq1));
    SOAPMessage saajReq2 = serverRequest.getSOAPMessage();
    System.out.println("==== serverRequest.getSOAPMessage() 2 " + saajReq2);
    // !! 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.getSOAPMessage();
    System.out.println("==== serverResponse.getSOAPMessage() 1 " + saajRes1);
    // !! server coverts response to saaj SOAPMessage again but get another new saaj SOAPMessage
    SOAPMessage saajRes2 = serverResponse.getSOAPMessage();
    System.out.println("==== serverResponse.getSOAPMessage() 2 " + 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 saajRes3 = serverResponse.getSOAPMessage();
    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();
    // 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 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 : Packet(com.sun.xml.ws.api.message.Packet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage) Databinding(com.oracle.webservices.api.databinding.Databinding) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageContext(com.oracle.webservices.api.message.MessageContext) JavaCallInfo(com.oracle.webservices.api.databinding.JavaCallInfo)

Example 10 with MessageContext

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

the class StreamMessageTest method testEmptySoapHeader.

public void testEmptySoapHeader() throws Exception {
    String soap = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>" + "<soap:Header xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'></soap:Header>" + "<soapenv:Body>" + "  <tes:fooOwsmMsgProtection xmlns:tes='http://testOwsm'>" + "   <!--Optional:-->" + "    <arg0>string</arg0>" + "  </tes:fooOwsmMsgProtection>" + "</soapenv:Body>" + "</soapenv:Envelope>";
    MessageContextFactory mcf = MessageContextFactory.createFactory();
    MessageContext mc = mcf.createContext(new ByteArrayInputStream(soap.getBytes()), "text/xml");
    String string1 = mc.toString();
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    mc.writeTo(bo);
    String string2 = new String(bo.toByteArray());
    assertTrue(string1.indexOf("Header") != -1);
    assertTrue(string2.indexOf("Header") != -1);
}
Also used : MessageContextFactory(com.oracle.webservices.api.message.MessageContextFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageContext(com.oracle.webservices.api.message.MessageContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

MessageContext (com.oracle.webservices.api.message.MessageContext)11 SOAPMessage (jakarta.xml.soap.SOAPMessage)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Packet (com.sun.xml.ws.api.message.Packet)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Databinding (com.oracle.webservices.api.databinding.Databinding)4 JavaCallInfo (com.oracle.webservices.api.databinding.JavaCallInfo)4 MessageContextFactory (com.oracle.webservices.api.message.MessageContextFactory)4 Message (com.sun.xml.ws.api.message.Message)4 DatabindingFactory (com.oracle.webservices.api.databinding.DatabindingFactory)3 AttachmentPart (jakarta.xml.soap.AttachmentPart)3 QName (javax.xml.namespace.QName)3 DatabindingModeFeature (com.oracle.webservices.api.databinding.DatabindingModeFeature)2 ContentType (com.oracle.webservices.api.message.ContentType)2 SOAPVersion (com.sun.xml.ws.api.SOAPVersion)2 Attachment (com.sun.xml.ws.api.message.Attachment)2 StreamingDataHandler (com.sun.xml.ws.developer.StreamingDataHandler)2 MIMEPartStreamingDataHandler (com.sun.xml.ws.encoding.MIMEPartStreamingDataHandler)2 MessageFactory (jakarta.xml.soap.MessageFactory)2 MimeHeaders (jakarta.xml.soap.MimeHeaders)2