Package org.apache.tuscany.sca.invocation

Examples of org.apache.tuscany.sca.invocation.Message


                else {
                    Assert.fail();
                }
                //System.out.println(" *TestImplPolicyHandler* " + op.getName() + " ** " + applicablePolicySet);
            } else if ( contextObj instanceof Message ) {
                Message msg = (Message)contextObj;
                System.out.println(" *TestImplPolicyHandler* " + msg.getOperation().getName() + " ** " + applicablePolicySet);
            }
        }
    }
View Full Code Here


        for ( Object contextObj : context) {
            if ( contextObj instanceof Operation ) {
                Operation op = (Operation)contextObj;
                System.out.println(" *TestSvcPolicyHandler* " + op.getName() + " ** " + applicablePolicySet);
            } else if ( contextObj instanceof Message ) {
                Message msg = (Message)contextObj;
                System.out.println(" *TestSvcPolicyHandler* " + msg.getOperation().getName() + " ** " + applicablePolicySet);
            }
        }
    }
View Full Code Here

        if (msg.getOperation().getName().equals("upper")){
          // Retrieve the async callback information
          AsyncResponseInvoker respInvoker = (AsyncResponseInvoker)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER");
          if( respInvoker == null ) throw new ServiceRuntimeException("Async Implementation invoked with no response invoker");
         
            Message responseMsg = processRequest(msg);
           
            // in this sample programming model we make the async
            // response from the implementation provider. The
            // component implementation itself doesn't get a chance to
            // do async responses.
       
            // At this point we could serialize the AsyncResponseInvoker and pick it up again
            // later to send the async response
           
            try {
                FileOutputStream fos = new FileOutputStream("ari.dat");
                ObjectOutputStream oos = new ObjectOutputStream(fos);
                oos.writeObject(respInvoker);
                oos.close();
                respInvoker.invokeAsyncResponse(responseMsg);
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        } else if (msg.getOperation().getName().equals("upper2")){
            Message responseMsg = processRequest(msg);
           
            // read the async response invoker back in and call it
            FileInputStream fis = null;
            ObjectInputStream ois = null;
            try {
                fis = new FileInputStream("ari.dat");
                ois = new ObjectInputStream(fis);
                AsyncResponseInvoker respInvoker = (AsyncResponseInvoker) ois.readObject();
                ois.close();
                respInvoker.invokeAsyncResponse(responseMsg);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else {
            // Retrieve the async callback information
            AsyncResponseInvoker respInvoker = (AsyncResponseInvoker)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER");
            if( respInvoker == null ) throw new ServiceRuntimeException("Async Implementation invoked with no response invoker");
           
            Message responseMsg = processRequest(msg);
           
            if (responseMsg.getBody() != null){
                respInvoker.invokeAsyncResponse(responseMsg);
            }
        }
       
    } // end method invokeAsyncRequest
View Full Code Here

    }

    public void invokeAsync(WebsocketBindingMessage request, TuscanyWebsocket channel) {
        String jsonParams = request.getPayload();
        Object[] args = JSONUtil.decodePayloadForOperation(jsonParams, operation);
        Message msg = new MessageImpl();
        msg.getHeaders().put(Constants.MESSAGE_ID, channel.getId());
        msg.setBody(args);
        EndpointReference re = new RuntimeEndpointReferenceImpl();
        RuntimeEndpointImpl callbackEndpoint = new RuntimeEndpointImpl();
        callbackEndpoint.setURI(request.getOperation());
        re.setCallbackEndpoint(callbackEndpoint);
        msg.setFrom(re);
        endpoint.invoke(operation, msg);
    }
View Full Code Here

   
    public OMElement invoke(OMElement requestOM, MessageContext inMC, MessageContext outMC) throws InvocationTargetException, AxisFault {
        String callbackAddress = null;

        // create a message object and set the args as its body
        Message msg = messageFactory.createMessage();
        msg.setOperation(operation);
        WSAxis2BindingContext bindingContext = new WSAxis2BindingContext();
        bindingContext.setAxisInMessageContext(inMC);
        bindingContext.setAxisOutMessageContext(outMC); //TUSCANY-3881
        msg.setBindingContext(bindingContext);

       
        if (wsBinding.isRpcLiteral()){              
            // remove the wrapping element containing
            // the operation name
            Iterator iter = requestOM.getChildElements();
            List<OMNode> list = new ArrayList<OMNode>();
            while(iter.hasNext()){
                OMNode node = (OMNode)iter.next();
                list.add(node);
            }
           
            Object[] args = list.toArray();
            msg.setBody(args);
           
        } else if (wsBinding.isRpcEncoded()){
            throw new ServiceRuntimeException("rpc/encoded WSDL style not supported for endpoint " + endpoint);
        } else if (wsBinding.isDocEncoded()){
            throw new ServiceRuntimeException("doc/encoded WSDL style not supported for endpoint " + endpoint);
        //} else if (wsBinding.isDocLiteralUnwrapped()){
           // throw new ServiceRuntimeException("doc/literal/unwrapped WSDL style not supported for endpoint " + endpoint);
        } else if (wsBinding.isDocLiteralWrapped() ||
                   wsBinding.isDocLiteralUnwrapped()){
            Object[] args = new Object[] {requestOM};
            msg.setBody(args);
        } else {
            throw new ServiceRuntimeException("Unrecognized WSDL style for endpoint " + endpoint);
        }       

        SOAPHeader header = inMC.getEnvelope().getHeader();
        if (header != null) {
          // Retrieve callback-related headers
          callbackAddress = handleCallbackAddress( header, msg );
            handleMessageIDHeader( header, msg );
            handleRelatesToHeader( header, msg );
        } // end if

        // Create a from EPR to hold the details of the callback endpoint, if any
        createCallbackEPR( callbackAddress, inMC, msg );
       
        // Set up any async response EPR
        setupAsyncResponse( msg, callbackAddress );

        Message response = endpoint.invoke(msg);
       
        if(response.isFault()) {
            throw new InvocationTargetException((Throwable) response.getBody());
        }
       
        // The envelope has already been set up in Axis2ServiceBindingResponseInvoker
        // so no need to return anything here
        return null;        
View Full Code Here

        Operation jsonOperation = findOperation(method);
        Object result = null;


        // Invoke the get operation on the service implementation
        Message requestMessage = messageFactory.createMessage();
        requestMessage.setOperation(jsonOperation);

        requestMessage.getHeaders().put("RequestMessage", request);

        if (jsonOperation.getWrapper().getDataBinding().equals(JSONDataBinding.NAME)) {
          requestMessage.setBody(new Object[]{jsonReq.toString()});
        } else {
          requestMessage.setBody(args);
        }

        //result = wire.invoke(jsonOperation, args);
        Message responseMessage = null;
        try {
            responseMessage = endpoint.getInvocationChain(jsonOperation).getHeadInvoker().invoke(requestMessage);
        } catch (RuntimeException re) {
            if (re.getCause() instanceof javax.security.auth.login.LoginException) {
                throw re;
            } else {
                //some other exception
                JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, re);
                return errorResult.toString().getBytes("UTF-8");
            }
        }

        if (!responseMessage.isFault()) {
            //successful execution of the invocation
            if (jsonOperation.getWrapper().getDataBinding().equals(JSONDataBinding.NAME)) {
                result = responseMessage.getBody();
              return result.toString().getBytes("UTF-8");
            } else {
                if (jsonOperation.getOutputType().getLogical().size() == 0) {
                    // void operation (json-rpc notification)
                    try {
                        JSONObject jsonResponse = new JSONObject();
                        jsonResponse.put("result", "");
                        //get response to send to client
                        return jsonResponse.toString().getBytes("UTF-8");
                    } catch (Exception e) {
                        throw new ServiceRuntimeException("Unable to create JSON response", e);
                    }

                } else {
                    // regular operation returning some value
                    try {
                        result = responseMessage.getBody();
                        JSONObject jsonResponse = new JSONObject();
                        //JSONObject put will remove the entry if it's value is null
                        //and per javadoc, we should pass JSONObject.NULL
                        if(result == null) {
                            jsonResponse.put("result", JSONObject.NULL);
                        } else {
                            jsonResponse.put("result", result);
                        }
                        jsonResponse.putOpt("id", id);
                        //get response to send to client
                        return jsonResponse.toString().getBytes("UTF-8");
                    } catch (Exception e) {
                        throw new ServiceRuntimeException("Unable to create JSON response", e);
                    }
                }
            }
        } else {
            //exception thrown while executing the invocation
            Throwable exception = (Throwable)responseMessage.getBody();
            JSONRPCResult errorResult = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, exception );
            return errorResult.toString().getBytes("UTF-8");
        }

   }
