1 16 17 package org.apache.axis.components.jms; 18 19 import java.util.HashMap ; 20 import java.util.Iterator ; 21 import java.util.Map ; 22 23 import javax.jms.InvalidDestinationException ; 24 import javax.jms.JMSException ; 25 import javax.jms.JMSSecurityException ; 26 import javax.jms.Message ; 27 import javax.jms.Queue ; 28 import javax.jms.QueueConnectionFactory ; 29 import javax.jms.QueueSession ; 30 import javax.jms.Topic ; 31 import javax.jms.TopicConnectionFactory ; 32 import javax.jms.TopicSession ; 33 34 import org.apache.axis.MessageContext; 35 import org.apache.axis.client.Call; 36 import org.apache.axis.transport.jms.JMSConstants; 37 import org.apache.axis.transport.jms.JMSURLHelper; 38 39 46 public abstract class JMSVendorAdapter 47 { 48 public static final int SEND_ACTION = 0; 49 public static final int CONNECT_ACTION = 1; 50 public static final int SUBSCRIBE_ACTION = 2; 51 public static final int RECEIVE_ACTION = 3; 52 public static final int ON_EXCEPTION_ACTION = 4; 53 54 public abstract QueueConnectionFactory getQueueConnectionFactory(HashMap cfProps) 55 throws Exception ; 56 public abstract TopicConnectionFactory getTopicConnectionFactory(HashMap cfProps) 57 throws Exception ; 58 59 public abstract void addVendorConnectionFactoryProperties(JMSURLHelper jmsurl, HashMap cfProps); 61 62 public abstract boolean isMatchingConnectionFactory(javax.jms.ConnectionFactory cf, JMSURLHelper jmsurl, HashMap cfProps); 64 65 public String getVendorId() 67 { 68 String name = this.getClass().getName(); 69 70 if (name.endsWith(JMSConstants.ADAPTER_POSTFIX)) 72 { 73 int index = name.lastIndexOf(JMSConstants.ADAPTER_POSTFIX); 74 name = name.substring(0,index); 75 } 76 77 int index = name.lastIndexOf("."); 79 if (index > 0) 80 name = name.substring(index+1); 81 82 return name; 83 } 84 85 93 public HashMap getJMSConnectorProperties(JMSURLHelper jmsurl) 94 { 95 HashMap connectorProps = new HashMap (); 96 97 connectorProps.put(JMSConstants.JMS_URL, jmsurl); 99 100 String clientID = jmsurl.getPropertyValue(JMSConstants._CLIENT_ID); 102 if (clientID != null) 103 connectorProps.put(JMSConstants.CLIENT_ID, clientID); 104 105 String connectRetryInterval = jmsurl.getPropertyValue(JMSConstants._CONNECT_RETRY_INTERVAL); 107 if (connectRetryInterval != null) 108 connectorProps.put(JMSConstants.CONNECT_RETRY_INTERVAL, connectRetryInterval); 109 110 String interactRetryInterval = jmsurl.getPropertyValue(JMSConstants._INTERACT_RETRY_INTERVAL); 112 if (interactRetryInterval != null) 113 connectorProps.put(JMSConstants.INTERACT_RETRY_INTERVAL, interactRetryInterval); 114 115 String domain = jmsurl.getPropertyValue(JMSConstants._DOMAIN); 117 if (domain != null) 118 connectorProps.put(JMSConstants.DOMAIN, domain); 119 120 String numRetries = jmsurl.getPropertyValue(JMSConstants._NUM_RETRIES); 122 if (numRetries != null) 123 connectorProps.put(JMSConstants.NUM_RETRIES, numRetries); 124 125 String numSessions = jmsurl.getPropertyValue(JMSConstants._NUM_SESSIONS); 127 if (numSessions != null) 128 connectorProps.put(JMSConstants.NUM_SESSIONS, numSessions); 129 130 String timeoutTime = jmsurl.getPropertyValue(JMSConstants._TIMEOUT_TIME); 132 if (timeoutTime != null) 133 connectorProps.put(JMSConstants.TIMEOUT_TIME, timeoutTime); 134 135 return connectorProps; 136 } 137 138 146 public HashMap getJMSConnectionFactoryProperties(JMSURLHelper jmsurl) 147 { 148 HashMap cfProps = new HashMap (); 149 150 cfProps.put(JMSConstants.JMS_URL, jmsurl); 153 154 String domain = jmsurl.getPropertyValue(JMSConstants._DOMAIN); 156 if (domain != null) 157 cfProps.put(JMSConstants.DOMAIN, domain); 158 159 addVendorConnectionFactoryProperties(jmsurl, cfProps); 161 162 return cfProps; 163 } 164 165 public Queue getQueue(QueueSession session, String name) 166 throws Exception 167 { 168 return session.createQueue(name); 169 } 170 171 public Topic getTopic(TopicSession session, String name) 172 throws Exception 173 { 174 return session.createTopic(name); 175 } 176 177 public boolean isRecoverable(Throwable thrown, int action) 178 { 179 if(thrown instanceof RuntimeException || 180 thrown instanceof Error || 181 thrown instanceof JMSSecurityException || 182 thrown instanceof InvalidDestinationException ) 183 return false; 184 if(action == ON_EXCEPTION_ACTION) 185 return false; 186 return true; 187 } 188 189 public void setProperties(Message message, HashMap props) 190 throws JMSException 191 { 192 Iterator iter = props.keySet().iterator(); 193 while (iter.hasNext()) 194 { 195 String key = (String )iter.next(); 196 String value = (String )props.get(key); 197 198 message.setStringProperty(key, value); 199 } 200 } 201 202 208 public void setupMessageContext(MessageContext context, 209 Call call, 210 JMSURLHelper jmsurl) 211 { 212 Object tmp = null; 213 214 String jmsurlDestination = null; 215 if (jmsurl != null) 216 jmsurlDestination = jmsurl.getDestination(); 217 if (jmsurlDestination != null) 218 context.setProperty(JMSConstants.DESTINATION, jmsurlDestination); 219 else 220 { 221 tmp = call.getProperty(JMSConstants.DESTINATION); 222 if (tmp != null && tmp instanceof String ) 223 context.setProperty(JMSConstants.DESTINATION, tmp); 224 else 225 context.removeProperty(JMSConstants.DESTINATION); 226 } 227 228 String delivMode = null; 229 if (jmsurl != null) 230 delivMode = jmsurl.getPropertyValue(JMSConstants._DELIVERY_MODE); 231 if (delivMode != null) 232 { 233 int mode = JMSConstants.DEFAULT_DELIVERY_MODE; 234 if (delivMode.equalsIgnoreCase(JMSConstants.DELIVERY_MODE_PERSISTENT)) 235 mode = javax.jms.DeliveryMode.PERSISTENT; 236 else if (delivMode.equalsIgnoreCase(JMSConstants.DELIVERY_MODE_NONPERSISTENT)) 237 mode = javax.jms.DeliveryMode.NON_PERSISTENT; 238 context.setProperty(JMSConstants.DELIVERY_MODE, new Integer (mode)); 239 } 240 else 241 { 242 tmp = call.getProperty(JMSConstants.DELIVERY_MODE); 243 if(tmp != null && tmp instanceof Integer ) 244 context.setProperty(JMSConstants.DELIVERY_MODE, tmp); 245 else 246 context.removeProperty(JMSConstants.DELIVERY_MODE); 247 } 248 249 String prio = null; 250 if (jmsurl != null) 251 prio = jmsurl.getPropertyValue(JMSConstants._PRIORITY); 252 if (prio != null) 253 context.setProperty(JMSConstants.PRIORITY, Integer.valueOf(prio)); 254 else 255 { 256 tmp = call.getProperty(JMSConstants.PRIORITY); 257 if(tmp != null && tmp instanceof Integer ) 258 context.setProperty(JMSConstants.PRIORITY, tmp); 259 else 260 context.removeProperty(JMSConstants.PRIORITY); 261 } 262 263 String ttl = null; 264 if (jmsurl != null) 265 ttl = jmsurl.getPropertyValue(JMSConstants._TIME_TO_LIVE); 266 if (ttl != null) 267 context.setProperty(JMSConstants.TIME_TO_LIVE, Long.valueOf(ttl)); 268 else 269 { 270 tmp = call.getProperty(JMSConstants.TIME_TO_LIVE); 271 if(tmp != null && tmp instanceof Long ) 272 context.setProperty(JMSConstants.TIME_TO_LIVE, tmp); 273 else 274 context.removeProperty(JMSConstants.TIME_TO_LIVE); 275 } 276 277 String wait = null; 278 if (jmsurl != null) 279 wait = jmsurl.getPropertyValue(JMSConstants._WAIT_FOR_RESPONSE); 280 if (wait != null) 281 context.setProperty(JMSConstants.WAIT_FOR_RESPONSE, Boolean.valueOf(wait)); 282 else 283 { 284 tmp = call.getProperty(JMSConstants.WAIT_FOR_RESPONSE); 285 if(tmp != null && tmp instanceof Boolean ) 286 context.setProperty(JMSConstants.WAIT_FOR_RESPONSE, tmp); 287 else 288 context.removeProperty(JMSConstants.WAIT_FOR_RESPONSE); 289 } 290 setupApplicationProperties(context, call, jmsurl); 291 } 292 293 public void setupApplicationProperties(MessageContext context, 294 Call call, 295 JMSURLHelper jmsurl) 296 { 297 Map appProps = new HashMap (); 299 if (jmsurl != null && jmsurl.getApplicationProperties() != null) { 300 for(Iterator itr=jmsurl.getApplicationProperties().iterator(); 301 itr.hasNext();) { 302 String name = (String )itr.next(); 303 appProps.put(name,jmsurl.getPropertyValue(name)); 304 } 305 } 306 307 Map ctxProps = 309 (Map )context.getProperty(JMSConstants.JMS_APPLICATION_MSG_PROPS); 310 if (ctxProps != null) { 311 appProps.putAll(ctxProps); 312 } 313 314 Map callProps = 316 (Map )call.getProperty(JMSConstants.JMS_APPLICATION_MSG_PROPS); 317 if (callProps != null) { 318 appProps.putAll(callProps); 319 } 320 321 context.setProperty(JMSConstants.JMS_APPLICATION_MSG_PROPS,appProps); 323 } 324 } | Popular Tags |