Package org.apache.tuscany.sca.runtime

Examples of org.apache.tuscany.sca.runtime.ReferenceParameters


     *
     */
    @Override
    protected void handleCallback(Message msg, RuntimeWire wire, Object currentConversationID)
        throws TargetResolutionException {
        ReferenceParameters parameters = msg.getFrom().getReferenceParameters();
        parameters.setCallbackID(getCallbackID());
    }
View Full Code Here


        //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));
        }
        if (callbackID != null) {
            parameters.setCallbackID(callbackID);
        }
        if (conversationID != null) {
            parameters.setConversationID(conversationID);
        }

        for ( PolicyHandler policyHandler : policyHandlerList ) {
            policyHandler.beforeInvoke(msg, inMC);
        }
View Full Code Here

     * @param interfaze
     * @throws TargetResolutionException
     */
    private void handleCallback(Message msg, RuntimeWire wire, Object currentConversationID)
        throws TargetResolutionException {
        ReferenceParameters parameters = msg.getFrom().getReferenceParameters();
        parameters.setCallbackID(getCallbackID());
        if (msg.getFrom() == null || msg.getFrom().getCallbackEndpoint() == null) {
            return;
        }

        parameters.setCallbackReference(msg.getFrom().getCallbackEndpoint());

        // If we are passing out a callback target
        // register the calling component instance against this
        // new conversation id so that stateful callbacks will be
        // able to find it
        Object callbackObject = getCallbackObject();
        if (conversational && callbackObject == null) {
            // the component instance is already registered
            // so add another registration
            ScopeContainer<Object> scopeContainer = getConversationalScopeContainer(wire);

            if (scopeContainer != null && currentConversationID != null) {
                scopeContainer.addWrapperReference(currentConversationID, conversation.getConversationID());
            }
        }

        Interface interfaze = msg.getFrom().getCallbackEndpoint().getInterfaceContract().getInterface();
        if (callbackObject != null) {
            if (callbackObject instanceof ServiceReference) {
                EndpointReference callbackRef = ((CallableReferenceImpl)callbackObject).getEndpointReference();
                parameters.setCallbackReference(callbackRef);
            } else {
                if (interfaze != null) {
                    if (!interfaze.isConversational()) {
                        throw new IllegalArgumentException(
                                                           "Callback object for stateless callback is not a ServiceReference");
                    } else {
                        if (!(callbackObject instanceof Serializable)) {
                            throw new IllegalArgumentException(
                                                               "Callback object for stateful callback is not Serializable");
                        }
                        ScopeContainer scopeContainer = getConversationalScopeContainer(wire);
                        if (scopeContainer != null) {
                            InstanceWrapper wrapper = new CallbackObjectWrapper(callbackObject);
                            scopeContainer.registerWrapper(wrapper, conversation.getConversationID());
                        }
                        parameters.setCallbackObjectID(callbackObject);
                    }
                }
            }
        }
    }
View Full Code Here

        init(wire);
    }

    protected void init(RuntimeWire wire) {
        if (wire != null) {
            ReferenceParameters parameters = wire.getSource().getReferenceParameters();
            this.callbackID = parameters.getCallbackID();
            this.callbackObject = parameters.getCallbackReference();
            this.conversationID = parameters.getConversationID();
            InterfaceContract contract = wire.getSource().getInterfaceContract();
            this.conversational = contract.getInterface().isConversational();
        }
    }
View Full Code Here

     * @param msg
     * @throws TargetResolutionException
     */
    private void conversationPreinvoke(Message msg) {
        if (conversational) {
            ReferenceParameters parameters = msg.getFrom().getReferenceParameters();
            // in some cases the ConversationID that should be used comes in with the
            // message, e.g. when ws binding is in use.
            Object convID = parameters.getConversationID();
            if (convID != null) {
                conversationID = convID;
            }
            conversation = conversationManager.getConversation(conversationID);
           
            if (conversation == null || conversation.getState() == ConversationState.ENDED) {
                conversation = conversationManager.startConversation(conversationID);
                conversation.initializeConversationAttributes(wire.getTarget().getComponent());
            } else if (conversation.conversationalAttributesInitialized() == false) {
                conversation.initializeConversationAttributes(wire.getTarget().getComponent());
            } else if (conversation.isExpired()){
              throw new ConversationEndedException("Conversation has expired.");
            }
           
            conversation.updateLastReferencedTime();
   
            parameters.setConversationID(conversation.getConversationID());
        }
    }
