Package org.apache.tuscany.sca.invocation

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


    }   
   
    @Override
    public void callAsync(String op, Element e) {
        // Asynchronously invoke the named operation on the endpoint reference
        Message message = mf.createMessage();
        message.setBody(new Object[]{e});
       
        // Generate MESSAGE_ID here.
        // String messageID = "myuniqueid";
        String messageID = UUID.randomUUID().toString();
        message.getHeaders().put(Constants.MESSAGE_ID, messageID);
       
        // save the message id ready for when we process the response       
        asyncMessageMap.put(messageID, op);
       
        // We could add implementation specific headers here if required
View Full Code Here


        if (getLocationInvoker == null) {
            throw new IllegalStateException("No getLocationURL operation found on target component");
        }

        // Get the location URL
        Message message = messageFactory.createMessage();
        message = getLocationInvoker.invoke(message);
        URL locationURL = message.getBody();
       
        // If resource is a file, register the parent dir
        try {
            if( locationURL.getProtocol().equals("file")) {
                File fileLocation = new File(locationURL.toURI());
View Full Code Here

                }
            }
        }

        // create a message object and set the args as its body
        Message msg = messageFactory.createMessage();
        msg.setBody(args);
        msg.setOperation(op);
       
        //fill message with QoS context info
        fillQoSContext(msg, inMC);
       
        // if reference parameters are needed, create a new "From" EPR to hold them
        EndpointReference from = null;
        ReferenceParameters parameters = null;
        if (callbackAddress != null ||
            callbackID != null ||
            conversationID != null) {
            from = new EndpointReferenceImpl(null);
            parameters = from.getReferenceParameters();
            msg.setFrom(from);
        }

        // set the reference parameters into the "From" EPR
        if (callbackAddress != null) {
            parameters.setCallbackReference(new EndpointReferenceImpl(callbackAddress));
View Full Code Here

            messageParameters.toArray(body);

            msg.setBody(body);
            msg.setOperation(operation);

            Message responseMessage = getNext().invoke(msg);

            //set Cache-Control to no-cache to avoid intermediary
            //proxy/reverse-proxy caches and always hit the server
            //that would identify if the value was current or not
            bindingContext.getHttpResponse().setHeader("Cache-Control", "no-cache");
            bindingContext.getHttpResponse().setHeader("Expires", new Date(0).toGMTString());


            String eTag = HTTPUtils.calculateHashETag(responseMessage.getBody().toString().getBytes("UTF-8"));

            // Test request for predicates.
            String predicate = bindingContext.getHttpRequest().getHeader( "If-Match" );
            if (( predicate != null ) && ( !predicate.equals(eTag) )) {
                // No match, should short circuit
View Full Code Here

        this.target = endpoint;
    }

    protected Object invoke(InvocationChain chain, Object[] args, RuntimeWire wire) throws Throwable {

        Message msg = messageFactory.createMessage();
        msg.setFrom(wire.getSource());
        if (target != null) {
            msg.setTo(target);
        } else {
            msg.setTo(wire.getTarget());
        }
        Invoker headInvoker = chain.getHeadInvoker();
        Operation operation = chain.getTargetOperation();
        msg.setOperation(operation);
        msg.setBody(args);

        Message msgContext = ThreadMessageContext.getMessageContext();
        Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID();

        conversationPreinvoke(msg, wire);
        handleCallback(msg, wire, currentConversationID);
        ThreadMessageContext.setMessageContext(msg);
        try {
            // dispatch the wire down the chain and get the response
            Message resp = headInvoker.invoke(msg);
            Object body = resp.getBody();
            if (resp.isFault()) {
                throw (Throwable)body;
            }
            return body;
        } finally {
            conversationPostInvoke(msg, wire);
View Full Code Here

        }
        return null;
    }

    public Object invoke(Operation operation, Object[] args) throws InvocationTargetException {
        Message msg = messageFactory.createMessage();
        msg.setBody(args);
        return invoker.invoke(operation, msg);
    }
View Full Code Here

        return ThreadMessageContext.getMessageContext().getTo().getContract().getName();
    }

    @SuppressWarnings("unchecked")
    public <B> CallableReference<B> getServiceReference() {
        Message msgContext = ThreadMessageContext.getMessageContext();
        // FIXME: [rfeng] Is this the service reference matching the caller side?
        EndpointReference to = msgContext.getTo();
        RuntimeComponentService service = (RuntimeComponentService) to.getContract();
        RuntimeComponent component = (RuntimeComponent) to.getComponent();
       
        CallableReference<B> callableReference = component.getComponentContext().getCallableReference(null, component, service);
        ReferenceParameters parameters = msgContext.getFrom().getReferenceParameters();
        ((CallableReferenceImpl<B>) callableReference).attachCallbackID(parameters.getCallbackID());
        if (callableReference.getConversation() != null) {
            ((CallableReferenceImpl<B>) callableReference).attachConversationID(parameters.getConversationID());
        }
        return callableReference;
View Full Code Here

        return cb.getService();
    }

    @SuppressWarnings("unchecked")
    public <CB> CallableReference<CB> getCallbackReference() {
        Message msgContext = ThreadMessageContext.getMessageContext();
        EndpointReference to = msgContext.getTo();
        RuntimeComponentService service = (RuntimeComponentService) to.getContract();
        RuntimeComponentReference callbackReference = (RuntimeComponentReference)service.getCallbackReference();
        if (callbackReference == null) {
            return null;
        }
        JavaInterface javaInterface = (JavaInterface) callbackReference.getInterfaceContract().getInterface();
        Class<CB> javaClass = (Class<CB>)javaInterface.getJavaClass();
        List<RuntimeWire> wires = callbackReference.getRuntimeWires();
        CallbackReferenceImpl ref = new CallbackReferenceImpl(javaClass, proxyFactory, wires);
        ref.resolveTarget();
        ReferenceParameters parameters = msgContext.getFrom().getReferenceParameters();
        ref.attachCallbackID(parameters.getCallbackID());
        if (ref.getConversation() != null) {
            ref.attachConversationID(parameters.getConversationID());
        }
        return ref;
View Full Code Here

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

        Message msgContext = ThreadMessageContext.getMessageContext();
        Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID();

        ThreadMessageContext.setMessageContext(msg);
        try {
            conversationPreinvoke(msg);
            // handleCallback(msg, currentConversationID);
            // dispatch the wire down the chain and get the response
            Message resp = headInvoker.invoke(msg);
            Object body = resp.getBody();
            if (resp.isFault()) {
                throw new InvocationTargetException((Throwable)body);
            }
            return body;
        } catch (InvocationTargetException e) {
            throw e;
View Full Code Here

        super(interfaze, null, proxyFactory);
        this.wires = wires;
    }

    public void resolveTarget() {
        Message msgContext = ThreadMessageContext.getMessageContext();
        wire = selectCallbackWire(msgContext);
        if (wire == null) {
            //FIXME: need better exception
            throw new RuntimeException("No callback wire found for " + msgContext.getFrom().getURI());
        }
        this.resolvedEndpoint = getCallbackEndpoint(msgContext);
        bind(wire);
    }
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.