This is an automated email from the ASF dual-hosted git repository. billblough pushed a commit to branch transport in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-transports.git
commit ef86ab6ee1f6bdc74ba63775518f96fcb42b4221 Author: Ruwan Linton <ru...@apache.org> AuthorDate: Mon Oct 12 05:09:35 2009 +0000 Refactoring the getDestination of the JMS transport (half way through WSCOMMONS-468) --- .../axis2/transport/jms/JMSOutTransportInfo.java | 106 ++++++++------------- .../org/apache/axis2/transport/jms/JMSUtils.java | 33 +++++++ 2 files changed, 72 insertions(+), 67 deletions(-) diff --git a/1.0.0/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSOutTransportInfo.java b/1.0.0/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSOutTransportInfo.java index edad78a..41c892f 100644 --- a/1.0.0/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSOutTransportInfo.java +++ b/1.0.0/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSOutTransportInfo.java @@ -20,23 +20,9 @@ import org.apache.axis2.transport.base.BaseUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.QueueConnection; -import javax.jms.QueueConnectionFactory; -import javax.jms.QueueSession; -import javax.jms.Session; -import javax.jms.Topic; -import javax.jms.TopicConnection; -import javax.jms.TopicConnectionFactory; -import javax.jms.TopicSession; +import javax.jms.*; import javax.naming.Context; import javax.naming.InitialContext; -import javax.naming.NameNotFoundException; import javax.naming.NamingException; import java.util.Hashtable; @@ -88,7 +74,7 @@ public class JMSOutTransportInfo implements OutTransportInfo { * * @param jmsConnectionFactory the JMS connection factory * @param dest the destination - * @param contentTypeProperty + * @param contentTypeProperty the content type */ JMSOutTransportInfo(JMSConnectionFactory jmsConnectionFactory, Destination dest, String contentTypeProperty) { @@ -176,20 +162,11 @@ public class JMSOutTransportInfo implements OutTransportInfo { */ private Destination getDestination(Context context, String url) { String destinationName = JMSUtils.getDestination(url); - try { - return JMSUtils.lookup(context, Destination.class, destinationName); - } catch (NameNotFoundException e) { - try { - return JMSUtils.lookup(context, Destination.class, - (JMSConstants.DESTINATION_TYPE_TOPIC.equals(destinationType) ? - "dynamicTopics/" : "dynamicQueues/") + destinationName); - } catch (NamingException x) { - handleException("Cannot locate destination : " + destinationName + " using " + url); - } - } catch (NamingException e) { - handleException("Cannot locate destination : " + destinationName + " using " + url, e); + if (log.isDebugEnabled()) { + log.debug("Lookup the JMS destination " + destinationName + " of type " + + destinationType + " extracted from the URL " + url); } - return null; + return JMSUtils.lookupDestination(context, destinationName, destinationType); } /** @@ -201,21 +178,11 @@ public class JMSOutTransportInfo implements OutTransportInfo { */ private Destination getReplyDestination(Context context, String url) { String replyDestinationName = properties.get(JMSConstants.PARAM_REPLY_DESTINATION); - if(replyDestinationName == null) { - return null; - } - - try { - return JMSUtils.lookup(context, Destination.class, replyDestinationName); - } catch (NameNotFoundException e) { - if (log.isDebugEnabled()) { - log.debug("Cannot locate destination : " + replyDestinationName + " using " + url); - } - } catch (NamingException e) { - handleException("Cannot locate destination : " + replyDestinationName + " using " + url, e); + if (log.isDebugEnabled()) { + log.debug("Lookup the JMS destination " + replyDestinationName + " of type " + + replyDestinationType + " extracted from the URL " + url); } - - return null; + return JMSUtils.lookupDestination(context, replyDestinationName, replyDestinationType); } /** @@ -224,17 +191,12 @@ public class JMSOutTransportInfo implements OutTransportInfo { * @return Destination for the JNDI name passed */ public Destination getReplyDestination(String replyDest) { - try { - return JMSUtils.lookup(jmsConnectionFactory.getContext(), Destination.class, - replyDest); - } catch (NameNotFoundException e) { - if (log.isDebugEnabled()) { - log.debug("Cannot locate reply destination : " + replyDest, e); - } - } catch (NamingException e) { - handleException("Cannot locate reply destination : " + replyDest, e); + if (log.isDebugEnabled()) { + log.debug("Lookup the JMS destination " + replyDest + " of type " + + replyDestinationType); } - return null; + return JMSUtils.lookupDestination( + jmsConnectionFactory.getContext(), replyDest, replyDestinationType); } @@ -360,26 +322,36 @@ public class JMSOutTransportInfo implements OutTransportInfo { } } - if (connection == null && jmsConnectionFactory != null) { - connection = jmsConnectionFactory.getConnection(); + if (connection == null) { + connection = jmsConnectionFactory != null ? jmsConnectionFactory.getConnection() : null; } Session session = null; MessageProducer producer = null; - if (destType == JMSConstants.QUEUE) { - session = ((QueueConnection) connection). - createQueueSession(false, Session.AUTO_ACKNOWLEDGE); - producer = ((QueueSession) session).createSender((Queue) destination); - } else { - session = ((TopicConnection) connection). - createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - producer = ((TopicSession) session).createPublisher((Topic) destination); + if (connection != null) { + if (destType == JMSConstants.QUEUE) { + session = ((QueueConnection) connection). + createQueueSession(false, Session.AUTO_ACKNOWLEDGE); + producer = ((QueueSession) session).createSender((Queue) destination); + } else { + session = ((TopicConnection) connection). + createTopicSession(false, Session.AUTO_ACKNOWLEDGE); + producer = ((TopicSession) session).createPublisher((Topic) destination); + } } - return new JMSMessageSender(connection, session, producer, - destination, (jmsConnectionFactory == null ? - JMSConstants.CACHE_NONE : jmsConnectionFactory.getCacheLevel()), false, - destType == -1 ? null : destType == JMSConstants.QUEUE ? Boolean.TRUE : Boolean.FALSE); + return new JMSMessageSender( + connection, + session, + producer, + destination, + jmsConnectionFactory == null ? + JMSConstants.CACHE_NONE : jmsConnectionFactory.getCacheLevel(), + false, + destType == -1 ? + null : destType == JMSConstants.QUEUE ? Boolean.TRUE : Boolean.FALSE + ); + } } diff --git a/1.0.0/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java b/1.0.0/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java index 16e9423..eae3525 100644 --- a/1.0.0/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java +++ b/1.0.0/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java @@ -40,6 +40,7 @@ import javax.mail.internet.ParseException; import javax.naming.Context; import javax.naming.NamingException; import javax.naming.Reference; +import javax.naming.NameNotFoundException; import java.lang.reflect.Method; import java.util.*; @@ -687,4 +688,36 @@ public class JMSUtils extends BaseUtils { return "Generic"; } } + + /** + * Return the JMS destination with the given destination name looked up from the context + * + * @param context the Context to lookup + * @param destinationName name of the destination to be looked up + * @param destinationType type of the destination to be looked up + * @return the JMS destination, or null if it does not exist + */ + public static Destination lookupDestination(Context context, String destinationName, + String destinationType) { + + if (destinationName == null) { + return null; + } + + try { + return JMSUtils.lookup(context, Destination.class, destinationName); + } catch (NameNotFoundException e) { + try { + return JMSUtils.lookup(context, Destination.class, + (JMSConstants.DESTINATION_TYPE_TOPIC.equals(destinationType) ? + "dynamicTopics/" : "dynamicQueues/") + destinationName); + } catch (NamingException x) { + handleException("Cannot locate destination : " + destinationName); + } + } catch (NamingException e) { + handleException("Cannot locate destination : " + destinationName, e); + } + + return null; + } }