Package org.apache.tuscany.sca.binding.jms.context

Examples of org.apache.tuscany.sca.binding.jms.context.JMSBindingContext


    } // end method invoke
   
    public Message invokeRequest(Message tuscanyMsg) {
        try {
            // Get the JMS context
            JMSBindingContext context = tuscanyMsg.getBindingContext();
            javax.jms.Message jmsMsg = tuscanyMsg.getBody();
           
            Operation operation = tuscanyMsg.getOperation();
            String operationName = operation.getName();
            RuntimeEndpointReference reference = runtimeWire;
           
            // OASIS spec suggests we do not need to do anything with
            // @nativeOperation here on the reference side.
            requestMessageProcessor.setOperationName(operationName, jmsMsg);

            if (jmsBinding.getEffectiveJMSDeliveryMode(operationName) != null) {
              if (jmsBinding.getEffectiveJMSDeliveryMode(operationName)) {
                jmsMsg.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
              } else {
                jmsMsg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
              }
            }
   
            if (jmsBinding.getEffectiveJMSPriority(operationName) != null) {
              jmsMsg.setJMSPriority(jmsBinding.getEffectiveJMSPriority(operationName));
            }
   
            if ( jmsBinding.getEffectiveJMSType(operationName) != null ) {        
              jmsMsg.setJMSType(jmsBinding.getEffectiveJMSType(operationName));
            }
           
            if ( jmsBinding.getEffectiveJMSTimeToLive(operationName) != null ) {
              jmsMsg.setJMSExpiration(jmsBinding.getEffectiveJMSTimeToLive(operationName));
            }
           
            if (jmsBinding.getOperationJMSCorrelationId(operationName) != null) {
                jmsMsg.setJMSCorrelationID(jmsBinding.getOperationJMSCorrelationId(operationName));
            } else if (JMSBindingConstants.CORRELATE_CORRELATION_ID.equals(jmsBinding.getCorrelationScheme())) {
                jmsMsg.setJMSCorrelationID(UUID.randomUUID().toString());
            }
   
            if (tuscanyMsg.getFrom().getCallbackEndpoint() != null) {
   
                String callbackDestName = getCallbackDestinationName(reference);
                if (callbackDestName != null) {
                    jmsMsg.setStringProperty(JMSBindingConstants.CALLBACK_Q_PROPERTY, "jms:jndi:" + callbackDestName);
                    if (operation.isNonBlocking()) {
                      Destination dest = context.getJmsResourceFactory().lookupDestination(callbackDestName);
            jmsMsg.setJMSReplyTo(dest);
                    }
                }
            }
           
            for (String propName : jmsBinding.getPropertyNames()) {
                Object value = jmsBinding.getProperty(propName);
                jmsMsg.setObjectProperty(propName, value);
            }
   
            Map<String, Object> operationProperties = jmsBinding.getOperationProperties(operationName);
            if (operationProperties != null) {
                for (String propName : operationProperties.keySet()) {
                    Object value = operationProperties.get(propName);
                    jmsMsg.setObjectProperty(propName, value);
                }
            }
           
            if (jmsBinding.getEffectiveJMSTimeToLive(operationName) != null) {
                context.setTimeToLive(jmsBinding.getEffectiveJMSTimeToLive(operationName) * 2);       
            } else {  
              context.setTimeToLive(JMSBindingConstants.DEFAULT_TIME_TO_LIVE);       
            }
           
            // Adding MESSAGE_ID field to the JMS message, which is used to correlate async callbacks
            String msgID = (String)tuscanyMsg.getHeaders().get("MESSAGE_ID");
            if( msgID != null ) {
View Full Code Here


    public Message invoke(Message msg) {
        try {
            return invokeResponse(next.invoke(invokeRequest(msg)));
        } catch (Throwable e) {
            logger.log(Level.SEVERE, "Exception invoking service '" + service.getName(), e);
            JMSBindingContext context = msg.getBindingContext();
            javax.jms.Message replyJMSMsg = responseMessageProcessor.createFaultMessage(context.getJmsResponseSession(),
                                                                                        (Throwable)e);
            msg.setBody(replyJMSMsg);
            invokeResponse(msg);
            return msg;
        } finally {
View Full Code Here

            return msg;

    } // end method invokeRequest
   
    public Message invokeResponse(Message msg) {
        JMSBindingContext context = msg.getBindingContext();
        try {

            //if operation is oneway, return back.
            Operation operation = msg.getOperation();
            if (operation != null && operation.isNonBlocking()) {
                return msg;
            }

            Session session = context.getJmsResponseSession();
            javax.jms.Message requestJMSMsg = context.getJmsMsg();
            javax.jms.Message responseJMSMsg = msg.getBody();
           
            Destination replyDest = requestJMSMsg.getJMSReplyTo();
            if (replyDest == null) {
                if (jmsBinding.getResponseDestinationName() != null) {
                    try {
                        replyDest = jmsResourceFactory.lookupDestination(jmsBinding.getResponseDestinationName());
                    } catch (NamingException e) {
                        throw new JMSBindingException("Exception lookingup response destination", e);
                    }
                }
            }

            if (replyDest == null) {
                // assume no reply is expected
                if (msg.getBody() != null) {
                    logger.log(Level.FINE, "JMS service '" + service.getName() + "' dropped response as request has no replyTo");
                }
                return msg;
            }

            if ((msg.getOperation() != null)) {
                String operationName = msg.getOperation().getName();
                if (jmsBinding.getEffectiveJMSPriority(operationName) != null) {
                    responseJMSMsg.setJMSPriority(jmsBinding.getEffectiveJMSPriority(operationName));
                }
       
                if ( jmsBinding.getEffectiveJMSType(operationName) != null) {
                    responseJMSMsg.setJMSType(jmsBinding.getEffectiveJMSType(operationName));
                }
               
                if ((jmsBinding.getEffectiveJMSDeliveryMode(operationName) != null)) {
                    responseJMSMsg.setJMSDeliveryMode(jmsBinding.getEffectiveJMSDeliveryMode(operationName) ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);                  
                }
               
                if ((jmsBinding.getEffectiveJMSTimeToLive(operationName) != null)) {
                  responseJMSMsg.setJMSExpiration(jmsBinding.getEffectiveJMSTimeToLive(operationName).longValue());
                }
            }
   
            if (correlationScheme == null ||
                JMSBindingConstants.CORRELATE_MSG_ID.equalsIgnoreCase(correlationScheme)) {
                responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSMessageID());
            } else if (JMSBindingConstants.CORRELATE_CORRELATION_ID.equalsIgnoreCase(correlationScheme)) {
                responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSCorrelationID());
            }               
                      
            MessageProducer producer = session.createProducer(replyDest);
           
            // Set jms header attributes in producer, not message.
            int deliveryMode = requestJMSMsg.getJMSDeliveryMode();
            producer.setDeliveryMode(deliveryMode);
            int deliveryPriority = requestJMSMsg.getJMSPriority();
            producer.setPriority(deliveryPriority);
            long timeToLive = requestJMSMsg.getJMSExpiration();
            producer.setTimeToLive(timeToLive);
   
            producer.send((javax.jms.Message)msg.getBody());
   
            producer.close();
           
            return msg;
   
        } catch (JMSException e) {
            throw new JMSBindingException(e);
        } finally {
            context.closeJmsResponseSession();
        }
    }   
View Full Code Here

  public Message processRequest(Message msg) {
    return invokeRequest( msg );
  } // end method processRequest

  public Message processResponse(Message msg) {
        JMSBindingContext context = msg.getBindingContext();
        try {
            Session session = context.getJmsResponseSession();
            //javax.jms.Message requestJMSMsg = context.getJmsMsg();
            javax.jms.Message responseJMSMsg = msg.getBody();
           
            //Destination replyDest = requestJMSMsg.getJMSReplyTo();
            Destination replyDest = context.getReplyToDestination();
            if (replyDest == null) {
                if (jmsBinding.getResponseDestinationName() != null) {
                    try {
                        replyDest = jmsResourceFactory.lookupDestination(jmsBinding.getResponseDestinationName());
                    } catch (NamingException e) {
                        throw new JMSBindingException("Exception lookingup response destination", e);
                    }
                }
            } // end if

            if (replyDest == null) {
                // assume no reply is expected
                if (msg.getBody() != null) {
                    logger.log(Level.FINE, "JMS service '" + service.getName() + "' dropped response as request has no replyTo");
                }
                return msg;
            } // end if

            if ((msg.getOperation() != null)) {
                String operationName = msg.getOperation().getName();
                if (jmsBinding.getEffectiveJMSPriority(operationName) != null) {
                    responseJMSMsg.setJMSPriority(jmsBinding.getEffectiveJMSPriority(operationName));
                }
       
                if ( jmsBinding.getEffectiveJMSType(operationName) != null) {
                    responseJMSMsg.setJMSType(jmsBinding.getEffectiveJMSType(operationName));
                }
               
                if ((jmsBinding.getEffectiveJMSDeliveryMode(operationName) != null)) {
                    responseJMSMsg.setJMSDeliveryMode(jmsBinding.getEffectiveJMSDeliveryMode(operationName) ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);                  
                }
               
                if ((jmsBinding.getEffectiveJMSTimeToLive(operationName) != null)) {
                  responseJMSMsg.setJMSExpiration(jmsBinding.getEffectiveJMSTimeToLive(operationName).longValue());
                }
            }
   
            /*
            if (correlationScheme == null ||
                JMSBindingConstants.CORRELATE_MSG_ID.equalsIgnoreCase(correlationScheme)) {
                responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSMessageID());
            } else if (JMSBindingConstants.CORRELATE_CORRELATION_ID.equalsIgnoreCase(correlationScheme)) {
                responseJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSCorrelationID());
            } 
            */             
                      
            MessageProducer producer = session.createProducer(replyDest);
           
            // Set jms header attributes in producer, not message.
            //int deliveryMode = requestJMSMsg.getJMSDeliveryMode();
            //producer.setDeliveryMode(deliveryMode);
            //int deliveryPriority = requestJMSMsg.getJMSPriority();
            //producer.setPriority(deliveryPriority);
            //long timeToLive = requestJMSMsg.getJMSExpiration();
            //producer.setTimeToLive(timeToLive);
   
            producer.send((javax.jms.Message)msg.getBody());
   
            producer.close();
           
            return msg;
   
        } catch (JMSException e) {
            throw new JMSBindingException(e);
        } finally {
            context.closeJmsResponseSession();
        } // end try
  } // end method processResponse 
View Full Code Here

        return next.invoke(invokeRequest(msg));
    }   
   
    public Message invokeRequest(Message msg) {
            // get the jms context
            JMSBindingContext context = msg.getBindingContext();
            javax.jms.Message jmsMsg = context.getJmsMsg();
           
            String operationName = requestMessageProcessor.getOperationName(jmsMsg);
            Operation operation = getTargetOperation(operationName, jmsMsg);
            msg.setOperation(operation);
View Full Code Here

        return msg;
    }

    public Message invokeRequest(Message msg) {
        // get the jms context
        JMSBindingContext context = msg.getBindingContext();
        javax.jms.Message jmsMsg = context.getJmsMsg();

        Object requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(jmsMsg);
        msg.setBody(new Object[] { requestPayload });

        return msg;
View Full Code Here

    }
   
    public Message invokeResponse(Message msg) {
       
        // get the jms context
        JMSBindingContext context = msg.getBindingContext();
        Session session = context.getJmsResponseSession();

        javax.jms.Message responseJMSMsg;
        if (msg.isFault()) {
            responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody());
        } else {
View Full Code Here

        return msg;
    }
   
    public Message invokeRequest(Message msg) {
        // get the jms context
        JMSBindingContext context = msg.getBindingContext();
        javax.jms.Message jmsMsg = context.getJmsMsg();
        Object requestPayload;
       
        // If the service interface has a single argument then we need
        // to check if the object from the wire is expected 
        // to be unwrapped or not
View Full Code Here

        return msg;
    }
   
    public Message invokeResponse(Message msg) {
        // get the jms context
        JMSBindingContext context = msg.getBindingContext();
        Session session = context.getJmsResponseSession();

        javax.jms.Message responseJMSMsg = null;
        if (msg.isFault()) {
            responseJMSMsg = responseMessageProcessor.createFaultMessage(session, (Throwable)msg.getBody());
        } else {
View Full Code Here

    }

    public Message invokeRequest(Message msg) {
        try {
            // get the jms context
            JMSBindingContext context = msg.getBindingContext();
            Session session = context.getJmsSession();

            javax.jms.Message requestMsg;

            if (((WireFormatJMSDefault) jmsBinding.getRequestWireFormat()).isUseBytesMessage()) {
                requestMsg = requestMessageProcessor.insertPayloadIntoJMSBytesMessage(session, msg.getBody(), this.inputWrapperMap.get(msg.getOperation().getName()));
            } else {
                requestMsg = requestMessageProcessor.insertPayloadIntoJMSTextMessage(session, msg.getBody(), this.inputWrapperMap.get(msg.getOperation().getName()));
            }

            msg.setBody(requestMsg);

            requestMsg.setJMSReplyTo(context.getReplyToDestination());

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

TOP

Related Classes of org.apache.tuscany.sca.binding.jms.context.JMSBindingContext

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.