View Full Code Here

        // Axis2 operationClients can not be shared so create a new one for each request
        final OperationClient operationClient = serviceClient.getServiceClient().createClient(wsdlOperationName);
        operationClient.setOptions(options);

        ReferenceParameters parameters = msg.getFrom().getReferenceParameters();

        // set callback endpoint and callback ID for WS-Addressing header
        EndpointReference fromEPR = null;
        org.apache.tuscany.sca.runtime.EndpointReference callbackEPR = parameters.getCallbackReference();
        if (callbackEPR != null) {
            fromEPR = new EndpointReference(callbackEPR.getBinding().getURI());
        }
        Object callbackID = parameters.getCallbackID();
        if (callbackID != null) {
            if (fromEPR == null) {
                fromEPR = new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL);
            }
            //FIXME: serialize callback ID to XML in case it is not a string
            fromEPR.addReferenceParameter(CALLBACK_ID_REFPARM_QN, callbackID.toString());
        }

        // set conversation ID for WS-Addressing header
        Object conversationId = parameters.getConversationID();
        if (conversationId != null) {
            if (fromEPR == null) {
                fromEPR = new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL);
            }
            //FIXME: serialize conversation ID to XML in case it is not a string
View Full Code Here

   
            if (jmsBinding.getOperationJMSType(operationName) != null) {
                jmsMsg.setJMSType(jmsBinding.getOperationJMSType(operationName));
            }
   
            ReferenceParameters parameters = tuscanyMsg.getFrom().getReferenceParameters();
   
            Object conversationID = parameters.getConversationID();
            if (conversationID != null) {
                jmsMsg.setStringProperty(JMSBindingConstants.CONVERSATION_ID_PROPERTY, conversationID.toString());
            }
   
            if (tuscanyMsg.getFrom().getCallbackEndpoint() != null) {
   
                if (parameters.getCallbackID() != null) {
                    jmsMsg.setStringProperty(JMSBindingConstants.CALLBACK_ID_PROPERTY, parameters.getCallbackID().toString());
                }
   
                String callbackDestName = getCallbackDestinationName(reference);
                if (callbackDestName != null) {
                    jmsMsg.setStringProperty(JMSBindingConstants.CALLBACK_Q_PROPERTY, callbackDestName);
View Full Code Here

            javax.jms.Message requestJMSMsg = context.getJmsMsg();
           
            EndpointReference from = new EndpointReferenceImpl(null);
            msg.setFrom(from);
            from.setCallbackEndpoint(new EndpointReferenceImpl("/")); // TODO: whats this for?
            ReferenceParameters parameters = from.getReferenceParameters();
   
            String conversationID = requestJMSMsg.getStringProperty(JMSBindingConstants.CONVERSATION_ID_PROPERTY);
            if (conversationID != null) {
                parameters.setConversationID(conversationID);
            }
           
            return msg;
        } catch (JMSException e) {
            throw new JMSBindingException(e);
View Full Code Here

        try {
            // get the jms context
            JMSBindingContext context = msg.getBindingContext();
            javax.jms.Message jmsMsg = context.getJmsMsg();
       
            ReferenceParameters parameters = msg.getFrom().getReferenceParameters();

            if (service.getInterfaceContract().getCallbackInterface() != null) {

                String callbackdestName = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_Q_PROPERTY);
                if (callbackdestName == null && msg.getOperation().isNonBlocking()) {
                    // if the request has a replyTo but this service operation is oneway but the service uses callbacks
                    // then use the replyTo as the callback destination
                    Destination replyTo = jmsMsg.getJMSReplyTo();
                    if (replyTo != null) {
                        callbackdestName = (replyTo instanceof Queue) ? ((Queue) replyTo).getQueueName() : ((Topic) replyTo).getTopicName();
                    }
                }

                if (callbackdestName != null) {
                    // append "jms:" to make it an absolute uri so the invoker can determine it came in on the request
                    // as otherwise the invoker should use the uri from the service callback binding
                    parameters.setCallbackReference(new EndpointReferenceImpl("jms:" + callbackdestName));
                }

                String callbackID = jmsMsg.getStringProperty(JMSBindingConstants.CALLBACK_ID_PROPERTY);
                if (callbackID != null) {
                    parameters.setCallbackID(callbackID);
                }
            }

        } catch (JMSException e) {
            throw new JMSBindingException(e);
View Full Code Here

        Object payload = msg.getBody();

        Object contextId = null;

        EndpointReference from = msg.getFrom();
        ReferenceParameters parameters = null;
        if (from != null) {
            parameters = from.getReferenceParameters();
        }
        // check what sort of context is required
        if (scopeContainer != null) {
            Scope scope = scopeContainer.getScope();
            if (scope == Scope.REQUEST) {
                contextId = Thread.currentThread();
            } else if (scope == Scope.CONVERSATION && parameters != null) {
                contextId = parameters.getConversationID();
            }
        }

        try {
            // The following call might create a new conversation, as a result, the msg.getConversationID() might
            // return a new value
            InstanceWrapper wrapper = scopeContainer.getWrapper(contextId);

            // detects whether the scope container has created a conversation Id. This will
            // happen in the case that the component has conversational scope but only the
            // callback interface is conversational. Or in the callback case if the service interface
            // is conversational and the callback interface isn't. If we are in this situation we need
            // to get the contextId of this component and remove it after we have invoked the method on
            // it. It is possible that the component instance will not go away when it is removed below
            // because a callback conversation will still be holding a reference to it
            boolean removeTemporaryConversationalComponentAfterCall = false;
            if (parameters != null && (contextId == null) && (parameters.getConversationID() != null)) {
                contextId = parameters.getConversationID();
                removeTemporaryConversationalComponentAfterCall = true;
            }

            Object instance = wrapper.getInstance();

            // If the method couldn't be computed statically, or the instance being
            // invoked is a user-specified callback object that doesn't implement
            // the service interface from which the reflective method was obtained,
            // compute the method object dynamically for this invocation.
            Method imethod = method;
            if (imethod == null || !imethod.getDeclaringClass().isInstance(instance)) {
                try {
                    imethod = JavaInterfaceUtil.findMethod(instance.getClass(), op);
                } catch (NoSuchMethodException e) {
                    throw new IllegalArgumentException("Callback object does not provide method " + e.getMessage());
                }
            }

            int argumentHolderCount = 0;

            // Holder pattern. Any payload parameters <T> which are should be in holders are placed in Holder<T>.
            // Only check Holder for remotable interfaces
            if (imethod != null && operation.getInterface().isRemotable()) {
                List<DataType> inputTypes = operation.getInputType().getLogical();
                for (int i = 0, size = inputTypes.size(); i < size; i++) {
                    if (ParameterMode.IN != operation.getParameterModes().get(i)) {
                        // Promote array params from [<T>] to [Holder<T>]
                        Object[] payloadArray = (Object[])payload;
                        for (int j = 0; payloadArray != null && j < payloadArray.length; j++) {
                            Object item = payloadArray[j];
                            payloadArray[j] = new Holder(item);
                        }
                        argumentHolderCount++;
                    }
                }
            }

            Object ret;
            if (payload != null && !payload.getClass().isArray()) {
                ret = imethod.invoke(instance, payload);
            } else {
                ret = imethod.invoke(instance, (Object[])payload);
            }

            scopeContainer.returnWrapper(wrapper, contextId);

            if ((sequence == ConversationSequence.CONVERSATION_END) || (removeTemporaryConversationalComponentAfterCall)) {
                // if end conversation, or we have the special case where a conversational
                // object was created to service the stateless half of a stateful component
                scopeContainer.remove(contextId);
                parameters.setConversationID(null);
            }

            if (argumentHolderCount > 0) {
                // Holder pattern. Any payload Holder<T> types are returned as the message body.
                List returnArgs = new ArrayList<Object>();
                if (imethod != null) {
                    for (int i = 0, size = operation.getParameterModes().size(); i < size; i++) {
                        // System.out.println( "JavaImplementationInvoker.invoke return parameter " + i + " type=" + parameter.getClass().getName() );
                        if (ParameterMode.IN != operation.getParameterModes().get(i)) {
                            // Demote array params from Holder<T> to <T>.
                            Object[] payloadArray = (Object[])payload;
                            for (int j = 0; j < payloadArray.length; j++) {
                                Holder<Object> item = (Holder<Object>)payloadArray[j];
                                payloadArray[j] = item.value;
                                returnArgs.add(payloadArray[j]);
                            }
                        }
                    }
                }
                // Although payload items are returned in a list, currently only support 1 return type.
                if (returnArgs.size() == 1) {
                    Object value = returnArgs.get(0);
                    msg.setBody(value);
                } else {
                    msg.setBody(returnArgs.toArray());
                }
            } else {
                msg.setBody(ret);
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getTargetException();
            boolean isChecked = false;
            for (DataType<?> d : operation.getFaultTypes()) {
                if (d.getPhysical().isInstance(cause)) {
                    isChecked = true;
                    msg.setFaultBody(cause);
                    break;
                }
            }

            if (sequence != ConversationSequence.CONVERSATION_NONE) {
                try {
                    //                    // If the exception is not a business exception then end the conversation
                    //                    boolean businessException = false;
                    //
                    //                    for (DataType dataType : operation.getFaultTypes()){
                    //                        if ((dataType.getPhysical() == e.getCause().getClass()) &&
                    //                            (contextId != null) ){
                    //                            businessException = true;
                    //                            break;
                    //                        }
                    //                    }

                    if (!isChecked && contextId != null) {
                        scopeContainer.remove(contextId);
                        parameters.setConversationID(null);
                    }
                } catch (Exception ex) {
                    // TODO - sure what the best course of action is here. We have
                    //        a system exception in the middle of a business exception
                }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.runtime.ReferenceParameters

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.