1 17 package org.apache.servicemix.jms; 18 19 import java.net.URI ; 20 import java.util.Map ; 21 22 import javax.jbi.messaging.MessageExchange; 23 import javax.jbi.servicedesc.ServiceEndpoint; 24 import javax.xml.namespace.QName ; 25 26 import org.apache.activemq.util.IntrospectionSupport; 27 import org.apache.activemq.util.URISupport; 28 import org.apache.servicemix.common.BaseComponent; 29 import org.apache.servicemix.common.BaseLifeCycle; 30 import org.apache.servicemix.common.Endpoint; 31 import org.apache.servicemix.common.ServiceUnit; 32 import org.apache.servicemix.jbi.security.auth.AuthenticationService; 33 import org.apache.servicemix.jbi.security.auth.impl.JAASAuthenticationService; 34 import org.apache.servicemix.jbi.security.keystore.KeystoreManager; 35 36 public class JmsLifeCycle extends BaseLifeCycle { 37 38 protected JmsConfiguration configuration; 39 40 public JmsLifeCycle(BaseComponent component) { 41 super(component); 42 configuration = new JmsConfiguration(); 43 } 44 45 48 protected Object getExtensionMBean() throws Exception { 49 return configuration; 50 } 51 52 55 protected void doInit() throws Exception { 56 super.doInit(); 57 configuration.setRootDir(context.getWorkspaceRoot()); 58 configuration.load(); 59 if (configuration.getKeystoreManager() == null) { 61 try { 62 String name = configuration.getKeystoreManagerName(); 63 Object km = context.getNamingContext().lookup(name); 64 configuration.setKeystoreManager((KeystoreManager) km); 65 } catch (Exception e) { 66 } 68 } 69 if (configuration.getAuthenticationService() == null) { 70 try { 71 String name = configuration.getAuthenticationServiceName(); 72 Object as = context.getNamingContext().lookup(name); 73 configuration.setAuthenticationService((AuthenticationService) as); 74 } catch (Exception e) { 75 configuration.setAuthenticationService(new JAASAuthenticationService()); 76 } 77 } 78 } 79 80 83 public JmsConfiguration getConfiguration() { 84 return configuration; 85 } 86 87 90 public void setConfiguration(JmsConfiguration configuration) { 91 this.configuration = configuration; 92 } 93 94 protected QName getEPRServiceName() { 95 return JmsResolvedEndpoint.EPR_SERVICE; 96 } 97 98 protected Endpoint getResolvedEPR(ServiceEndpoint ep) throws Exception { 99 JmsEndpoint jmsEp = new JmsEndpoint(); 102 jmsEp.setServiceUnit(new ServiceUnit(component)); 103 jmsEp.setService(ep.getServiceName()); 104 jmsEp.setEndpoint(ep.getEndpointName()); 105 jmsEp.setRole(MessageExchange.Role.PROVIDER); 106 URI uri = new URI (ep.getEndpointName()); 107 Map map = URISupport.parseQuery(uri.getQuery()); 108 if( IntrospectionSupport.setProperties(jmsEp, map, "jms.") ) { 109 uri = URISupport.createRemainingURI(uri, map); 110 } 111 if (uri.getPath() != null) { 112 String path = uri.getSchemeSpecificPart(); 113 while (path.startsWith("/")) { 114 path = path.substring(1); 115 } 116 if (path.startsWith(AbstractJmsProcessor.STYLE_QUEUE + "/")) { 117 jmsEp.setDestinationStyle(AbstractJmsProcessor.STYLE_QUEUE); 118 jmsEp.setJmsProviderDestinationName(path.substring(AbstractJmsProcessor.STYLE_QUEUE.length() + 1)); 119 } else if (path.startsWith(AbstractJmsProcessor.STYLE_TOPIC + "/")) { 120 jmsEp.setDestinationStyle(AbstractJmsProcessor.STYLE_TOPIC); 121 jmsEp.setJmsProviderDestinationName(path.substring(AbstractJmsProcessor.STYLE_TOPIC.length() + 1)); 122 } 123 } 124 jmsEp.activateDynamic(); 125 return jmsEp; 128 } 129 130 133 public KeystoreManager getKeystoreManager() { 134 return configuration.getKeystoreManager(); 135 } 136 137 140 public void setKeystoreManager(KeystoreManager keystoreManager) { 141 this.configuration.setKeystoreManager(keystoreManager); 142 } 143 144 147 public AuthenticationService getAuthenticationService() { 148 return configuration.getAuthenticationService(); 149 } 150 151 154 public void setAuthenticationService(AuthenticationService authenticationService) { 155 this.configuration.setAuthenticationService(authenticationService); 156 } 157 158 } 159 | Popular Tags |