You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2008/11/05 00:03:23 UTC

svn commit: r711460 - in /webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms: JMSConnectionFactory.java JMSEndpoint.java JMSListener.java JMSMessageReceiver.java JMSUtils.java

Author: veithen
Date: Tue Nov  4 15:03:22 2008
New Revision: 711460

URL: http://svn.apache.org/viewvc?rev=711460&view=rev
Log:
JMS transport: Introduced a new class, JMSEndpoint, that centralizes the JMS configuration for a given Axis2 service. The role of the JMSEndpoint class is similar to the PollTableEntry classes in the polling transports and the Endpoint class in the UDP transport. This also prepares resolution of SYNAPSE-424.

Added:
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSEndpoint.java   (with props)
Modified:
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConnectionFactory.java
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java

Modified: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConnectionFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConnectionFactory.java?rev=711460&r1=711459&r2=711460&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConnectionFactory.java (original)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConnectionFactory.java Tue Nov  4 15:03:22 2008
@@ -84,10 +84,8 @@
     private final WorkerPool workerPool;
     /** The JNDI name of the actual connection factory */
     private String connFactoryJNDIName = null;
-    /** Map of destination JNDI names to service names */
-    private Map<String,String> serviceJNDINameMapping = null;
-    /** Map of destination JNDI names to destination types*/
-    private Map<String,String> destinationTypeMapping = null;
+    /** Map of destination JNDI names to endpoints */
+    private Map<String,JMSEndpoint> endpointJNDINameMapping = null;
     /** JMS Sessions currently active. One session for each Destination / Service */
     private Map<String,Session> jmsSessions = null;
     /** Properties of the connection factory to acquire the initial context */
@@ -122,8 +120,7 @@
         this.jmsListener = jmsListener;
         this.workerPool = workerPool;
         this.cfgCtx = cfgCtx;
-        serviceJNDINameMapping = new HashMap<String,String>();
-        destinationTypeMapping = new HashMap<String,String>();
+        endpointJNDINameMapping = new HashMap<String,JMSEndpoint>();
         jndiProperties = new Hashtable<String,String>();
         jmsSessions = new HashMap<String,Session>();
     }
@@ -132,11 +129,11 @@
     /**
      * Add a listen destination on this connection factory on behalf of the given service
      *
-     * @param destinationJNDIName destination JNDI name
-     * @param serviceName     the service to which it belongs
+     * @param endpoint the {@link JMSEndpoint} object that specifies the destination and
+     *                 the service
      */
-    public void addDestination(String destinationJNDIName, String destinationType, String serviceName) {
-
+    public void addDestination(JMSEndpoint endpoint) {
+        String destinationJNDIName = endpoint.getJndiDestinationName();
         String destinationName = getPhysicalDestinationName(destinationJNDIName);
 
         if (destinationName == null) {
@@ -145,25 +142,24 @@
             try {
                 log.info("Creating a JMS Queue with the JNDI name : " + destinationJNDIName +
                     " using the connection factory definition named : " + name);
-                JMSUtils.createDestination(conFactory, destinationJNDIName, destinationType);
+                JMSUtils.createDestination(conFactory, destinationJNDIName, endpoint.getDestinationType());
 
                 destinationName = getPhysicalDestinationName(destinationJNDIName);
                 
             } catch (JMSException e) {
                 log.error("Unable to create Destination with JNDI name : " + destinationJNDIName, e);
                 BaseUtils.markServiceAsFaulty(
-                    serviceName,
+                    endpoint.getServiceName(),
                     "Error creating JMS destination : " + destinationJNDIName,
                     cfgCtx.getAxisConfiguration());
                 return;
             }
         }
 
-        serviceJNDINameMapping.put(destinationJNDIName, serviceName);
-        destinationTypeMapping.put(destinationJNDIName, destinationType);
+        endpointJNDINameMapping.put(destinationJNDIName, endpoint);
 
         log.info("Mapped JNDI name : " + destinationJNDIName + " and JMS Destination name : " +
-            destinationName + " against service : " + serviceName);
+            destinationName + " against service : " + endpoint.getServiceName());
     }
 
     /**
@@ -173,7 +169,7 @@
      */
     public void removeDestination(String jndiDestinationName) {
         stoplisteningOnDestination(jndiDestinationName);
-        serviceJNDINameMapping.remove(jndiDestinationName);
+        endpointJNDINameMapping.remove(jndiDestinationName);
     }
 
     /**
@@ -248,11 +244,8 @@
             handleException("Error connecting to Connection Factory : " + connFactoryJNDIName, e);
         }
 
-        for (Map.Entry<String,String> entry : serviceJNDINameMapping.entrySet()) {
-            String destJNDIName = entry.getKey();
-            String serviceName = entry.getValue();
-            String destinationType = destinationTypeMapping.get(destJNDIName);
-            startListeningOnDestination(destJNDIName, destinationType, serviceName);
+        for (JMSEndpoint endpoint : endpointJNDINameMapping.values()) {
+            startListeningOnDestination(endpoint);
         }
 
         connection.start(); // indicate readiness to start receiving messages
@@ -294,12 +287,11 @@
      * Listen on the given destination from this connection factory. Used to
      * start listening on a destination associated with a newly deployed service
      *
-     * @param destinationJNDIname the JMS destination to listen on
+     * @param endpoint the JMS destination to listen on
      */
