1 17 package org.apache.servicemix.jms; 18 19 import java.io.InputStream ; 20 import java.lang.reflect.Constructor ; 21 import java.util.Iterator ; 22 import java.util.Properties ; 23 24 import javax.jbi.component.ComponentLifeCycle; 25 import javax.jbi.servicedesc.ServiceEndpoint; 26 import javax.jms.ConnectionFactory ; 27 import javax.jms.Destination ; 28 import javax.resource.spi.ActivationSpec ; 29 import javax.resource.spi.BootstrapContext ; 30 import javax.resource.spi.ResourceAdapter ; 31 import javax.wsdl.Definition; 32 import javax.wsdl.Port; 33 import javax.wsdl.Service; 34 35 import org.apache.servicemix.common.ExchangeProcessor; 36 import org.apache.servicemix.jbi.security.auth.AuthenticationService; 37 import org.apache.servicemix.jbi.security.keystore.KeystoreManager; 38 import org.apache.servicemix.soap.SoapEndpoint; 39 40 48 public class JmsEndpoint extends SoapEndpoint { 49 50 protected String initialContextFactory; 54 protected String jndiProviderURL; 55 protected String destinationStyle; 56 protected String jndiConnectionFactoryName; 57 protected String jndiDestinationName; 58 protected String jmsProviderDestinationName; 59 protected ConnectionFactory connectionFactory; 63 protected Destination destination; 64 protected String processorName; 65 protected ResourceAdapter resourceAdapter; 69 protected ActivationSpec activationSpec; 70 protected BootstrapContext bootstrapContext; 71 protected boolean synchronous; 72 protected boolean needJavaIdentifiers; 74 75 80 public BootstrapContext getBootstrapContext() { 81 return bootstrapContext; 82 } 83 84 87 public void setBootstrapContext(BootstrapContext bootstrapContext) { 88 this.bootstrapContext = bootstrapContext; 89 } 90 91 98 public boolean isSynchronous() { 99 return synchronous; 100 } 101 102 105 public void setSynchronous(boolean synchronous) { 106 this.synchronous = synchronous; 107 } 108 109 114 public ActivationSpec getActivationSpec() { 115 return activationSpec; 116 } 117 118 121 public void setActivationSpec(ActivationSpec activationSpec) { 122 this.activationSpec = activationSpec; 123 } 124 125 130 public ResourceAdapter getResourceAdapter() { 131 return resourceAdapter; 132 } 133 134 137 public void setResourceAdapter(ResourceAdapter resourceAdapter) { 138 this.resourceAdapter = resourceAdapter; 139 } 140 141 146 public String getInitialContextFactory() { 147 return initialContextFactory; 148 } 149 150 153 public void setInitialContextFactory(String initialContextFactory) { 154 this.initialContextFactory = initialContextFactory; 155 } 156 157 166 public String getJmsProviderDestinationName() { 167 return jmsProviderDestinationName; 168 } 169 170 173 public void setJmsProviderDestinationName(String jmsProviderDestinationName) { 174 this.jmsProviderDestinationName = jmsProviderDestinationName; 175 } 176 177 183 public String getJndiConnectionFactoryName() { 184 return jndiConnectionFactoryName; 185 } 186 187 190 public void setJndiConnectionFactoryName(String jndiConnectionFactoryName) { 191 this.jndiConnectionFactoryName = jndiConnectionFactoryName; 192 } 193 194 200 public String getJndiDestinationName() { 201 return jndiDestinationName; 202 } 203 204 207 public void setJndiDestinationName(String jndiDestinationName) { 208 this.jndiDestinationName = jndiDestinationName; 209 } 210 211 216 public String getJndiProviderURL() { 217 return jndiProviderURL; 218 } 219 220 223 public void setJndiProviderURL(String jndiProviderURL) { 224 this.jndiProviderURL = jndiProviderURL; 225 } 226 227 233 public String getDestinationStyle() { 234 return destinationStyle; 235 } 236 237 240 public void setDestinationStyle(String destinationStyle) { 241 this.destinationStyle = destinationStyle; 242 } 243 244 249 public ConnectionFactory getConnectionFactory() { 250 return connectionFactory; 251 } 252 253 256 public void setConnectionFactory(ConnectionFactory connectionFactory) { 257 this.connectionFactory = connectionFactory; 258 } 259 260 265 public Destination getDestination() { 266 return destination; 267 } 268 269 272 public void setDestination(Destination destination) { 273 this.destination = destination; 274 } 275 276 279 public boolean isNeedJavaIdentifiers() { 280 return needJavaIdentifiers; 281 } 282 283 286 public void setNeedJavaIdentifiers(boolean needJavaIdentifiers) { 287 this.needJavaIdentifiers = needJavaIdentifiers; 288 } 289 290 297 public void setRoleAsString(String role) { 298 super.setRoleAsString(role); 299 } 300 301 protected ExchangeProcessor createProviderProcessor() { 302 return createProcessor("provider"); 303 } 304 305 protected ExchangeProcessor createConsumerProcessor() { 306 return createProcessor("consumer"); 307 } 308 309 protected ExchangeProcessor createProcessor(String type) { 310 try { 311 String procName = processorName; 312 if (processorName == null) { 313 JmsLifeCycle lf = (JmsLifeCycle) getServiceUnit().getComponent().getLifeCycle(); 314 procName = lf.getConfiguration().getProcessorName(); 315 } 316 String uri = "META-INF/services/org/apache/servicemix/jms/" + procName; 317 InputStream in = loadResource(uri); 318 Properties props = new Properties (); 319 props.load(in); 320 String className = props.getProperty(type); 321 Class cl = loadClass(className); 322 Constructor cns = cl.getConstructor(new Class [] { getClass() }); 323 return (ExchangeProcessor) cns.newInstance(new Object [] { this }); 324 } catch (Exception e) { 325 throw new RuntimeException ("Could not create processor of type " + type + " and name " + processorName, e); 326 } 327 } 328 329 333 protected Class loadClass(String name) throws ClassNotFoundException { 334 ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); 335 if (contextClassLoader != null) { 336 try { 337 return contextClassLoader.loadClass(name); 338 } 339 catch (ClassNotFoundException e) { 340 } 341 } 342 return getClass().getClassLoader().loadClass(name); 343 } 344 345 348 protected InputStream loadResource(String uri) { 349 InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(uri); 351 if (in == null) { 352 in = getClass().getClassLoader().getResourceAsStream(uri); 353 if (in == null) { 354 logger.debug("Could not find resource: " + uri); 355 } 356 } 357 return in; 358 } 359 360 protected ServiceEndpoint createExternalEndpoint() { 361 return new JmsExternalEndpoint(this); 362 } 363 364 protected void overrideDefinition(Definition def) { 365 Service svc = null; 366 Port port = null; 367 if (targetService != null && targetEndpoint != null) { 368 svc = def.getService(targetService); 369 port = (svc != null) ? svc.getPort(targetEndpoint) : null; 370 } else if (targetService != null) { 371 svc = def.getService(targetService); 372 if (svc != null) { 373 Iterator it = svc.getPorts().values().iterator(); 374 port = (it.hasNext()) ? (Port) it.next() : null; 375 } 376 } else if (targetInterfaceName != null) { 377 Iterator it = def.getServices().values().iterator(); 378 svc = it .hasNext() ? (Service) it.next() : null; 379 if (svc != null) { 380 it = svc.getPorts().values().iterator(); 381 port = (it.hasNext()) ? (Port) it.next() : null; 382 } 383 } else { 384 svc = def.getService(service); 385 port = (svc != null) ? svc.getPort(endpoint) : null; 386 } 387 if (port != null) { 388 port.getExtensibilityElements().clear(); 389 402 svc.getPorts().clear(); 404 svc.addPort(port); 405 definition = def; 406 } 407 } 408 409 public String toString() { 410 return "JMSEndpoint[service: " + service + ", " + 411 "endpoint: " + endpoint + ", " + 412 "address: " + jndiDestinationName + "(" + destinationStyle + "), " + 413 "soap: " + soap + "]"; 414 } 415 416 427 public String getProcessorName() { 428 return processorName; 429 } 430 431 434 public void setProcessorName(String processorName) { 435 this.processorName = processorName; 436 } 437 438 public JmsConfiguration getConfiguration() { 439 JmsLifeCycle lifeCycle = (JmsLifeCycle) getServiceUnit().getComponent().getLifeCycle(); 440 return lifeCycle.getConfiguration(); 441 } 442 443 public AuthenticationService getAuthenticationService() { 444 ComponentLifeCycle lf = getServiceUnit().getComponent().getLifeCycle(); 445 return ((JmsLifeCycle) lf).getAuthenticationService(); 446 } 447 448 public KeystoreManager getKeystoreManager() { 449 ComponentLifeCycle lf = getServiceUnit().getComponent().getLifeCycle(); 450 return ((JmsLifeCycle) lf).getKeystoreManager(); 451 } 452 453 } | Popular Tags |