View Full Code Here

        WorkScheduler scheduler = utilities.getUtility(WorkScheduler.class);
        theExecutor = scheduler.getExecutorService();
    }

    public Message invokeBinding(Message msg) {
        Message context = ThreadMessageContext.setMessageContext(msg);
        try {
            return invocable.getBindingInvocationChain().getHeadInvoker().invoke(msg);
        } finally {
            ThreadMessageContext.setMessageContext(context);
        }
View Full Code Here

    /**
     * Async Invoke of the Binding Chain
     * @param msg - the message to use in the invocation
     */
    public void invokeBindingAsync(Message msg) {
        Message context = ThreadMessageContext.setMessageContext(msg);
        try {
            ((InvokerAsyncRequest)invocable.getBindingInvocationChain().getHeadInvoker()).invokeAsyncRequest(msg);
        } catch (Throwable t ) {
          // TODO - consider what best to do with exception
        } finally {
View Full Code Here

    public Message invoke(Message msg) {
        return invoke(msg.getOperation(), msg);
    }

    public Object invoke(Operation operation, Object[] args) throws InvocationTargetException {
        Message msg = messageFactory.createMessage();
        msg.setBody(args);
        Message resp = invoke(operation, msg);
        Object body = resp.getBody();
        if (resp.isFault()) {
            throw new InvocationTargetException((Throwable)body);
        }
        return body;
    }
View Full Code Here

        Invoker headInvoker = chain.getHeadInvoker();
        Operation operation = chain.getTargetOperation();
        msg.setOperation(operation);

        Message msgContext = ThreadMessageContext.setMessageContext(msg);
        try {
            return headInvoker.invoke(msg);
        } finally {
            ThreadMessageContext.setMessageContext(msgContext);
        }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.invocation.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.