-    public void startListeningOnDestination(String destinationJNDIname,
-                                            String destinationType,
-                                            String serviceName) {
-
+    public void startListeningOnDestination(JMSEndpoint endpoint) {
+        String destinationJNDIname = endpoint.getJndiDestinationName();
+        String destinationType = endpoint.getDestinationType();
         Session session = jmsSessions.get(destinationJNDIname);
         // if we already had a session open, close it first
         if (session != null) {
@@ -322,7 +314,7 @@
 
             MessageConsumer consumer = JMSUtils.createConsumer(session, destination);
             consumer.setMessageListener(new JMSMessageReceiver(jmsListener, this, workerPool,
-                    cfgCtx, serviceName));
+                    cfgCtx, endpoint));
             jmsSessions.put(destinationJNDIname, session);
 
         // catches NameNotFound and JMSExceptions and marks service as faulty    
@@ -334,7 +326,7 @@
             }
 
             BaseUtils.markServiceAsFaulty(
-                serviceJNDINameMapping.get(destinationJNDIname),
+                endpoint.getServiceName(),
                 "Error looking up JMS destination : " + destinationJNDIname,
                 cfgCtx.getAxisConfiguration());
         }
@@ -454,16 +446,6 @@
 
     // -------------------- getters and setters and trivial methods --------------------
 
-    /**
-     * Return the service name using the JMS destination given by the JNDI name
-     *
-     * @param jndiDestinationName the JNDI name of the destination
-     * @return the name of the service using the destination
-     */
-    public String getServiceNameForJNDIName(String jndiDestinationName) {
-        return serviceJNDINameMapping.get(jndiDestinationName);
-    }
-
     public void setConnFactoryJNDIName(String connFactoryJNDIName) {
         this.connFactoryJNDIName = connFactoryJNDIName;
     }

Added: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSEndpoint.java?rev=711460&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSEndpoint.java (added)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSEndpoint.java Tue Nov  4 15:03:22 2008
@@ -0,0 +1,75 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.axis2.transport.jms;
+
+import org.apache.axis2.description.AxisService;
+
+/**
+ * Class that links an Axis2 service to a JMS destination. Additionally, it contains
+ * all the required information to process incoming JMS messages and to inject them
+ * into Axis2.
+ */
+public class JMSEndpoint {
+    private AxisService service;
+    private String jndiDestinationName;
+    private String destinationType;
+    private String endpointReference;
+    private String contentType;
+
+    public AxisService getService() {
+        return service;
+    }
+
+    public void setService(AxisService service) {
+        this.service = service;
+    }
+    
+    public String getServiceName() {
+        return service.getName();
+    }
+
+    public String getJndiDestinationName() {
+        return jndiDestinationName;
+    }
+
+    public void setJndiDestinationName(String destinationJNDIName) {
+        this.jndiDestinationName = destinationJNDIName;
+    }
+
+    public String getDestinationType() {
+        return destinationType;
+    }
+
+    public void setDestinationType(String destinationType) {
+        this.destinationType = destinationType;
+    }
+
+    public String getEndpointReference() {
+        return endpointReference;
+    }
+
+    public void setEndpointReference(String endpointReference) {
+        this.endpointReference = endpointReference;
+    }
+
+    public String getContentType() {
+        return contentType;
+    }
+
+    public void setContentType(String contentType) {
+        this.contentType = contentType;
+    }
+}

Propchange: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java?rev=711460&r1=711459&r2=711460&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java (original)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java Tue Nov  4 15:03:22 2008
@@ -61,8 +61,8 @@
     public static final String TRANSPORT_NAME = Constants.TRANSPORT_JMS;
 
     private JMSConnectionFactoryManager connFacManager;
