Search in sources :

Example 6 with JavaCallInfo

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));
}
Also used : DataHandlerAttachment(com.sun.xml.ws.message.DataHandlerAttachment) HashMap(java.util.HashMap) DataHandlerAttachment(com.sun.xml.ws.message.DataHandlerAttachment) Attachment(com.sun.xml.ws.api.message.Attachment) DataHandler(jakarta.activation.DataHandler) Image(java.awt.Image) URL(java.net.URL) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort) Databinding(com.sun.xml.ws.api.databinding.Databinding) AttachmentSet(com.sun.xml.ws.api.message.AttachmentSet) Attachment(com.sun.xml.ws.api.message.Attachment) JavaCallInfo(com.oracle.webservices.api.databinding.JavaCallInfo) Packet(com.sun.xml.ws.api.message.Packet) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) Method(java.lang.reflect.Method) SOAPMessageContextImpl(com.sun.xml.ws.handler.SOAPMessageContextImpl) DatabindingConfig(com.sun.xml.ws.api.databinding.DatabindingConfig) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) HashMap(java.util.HashMap) Map(java.util.Map) MailcapCommandMap(jakarta.activation.MailcapCommandMap) CommandMap(jakarta.activation.CommandMap)

Example 7 with JavaCallInfo

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);
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) JavaCallInfo(com.oracle.webservices.api.databinding.JavaCallInfo) DispatchException(com.sun.xml.ws.wsdl.DispatchException) DispatchException(com.sun.xml.ws.wsdl.DispatchException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotNull(com.sun.istack.NotNull)

Example 8 with JavaCallInfo

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);
}
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 9 with JavaCallInfo

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;
}
Also used : JavaMethodImpl(com.sun.xml.ws.model.JavaMethodImpl) DispatchException(com.sun.xml.ws.wsdl.DispatchException) JavaCallInfo(com.oracle.webservices.api.databinding.JavaCallInfo) TieHandler(com.sun.xml.ws.server.sei.TieHandler)

Example 10 with JavaCallInfo

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();
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) JAXBMessage(com.sun.xml.ws.message.jaxb.JAXBMessage) Message(com.sun.xml.ws.api.message.Message) WebServiceException(jakarta.xml.ws.WebServiceException) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(jakarta.xml.bind.JAXBException) JavaCallInfo(com.oracle.webservices.api.databinding.JavaCallInfo) DeserializationException(com.sun.xml.ws.encoding.soap.DeserializationException)

Aggregations

JavaCallInfo (com.oracle.webservices.api.databinding.JavaCallInfo)10 Packet (com.sun.xml.ws.api.message.Packet)6 MessageContext (com.oracle.webservices.api.message.MessageContext)4 SOAPMessage (jakarta.xml.soap.SOAPMessage)4 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)4 Method (java.lang.reflect.Method)4 QName (javax.xml.namespace.QName)4 Databinding (com.oracle.webservices.api.databinding.Databinding)3 DatabindingFactory (com.oracle.webservices.api.databinding.DatabindingFactory)2 DatabindingModeFeature (com.oracle.webservices.api.databinding.DatabindingModeFeature)2 Databinding (com.sun.xml.ws.api.databinding.Databinding)2 DatabindingConfig (com.sun.xml.ws.api.databinding.DatabindingConfig)2 Attachment (com.sun.xml.ws.api.message.Attachment)2 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)2 SOAPMessageContextImpl (com.sun.xml.ws.handler.SOAPMessageContextImpl)2 DispatchException (com.sun.xml.ws.wsdl.DispatchException)2 CommandMap (jakarta.activation.CommandMap)2 DataHandler (jakarta.activation.DataHandler)2 MailcapCommandMap (jakarta.activation.MailcapCommandMap)2 Image (java.awt.Image)2