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);
}
}
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);
}
}
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"));
}
}
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);
}
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);
}
Aggregations