1 16 17 package org.apache.axis.components.jms; 18 19 import org.apache.axis.MessageContext; 20 import org.apache.axis.client.Call; 21 import org.apache.axis.transport.jms.JMSConnector; 22 import org.apache.axis.transport.jms.JMSConnectorFactory; 23 import org.apache.axis.transport.jms.JMSURLHelper; 24 25 import progress.message.client.ENetworkFailure; 26 import progress.message.client.EUserAlreadyConnected; 27 import progress.message.jclient.ErrorCodes; 28 29 import javax.jms.ConnectionFactory ; 30 import javax.jms.JMSException ; 31 import javax.jms.QueueConnectionFactory ; 32 import javax.jms.TopicConnectionFactory ; 33 import java.util.HashMap ; 34 import java.util.Iterator ; 35 36 43 public class SonicMQVendorAdapter extends BeanVendorAdapter 44 { 45 private final static String QCF_CLASS = 46 "progress.message.jclient.QueueConnectionFactory"; 47 48 private final static String TCF_CLASS = 49 "progress.message.jclient.TopicConnectionFactory"; 50 51 59 public final static String BROKER_URL = "brokerURL"; 60 61 69 public final static String DEFAULT_USERNAME = "defaultUser"; 70 71 79 public final static String DEFAULT_PASSWORD = "defaultPassword"; 80 87 public final static String PING_INTERVAL = "pingIntervalLong"; 88 95 public final static String RECONNECT_INTERVAL = "reconnectIntervalInteger"; 96 103 public final static String RECONNECT_TIMEOUT = "reconnectTimeoutInteger"; 104 111 public final static String CONNECT_ID = "connectID"; 112 119 public final static String CONNECTION_URLS = "connectionURLs"; 120 127 public final static String LOAD_BALANCING = "loadBalancingBoolean"; 128 135 public final static String MONITOR_INTERVAL = "monitorInterval"; 136 143 public final static String PERSISTENT_DELIVERY = "persistentDeliveryBoolean"; 144 151 public final static String SEQUENTIAL = "sequentialBoolean"; 152 153 160 public final static String PREFETCH_COUNT = "prefetchCountInteger"; 161 168 public final static String PREFETCH_THRESHOLD = "prefetchThresholdInteger"; 169 176 public final static String SELECTOR_AT_BROKER = "selectorAtBroker"; 177 178 public QueueConnectionFactory getQueueConnectionFactory(HashMap cfConfig) 179 throws Exception 180 { 181 cfConfig = (HashMap )cfConfig.clone(); 182 cfConfig.put(CONNECTION_FACTORY_CLASS, QCF_CLASS); 183 return super.getQueueConnectionFactory(cfConfig); 184 } 185 186 public TopicConnectionFactory getTopicConnectionFactory(HashMap cfConfig) 187 throws Exception 188 { 189 cfConfig = (HashMap )cfConfig.clone(); 190 cfConfig.put(CONNECTION_FACTORY_CLASS, TCF_CLASS); 191 return super.getTopicConnectionFactory(cfConfig); 192 } 193 194 200 public void addVendorConnectionFactoryProperties(JMSURLHelper jmsurl, HashMap cfProps) 201 { 202 if (jmsurl.getPropertyValue(BROKER_URL) != null) 203 cfProps.put(BROKER_URL, jmsurl.getPropertyValue(BROKER_URL)); 204 205 if (jmsurl.getPropertyValue(DEFAULT_USERNAME) != null) 206 cfProps.put(DEFAULT_USERNAME, jmsurl.getPropertyValue(DEFAULT_USERNAME)); 207 208 if (jmsurl.getPropertyValue(DEFAULT_PASSWORD) != null) 209 cfProps.put(DEFAULT_PASSWORD, jmsurl.getPropertyValue(DEFAULT_PASSWORD)); 210 211 if (jmsurl.getPropertyValue(PING_INTERVAL) != null) 212 cfProps.put(PING_INTERVAL, jmsurl.getPropertyValue(PING_INTERVAL)); 213 214 if (jmsurl.getPropertyValue(RECONNECT_INTERVAL) != null) 215 cfProps.put(RECONNECT_INTERVAL, jmsurl.getPropertyValue(RECONNECT_INTERVAL)); 216 217 if (jmsurl.getPropertyValue(RECONNECT_TIMEOUT) != null) 218 cfProps.put(RECONNECT_TIMEOUT, jmsurl.getPropertyValue(RECONNECT_TIMEOUT)); 219 220 if (jmsurl.getPropertyValue(CONNECT_ID) != null) 221 cfProps.put(CONNECT_ID, jmsurl.getPropertyValue(CONNECT_ID)); 222 223 if (jmsurl.getPropertyValue(CONNECTION_URLS) != null) 224 cfProps.put(CONNECTION_URLS, jmsurl.getPropertyValue(CONNECTION_URLS)); 225 226 if (jmsurl.getPropertyValue(LOAD_BALANCING) != null) 227 cfProps.put(LOAD_BALANCING, jmsurl.getPropertyValue(LOAD_BALANCING)); 228 229 if (jmsurl.getPropertyValue(MONITOR_INTERVAL) != null) 230 cfProps.put(MONITOR_INTERVAL, jmsurl.getPropertyValue(MONITOR_INTERVAL)); 231 232 if (jmsurl.getPropertyValue(PERSISTENT_DELIVERY) != null) 233 cfProps.put(PERSISTENT_DELIVERY, jmsurl.getPropertyValue(PERSISTENT_DELIVERY)); 234 235 if (jmsurl.getPropertyValue(SEQUENTIAL) != null) 236 cfProps.put(SEQUENTIAL, jmsurl.getPropertyValue(SEQUENTIAL)); 237 238 if (jmsurl.getPropertyValue(PREFETCH_COUNT) != null) 239 cfProps.put(PREFETCH_COUNT, jmsurl.getPropertyValue(PREFETCH_COUNT)); 240 241 if (jmsurl.getPropertyValue(PREFETCH_THRESHOLD) != null) 242 cfProps.put(PREFETCH_THRESHOLD, jmsurl.getPropertyValue(PREFETCH_THRESHOLD)); 243 244 if (jmsurl.getPropertyValue(SELECTOR_AT_BROKER) != null) 245 cfProps.put(SELECTOR_AT_BROKER, jmsurl.getPropertyValue(SELECTOR_AT_BROKER)); 246 } 247 248 257 public boolean isMatchingConnectionFactory(javax.jms.ConnectionFactory cf, 258 JMSURLHelper jmsurl, 259 HashMap cfProps) 260 { 261 String brokerURL = null; 262 String connectionURLs = null; 263 boolean loadBalancing = false; 264 boolean sequential = false; 265 266 if (cf instanceof progress.message.jclient.QueueConnectionFactory) 267 { 268 progress.message.jclient.QueueConnectionFactory qcf = 269 (progress.message.jclient.QueueConnectionFactory)cf; 270 271 brokerURL = qcf.getBrokerURL(); 273 connectionURLs = qcf.getConnectionURLs(); 274 loadBalancing = qcf.getLoadBalancing(); 275 sequential = qcf.getSequential(); 276 } 277 else if (cf instanceof progress.message.jclient.TopicConnectionFactory) 278 { 279 progress.message.jclient.TopicConnectionFactory tcf = 280 (progress.message.jclient.TopicConnectionFactory)cf; 281 282 brokerURL = tcf.getBrokerURL(); 284 connectionURLs = tcf.getConnectionURLs(); 285 loadBalancing = tcf.getLoadBalancing(); 286 sequential = tcf.getSequential(); 287 } 288 289 String propertyBrokerURL = (String )cfProps.get(BROKER_URL); 291 if (!brokerURL.equals(propertyBrokerURL)) 292 return false; 293 294 String propertyConnectionURLs = (String )cfProps.get(CONNECTION_URLS); 296 if ((connectionURLs != null) && (propertyConnectionURLs != null)) 297 { 298 if (!connectionURLs.equalsIgnoreCase(propertyConnectionURLs)) 299 return false; 300 301 String tmpSequential = (String )cfProps.get(SEQUENTIAL); 303 boolean propertySequential = true; 304 if (tmpSequential != null) 305 propertySequential = Boolean.getBoolean(tmpSequential); 306 if (sequential != propertySequential) 307 return false; 308 } 309 else if ((connectionURLs != null) || (propertyConnectionURLs != null)) 310 return false; 311 312 String tmpLoadBalancing = (String )cfProps.get(LOAD_BALANCING); 314 boolean propertyLoadBalancing = false; 315 if (tmpLoadBalancing != null) 316 propertyLoadBalancing = Boolean.getBoolean(tmpLoadBalancing); 317 if (loadBalancing != propertyLoadBalancing) 318 return false; 319 320 return true; 321 } 322 323 public boolean isRecoverable(Throwable thrown, int action) 324 { 325 if(action != ON_EXCEPTION_ACTION && !super.isRecoverable(thrown, action)) 328 return false; 329 330 if(!(thrown instanceof JMSException )) 331 return true; 332 333 JMSException jmse = (JMSException )thrown; 334 switch(action) 335 { 336 case CONNECT_ACTION: 337 if(isNetworkFailure(jmse)) 338 return false; 339 break; 340 case SUBSCRIBE_ACTION: 341 342 if(isQueueMissing(jmse) || isAnotherSubscriberConnected(jmse)) 343 return false; 344 break; 345 346 case ON_EXCEPTION_ACTION: 347 if(isConnectionDropped(jmse)) 348 return false; 349 break; 350 351 } 352 353 return true; 354 } 355 356 public boolean isConnectionDropped(JMSException jmse) 357 { 358 return ErrorCodes.testException(jmse, ErrorCodes.ERR_CONNECTION_DROPPED); 359 } 360 361 private boolean isQueueMissing(JMSException jmse) 362 { 363 String message = jmse.getMessage(); 364 if(message != null && message.startsWith("Queue not found")) 365 { 366 return true; 367 } 368 return false; 369 } 370 371 private boolean isAnotherSubscriberConnected(JMSException jmse) 372 { 373 Exception linkedException = jmse.getLinkedException(); 374 if(linkedException != null && 375 linkedException instanceof EUserAlreadyConnected) 376 { 377 return true; 378 } 379 return false; 380 } 381 382 private boolean isNetworkFailure(JMSException jmse) 383 { 384 Exception linkedException = jmse.getLinkedException(); 385 if(linkedException != null && 386 linkedException instanceof ENetworkFailure) 387 { 388 return true; 389 } 390 return false; 391 } 392 } | Popular Tags |