use of com.oracle.webservices.api.databinding.JavaCallInfo in project metro-jax-ws by eclipse-ee4j.
the class SwaMimeAttachmentTest method testCustomAttachmentContentId.
public void testCustomAttachmentContentId() throws Exception {
WSDLPort wsdlPort = getWSDLPort(getResource("WSW2JDLSwaTestService.wsdl"));
Class proxySEIClass = SwaTest1.class;
WebServiceFeature[] f = { databindingMode() };
DatabindingConfig cliConfig = new DatabindingConfig();
cliConfig.setContractClass(proxySEIClass);
cliConfig.setFeatures(f);
cliConfig.setWsdlPort(wsdlPort);
cliConfig.setWsdlPort(wsdlPort);
cliConfig.getMappingInfo().setServiceName(new QName("http://SwaTestService.org/wsdl", "WSIDLSwaTestService"));
Databinding cli = (Databinding) factory.createRuntime(cliConfig);
URL url1 = getResource("attach.text");
URL url2 = getResource("attach.html");
URL url3 = getResource("attach.xml");
URL url4 = getResource("attach.jpeg1");
URL url5 = getResource("attach.jpeg2");
DataHandler dh1 = new DataHandler(url1);
DataHandler dh2 = new DataHandler(url2);
DataHandler dh3 = new DataHandler(url3);
DataHandler dh4 = new DataHandler(url4);
// DataHandler dh5 = new DataHandler(url5);
jakarta.xml.ws.Holder<jakarta.activation.DataHandler> attach1 = new jakarta.xml.ws.Holder<jakarta.activation.DataHandler>();
attach1.value = dh1;
jakarta.xml.ws.Holder<jakarta.activation.DataHandler> attach2 = new jakarta.xml.ws.Holder<jakarta.activation.DataHandler>();
attach2.value = dh2;
jakarta.xml.ws.Holder<javax.xml.transform.Source> attach3 = new jakarta.xml.ws.Holder<javax.xml.transform.Source>();
attach3.value = new StreamSource(dh3.getInputStream());
jakarta.xml.ws.Holder<java.awt.Image> attach4 = new jakarta.xml.ws.Holder<java.awt.Image>();
jakarta.xml.ws.Holder<java.awt.Image> attach5 = new jakarta.xml.ws.Holder<java.awt.Image>();
attach4.value = javax.imageio.ImageIO.read(url4);
attach5.value = javax.imageio.ImageIO.read(url5);
VoidRequest request = new VoidRequest();
Object[] args = { request, attach1, attach2, attach3, attach4, attach5 };
Method method = findMethod(proxySEIClass, "echoAllAttachmentTypes");
JavaCallInfo cliCall = cli.createJavaCallInfo(method, args);
Packet cliSoapReq = (Packet) cli.serializeRequest(cliCall);
String customContentId = "<abcd@example.org>";
Map<String, DataHandler> attMap = new HashMap<String, DataHandler>();
attMap.put(customContentId, dh4);
cliSoapReq.invocationProperties.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, attMap);
SOAPMessageContextImpl smc = new SOAPMessageContextImpl(null, cliSoapReq, null);
Map<String, DataHandler> smcAtts1 = (Map<String, DataHandler>) smc.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
assertEquals(6, smcAtts1.size());
assertNotNull(smcAtts1.get(customContentId));
{
// ClientSOAPHandlerTube.callHandlersOnRequest
Map<String, DataHandler> atts = (Map<String, DataHandler>) smc.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
AttachmentSet attSet = cliSoapReq.getMessage().getAttachments();
for (String cid : atts.keySet()) {
if (attSet.get(cid) == null) {
// Otherwise we would be adding attachments twice
Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
attSet.add(att);
}
}
}
int attCount = 0;
for (com.sun.xml.ws.api.message.Attachment a : cliSoapReq.getMessage().getAttachments()) {
// assertTrue(a.getContentId().charAt(0)!='<');
attCount++;
}
assertEquals(6, attCount);
Object s1 = cliSoapReq.getAsSOAPMessage();
Object s2 = smc.getMessage();
assertTrue(s1 == s2);
int attCountSaaj = 0;
for (com.sun.xml.ws.api.message.Attachment a : cliSoapReq.getMessage().getAttachments()) {
assertTrue(a.getContentId().charAt(0) != '<');
attCountSaaj++;
}
assertEquals(6, attCountSaaj);
Map<String, DataHandler> smcAtts2 = (Map<String, DataHandler>) smc.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
assertEquals(6, smcAtts2.size());
// System.out.println(smcAtts2.size() + " " + smcAtts2);
assertNotNull(smcAtts2.get(customContentId));
}
use of com.oracle.webservices.api.databinding.JavaCallInfo in project metro-jax-ws by eclipse-ee4j.
the class SEIInvokerTube method processRequest.
/**
* This binds the parameters for SEI endpoints and invokes the endpoint method. The
* return value, and response Holder arguments are used to create a new {@link Message}
* that traverses through the Pipeline to transport.
*/
@NotNull
public NextAction processRequest(@NotNull Packet req) {
JavaCallInfo call = model.getDatabinding().deserializeRequest(req);
if (call.getException() == null) {
try {
if (req.getMessage().isOneWay(model.getPort()) && req.transportBackChannel != null) {
req.transportBackChannel.close();
}
Object ret = getInvoker(req).invoke(req, call.getMethod(), call.getParameters());
call.setReturnValue(ret);
} catch (Exception e) {
call.setException(e);
}
} else if (call.getException() instanceof DispatchException) {
DispatchException e = (DispatchException) call.getException();
return doReturnWith(req.createServerResponse(e.fault, model.getPort(), null, binding));
}
Packet res = (Packet) model.getDatabinding().serializeResponse(call);
res = req.relateServerResponse(res, req.endpoint.getPort(), model, req.endpoint.getBinding());
assert res != null;
return doReturnWith(res);
}
use of com.oracle.webservices.api.databinding.JavaCallInfo 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.databinding.JavaCallInfo in project metro-jax-ws by eclipse-ee4j.
the class DatabindingImpl method deserializeRequest.
public JavaCallInfo deserializeRequest(Packet req) {
com.sun.xml.ws.api.databinding.JavaCallInfo call = new com.sun.xml.ws.api.databinding.JavaCallInfo();
try {
JavaMethodImpl wsdlOp = resolveJavaMethod(req);
TieHandler tie = wsdlOpMap.get(wsdlOp);
call.setMethod(tie.getMethod());
Object[] args = tie.readRequest(req.getMessage());
call.setParameters(args);
} catch (DispatchException e) {
call.setException(e);
}
return call;
}
use of com.oracle.webservices.api.databinding.JavaCallInfo in project metro-jax-ws by eclipse-ee4j.
the class SyncMethodHandler method invoke.
/**
* Invokes synchronously, but with the given {@link RequestContext}
* and {@link ResponseContextReceiver}.
*
* @param rc
* This {@link RequestContext} is used for invoking this method.
* We take this as a separate parameter because of the async invocation
* handling, which requires a separate copy.
*/
Object invoke(Object proxy, Object[] args, RequestContext rc, ResponseContextReceiver receiver) throws Throwable {
JavaCallInfo call = owner.databinding.createJavaCallInfo(method, args);
Packet req = (Packet) owner.databinding.serializeRequest(call);
// process the message
Packet reply = owner.doProcess(req, rc, receiver);
Message msg = reply.getMessage();
if (msg == null) {
if (!isOneway || !isVoid) {
throw new WebServiceException(DispatchMessages.INVALID_RESPONSE());
}
return null;
}
try {
call = owner.databinding.deserializeResponse(reply, call);
if (call.getException() != null) {
throw call.getException();
} else {
return call.getReturnValue();
}
} catch (JAXBException e) {
throw new DeserializationException(DispatchMessages.INVALID_RESPONSE_DESERIALIZATION(), e);
} catch (XMLStreamException e) {
throw new DeserializationException(DispatchMessages.INVALID_RESPONSE_DESERIALIZATION(), e);
} finally {
if (reply.transportBackChannel != null)
reply.transportBackChannel.close();
}
}
Aggregations