-    /** A Map of service name to the JMS EPR addresses */
-    private Map<String,String> serviceNameToEPRMap = new HashMap<String,String>();
+    /** A Map of service name to the JMS endpoints */
+    private Map<String,JMSEndpoint> serviceNameToEndpointMap = new HashMap<String,JMSEndpoint>();
 
     private final TransportErrorSourceSupport tess = new TransportErrorSourceSupport(this);
     
@@ -124,8 +124,12 @@
         if (serviceName.indexOf('.') != -1) {
             serviceName = serviceName.substring(0, serviceName.indexOf('.'));
         }
-        return new EndpointReference[]{
-            new EndpointReference(serviceNameToEPRMap.get(serviceName))};
+        JMSEndpoint endpoint = serviceNameToEndpointMap.get(serviceName);
+        if (endpoint != null) {
+            return new EndpointReference[] { new EndpointReference(endpoint.getEndpointReference()) };
+        } else {
+            return null;
+        }
     }
 
     /**
@@ -146,16 +150,42 @@
             return;
         }
 
+        JMSEndpoint endpoint = new JMSEndpoint();
+        endpoint.setService(service);
+        
+        Parameter destParam = service.getParameter(JMSConstants.DEST_PARAM);
+        if (destParam != null) {
+            endpoint.setJndiDestinationName((String)destParam.getValue());
+        } else {
+            // Assume that the JNDI destination name is the same as the service name
+            endpoint.setJndiDestinationName(service.getName());
+        }
+        
+        Parameter destTypeParam = service.getParameter(JMSConstants.DEST_PARAM_TYPE);
+        if (destTypeParam != null) {
+            String paramValue = (String) destTypeParam.getValue();
+            if(JMSConstants.DESTINATION_TYPE_QUEUE.equals(paramValue) ||
+                    JMSConstants.DESTINATION_TYPE_TOPIC.equals(paramValue) )  {
+                endpoint.setDestinationType(paramValue);
+            } else {
+                throw new AxisJMSException("Invalid destinaton type value " + paramValue);
+            }
+        } else {
+            log.debug("JMS destination type not given. default queue");
+            endpoint.setDestinationType(JMSConstants.DESTINATION_TYPE_QUEUE);
+        }
+        
         // compute service EPR and keep for later use
-        String destinationName = JMSUtils.getJNDIDestinationNameForService(service);
-        String destinationType = JMSUtils.getDestinationTypeForService(service);
-        serviceNameToEPRMap.put(service.getName(),
-                JMSUtils.getEPR(cf, destinationType, destinationName));
+        endpoint.setEndpointReference(JMSUtils.getEPR(cf, endpoint.getDestinationType(),
+                endpoint.getJndiDestinationName()));
+        serviceNameToEndpointMap.put(service.getName(), endpoint);
+        
+        endpoint.setContentType((String)service.getParameterValue(JMSConstants.CONTENT_TYPE_PARAM));
         
-        log.info("Starting to listen on destination : " + destinationName + " of type "
-                + destinationType + " for service " + service.getName());
-        cf.addDestination(destinationName, destinationType, service.getName());
-        cf.startListeningOnDestination(destinationName, destinationType, service.getName());
+        log.info("Starting to listen on destination : " + endpoint.getJndiDestinationName() + " of type "
+                + endpoint.getDestinationType() + " for service " + service.getName());
+        cf.addDestination(endpoint);
+        cf.startListeningOnDestination(endpoint);
     }
 
     /**
@@ -168,10 +198,9 @@
         JMSConnectionFactory cf = getConnectionFactory(service);
         if (cf != null) {
             // remove from the serviceNameToEprMap
-            serviceNameToEPRMap.remove(service.getName());
+            JMSEndpoint endpoint = serviceNameToEndpointMap.remove(service.getName());
 
-            String destination = JMSUtils.getJNDIDestinationNameForService(service);
-            cf.removeDestination(destination);
+            cf.removeDestination(endpoint.getJndiDestinationName());
         }
     }
     /**

Modified: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java?rev=711460&r1=711459&r2=711460&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java (original)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java Tue Nov  4 15:03:22 2008
@@ -49,8 +49,8 @@
     private ConfigurationContext cfgCtx = null;
     /** A reference to the JMS Connection Factory to which this applies */
     private JMSConnectionFactory jmsConnectionFactory = null;
-    /** The name of the service this message receiver is bound to. */
-    final String serviceName;
+    /** The endpoint this message receiver is bound to. */
+    final JMSEndpoint endpoint;
     /** Metrics collector */
     private MetricsCollector metrics = null;
 
