You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by as...@apache.org on 2007/03/30 08:04:43 UTC

svn commit: r523954 - in /webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2: Constants.java transport/jms/JMSConnectionFactory.java transport/jms/JMSConstants.java transport/jms/JMSMessageReceiver.java transport/jms/JMSSender.java

Author: asankha
Date: Thu Mar 29 23:04:42 2007
New Revision: 523954

URL: http://svn.apache.org/viewvc?view=rev&rev=523954
Log:
apply fixes for  AXIS2-2434 and AXIS2-2266 from trunk

Modified:
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/Constants.java
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSConnectionFactory.java
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSConstants.java
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSMessageReceiver.java
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSSender.java

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/Constants.java?view=diff&rev=523954&r1=523953&r2=523954
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/Constants.java (original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/Constants.java Thu Mar 29 23:04:42 2007
@@ -266,8 +266,6 @@
         public static final String CONTENT_TYPE = "ContentType";
         public static final String CONTENT_TYPE_OF_FAULT = "ContentTypeOfFault";
 
-        public static final String IS_USING_SEPARATE_LISTENER = "IsUsingSeparateListener";
-
         public static final String CONFIG_CONTEXT_TIMOUT_INTERVAL = "ConfigContextTimeoutInterval";
 
         public static final String TRANSPORT_IN_URL = "TransportInURL";

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSConnectionFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSConnectionFactory.java?view=diff&rev=523954&r1=523953&r2=523954
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSConnectionFactory.java (original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSConnectionFactory.java Thu Mar 29 23:04:42 2007
@@ -17,6 +17,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.addressing.EndpointReference;
 
 import javax.jms.*;
 import javax.naming.Context;
@@ -176,8 +177,38 @@
      * @param serviceName     the service to which it belongs
      */
     public void addDestination(String destinationJndi, String serviceName) {
+
         serviceJNDINameMapping.put(destinationJndi, serviceName);
-        serviceDestinationMapping.put(getDestinationName(destinationJndi), serviceName);
+        String destinationName = getDestinationName(destinationJndi);
+        log.warn("JMS Destination with JNDI name : " + destinationJndi + " does not exist");
+
+        Connection con = null;
+        try {
+            con = conFactory.createConnection();
+            Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            Queue queue = session.createQueue(destinationJndi);
+            destinationName = queue.getQueueName();
+            log.warn("JMS Destination with JNDI name : " + destinationJndi + " created");
+            
+        } catch (JMSException e) {
+            log.error("Unable to create a Destination with JNDI name : " + destinationJndi, e);
+            // mark service as faulty
+            JMSUtils.markServiceAsFaulty(
+                (String) serviceJNDINameMapping.get(destinationJndi),
+                "Error looking up JMS destination : " + destinationJndi,
+                msgRcvr.getAxisConf().getAxisConfiguration());
+
+        } finally {
+            if (con != null) {
+                try {
+                    con.close();
+                } catch (JMSException ignore) {}
+            }
+        }
+
+        serviceDestinationMapping.put(destinationName, serviceName);
+        log.info("Mapping JNDI name : " + destinationJndi + " and JMS Destination name : " +
+            destinationName + " against service : " + serviceName);
     }
 
     /**
@@ -377,6 +408,28 @@
                 " to map its corresponding provider specific Destination name");
         }
         return null;
+    }
+
+    /**
+     * Return the EPR for the JMS Destination with the given JNDI name and using
+     * this connection factory
+     * @param destination the JNDI name of the JMS Destionation
+     * @return the EPR
+     */
+    public EndpointReference getEPRForDestination(String destination) {
+
+        StringBuffer sb = new StringBuffer();
+        sb.append(JMSConstants.JMS_PREFIX).append(destination);
+        sb.append("?").append(JMSConstants.CONFAC_JNDI_NAME_PARAM).
+                append("=").append(getJndiName());
+        Iterator props = getProperties().keySet().iterator();
+        while (props.hasNext()) {
+            String key = (String) props.next();
+            String value = (String) getProperties().get(key);
+            sb.append("&").append(key).append("=").append(value);
+        }
+
+        return new EndpointReference(sb.toString());
     }
 
     public String getServiceByDestination(String destinationName) {

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSConstants.java?view=diff&rev=523954&r1=523953&r2=523954
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSConstants.java (original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSConstants.java Thu Mar 29 23:04:42 2007
@@ -28,9 +28,14 @@
     public static final String JMS_PREFIX = "jms:/";
 
     /**
-     * The Parameter name indicating a JMS destination
+     * The Parameter name indicating a JMS destination for requests
      */
     public static final String DEST_PARAM = "transport.jms.Destination";
+
+    /**
+     * The Parameter name indicating the response JMS destination
+     */
+    public static final String REPLY_PARAM = "transport.jms.ReplyDestination";
 
     /**
      * The Parameter name indicating the JMS destination type

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSMessageReceiver.java?view=diff&rev=523954&r1=523953&r2=523954
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSMessageReceiver.java (original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSMessageReceiver.java Thu Mar 29 23:04:42 2007
@@ -19,6 +19,7 @@
 import org.apache.axiom.om.util.UUIDGenerator;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.description.Parameter;
 import org.apache.axis2.addressing.RelatesTo;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.ContextFactory;
@@ -101,8 +102,14 @@
     public void onMessage(Message message) {
         // directly create a new worker and delegate processing
         try {
-            log.debug("Received JMS message to destination : " +
-                    message.getJMSDestination());
+            if (log.isDebugEnabled()) {
+                StringBuffer sb = new StringBuffer();
+                sb.append("Received JMS message to destination : " + message.getJMSDestination());                
+                sb.append("\nMessage ID : " + message.getJMSMessageID());
+                sb.append("\nCorrelation ID : " + message.getJMSCorrelationID());
+                sb.append("\nReplyTo ID : " + message.getJMSReplyTo());
+                log.debug(sb.toString());
+            }
         } catch (JMSException e) {
             e.printStackTrace();
         }
@@ -168,6 +175,19 @@
             msgContext.setServerSide(true);
             msgContext.setServiceGroupContextId(UUIDGenerator.getUUID());
             msgContext.setMessageID(message.getJMSMessageID());
+
+            Destination replyTo = message.getJMSReplyTo();
+            String jndiDestinationName = null;
+            if (replyTo == null) {
+                Parameter param = msgContext.getAxisService().getParameter(JMSConstants.REPLY_PARAM);
+                if (param != null && param.getValue() != null) {
+                    jndiDestinationName = (String) param.getValue();
+                }
+            }
+
+            if (jndiDestinationName != null) {
+                msgContext.setReplyTo(jmsConFac.getEPRForDestination(jndiDestinationName));
+            }
 
             String soapAction = JMSUtils.getProperty(message, JMSConstants.SOAPACTION);
             if (soapAction != null) {

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSSender.java?view=diff&rev=523954&r1=523953&r2=523954
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSSender.java (original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSSender.java Thu Mar 29 23:04:42 2007
@@ -22,6 +22,8 @@
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.description.WSDL2Constants;
+import org.apache.axis2.description.Parameter;
 import org.apache.axis2.handlers.AbstractHandler;
 import org.apache.axis2.transport.TransportSender;
 import org.apache.commons.logging.Log;
@@ -38,8 +40,13 @@
 import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.xml.stream.XMLStreamException;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.util.Hashtable;
 
 /**
  * The TransportSender for JMS
@@ -83,17 +90,6 @@
                     msgContext.getProperty(Constants.OUT_TRANSPORT_INFO);
         }
 
-        // should we wait and listen for a response?
-        boolean waitForResponse = false;
-
-        Object seprLisn = msgContext.getProperty(
-                Constants.Configuration.IS_USING_SEPARATE_LISTENER);
-        if (Boolean.TRUE.equals(seprLisn)) {
-            waitForResponse = false;
-        } else if (!msgContext.isServerSide()) {
-            waitForResponse = !msgContext.getOptions().isUseSeparateListener();
-        }
-
         // get the ConnectionFactory to be used for the send
         ConnectionFactory connectionFac = transportInfo.getConnectionFactory();
 
@@ -119,14 +115,45 @@
             MessageProducer producer = session.createProducer(dest);
             Destination replyDest = null;
 
+            boolean waitForResponse =
+                msgContext.getOperationContext() != null &&
+                WSDL2Constants.MEP_URI_OUT_IN.equals(
+                    msgContext.getOperationContext().getAxisOperation().getMessageExchangePattern());
+
             if (waitForResponse) {
-                try {
-                    // create temporary queue to receive reply
-                    replyDest = session.createTemporaryQueue();
-                    message.setJMSReplyTo(replyDest);
-                } catch (JMSException e) {
-                    handleException("Error creating temporary queue for response");
+                String replyToJNDIName = (String) msgContext.getProperty(JMSConstants.REPLY_PARAM);
+                if (replyToJNDIName != null && replyToJNDIName.length() > 0) {
+                    Context context = null;
+                    Hashtable props = JMSUtils.getProperties(targetAddress);
+                    try {
+                        context = new InitialContext(props);
+                    } catch (NamingException e) {
+                        handleException("Could not get the initial context", e);
+                    }
+
+                    try {
+                        replyDest = (Destination) context.lookup(replyToJNDIName);
+
+                    } catch (NameNotFoundException e) {
+                        log.warn("Cannot get or lookup JMS response destination : " +
+                            replyToJNDIName + " : " + e.getMessage() +
+                            ". Attempting to create a Queue named : " + replyToJNDIName);
+                        replyDest = session.createQueue(replyToJNDIName);
+
+                    } catch (NamingException e) {
+                        handleException("Cannot get JMS response destination : " +
+                            replyToJNDIName + " : ", e);
+                    }
+
+                } else {
+                    try {
+                        // create temporary queue to receive reply
+                        replyDest = session.createTemporaryQueue();
+                    } catch (JMSException e) {
+                        handleException("Error creating temporary queue for response");
+                    }
                 }
+                message.setJMSReplyTo(replyDest);
             }
 
             try {



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org