@@ -64,12 +64,12 @@
      * @param serviceName the name of the Axis service
      */
     JMSMessageReceiver(JMSListener jmsListener, JMSConnectionFactory jmsConFac,
-                       WorkerPool workerPool, ConfigurationContext cfgCtx, String serviceName) {
+                       WorkerPool workerPool, ConfigurationContext cfgCtx, JMSEndpoint endpoint) {
         this.jmsListener = jmsListener;
         this.jmsConnectionFactory = jmsConFac;
         this.workerPool = workerPool;
         this.cfgCtx = cfgCtx;
-        this.serviceName = serviceName;
+        this.endpoint = endpoint;
         this.metrics = jmsListener.getMetricsCollector();
     }
 
@@ -163,23 +163,20 @@
                 String soapAction = JMSUtils.
                     getProperty(message, BaseConstants.SOAPACTION);
 
-                // set to bypass dispatching if we know the service - we already should!
-                if (serviceName != null) {
-                    service = cfgCtx.getAxisConfiguration().getService(serviceName);
-                    msgContext.setAxisService(service);
-
-                    // find the operation for the message, or default to one
-                    Parameter operationParam = service.getParameter(BaseConstants.OPERATION_PARAM);
-                    QName operationQName = (
-                        operationParam != null ?
-                            BaseUtils.getQNameFromString(operationParam.getValue()) :
-                            BaseConstants.DEFAULT_OPERATION);
-
-                    AxisOperation operation = service.getOperation(operationQName);
-                    if (operation != null) {
-                        msgContext.setAxisOperation(operation);
-                        msgContext.setSoapAction("urn:" + operation.getName().getLocalPart());
-                    }
+                service = endpoint.getService();
+                msgContext.setAxisService(service);
+
+                // find the operation for the message, or default to one
+                Parameter operationParam = service.getParameter(BaseConstants.OPERATION_PARAM);
+                QName operationQName = (
+                    operationParam != null ?
+                        BaseUtils.getQNameFromString(operationParam.getValue()) :
+                        BaseConstants.DEFAULT_OPERATION);
+
+                AxisOperation operation = service.getOperation(operationQName);
+                if (operation != null) {
+                    msgContext.setAxisOperation(operation);
+                    msgContext.setSoapAction("urn:" + operation.getName().getLocalPart());
                 }
 
                 // set the message property OUT_TRANSPORT_INFO
@@ -202,10 +199,7 @@
                     }
                 }
 
-                String contentType = null;
-                if (service != null) {
-                    contentType = (String)service.getParameterValue(JMSConstants.CONTENT_TYPE_PARAM);
-                }
+                String contentType = endpoint.getContentType();
                 if (contentType == null) {
                     contentType
                         = JMSUtils.getProperty(message, BaseConstants.CONTENT_TYPE);

Modified: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java?rev=711460&r1=711459&r2=711460&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java (original)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java Tue Nov  4 15:03:22 2008
@@ -128,44 +128,6 @@
     }
 
     /**
-     * Get the JMS destination used by this service
-     *
-     * @param service the Axis Service
-     * @return the name of the JMS destination
-     */
-    public static String getJNDIDestinationNameForService(AxisService service) {
-        Parameter destParam = service.getParameter(JMSConstants.DEST_PARAM);
-        if (destParam != null) {
-            return (String) destParam.getValue();
-        } else {
-            return service.getName();
-        }
-    }
-
-    /**
-     * Get the JMS destination type of this service
-     *
-     * @param service the Axis Service
-     * @return the name of the JMS destination
-     */
-    public static String getDestinationTypeForService(AxisService service) {
-        Parameter destTypeParam = service.getParameter(JMSConstants.DEST_PARAM_TYPE);
-        if (destTypeParam != null) {
-            String paramValue = (String) destTypeParam.getValue();
-            if(JMSConstants.DESTINATION_TYPE_QUEUE.equals(paramValue) ||
-                    JMSConstants.DESTINATION_TYPE_TOPIC.equals(paramValue) )  {
-                return paramValue;
-            } else {
-               handleException("Invalid destinaton type value " + paramValue);
-               return null;
-            }
-        } else {
-            log.debug("JMS destination type not given. default queue");
-            return JMSConstants.DESTINATION_TYPE_QUEUE;
-        }
-    }
-    
-    /**
      * Extract connection factory properties from a given URL
      *
      * @param url a JMS URL of the form jms:/<destination>?[<key>=<value>&]*