1 16 17 package org.apache.axis.transport.jms; 18 19 import org.apache.axis.AxisEngine; 20 import org.apache.axis.AxisFault; 21 import org.apache.axis.MessageContext; 22 import org.apache.axis.client.Call; 23 import org.apache.axis.client.Transport; 24 import org.apache.axis.components.jms.JMSVendorAdapter; 25 import org.apache.axis.components.jms.JMSVendorAdapterFactory; 26 import org.apache.axis.components.logger.LogFactory; 27 import org.apache.axis.utils.Messages; 28 import org.apache.commons.logging.Log; 29 30 import java.util.HashMap ; 31 32 47 public class JMSTransport extends Transport 48 { 49 protected static Log log = 50 LogFactory.getLog(JMSTransport.class.getName()); 51 52 private static HashMap vendorConnectorPools = new HashMap (); 53 54 private HashMap defaultConnectorProps; 55 private HashMap defaultConnectionFactoryProps; 56 57 static 58 { 59 Runtime.getRuntime().addShutdownHook( 61 new Thread () 62 { 63 public void run() 64 { 65 JMSTransport.closeAllConnectors(); 66 } 67 } 68 ); 69 } 70 71 public JMSTransport() 72 { 73 transportName = "JMSTransport"; 74 } 75 76 public JMSTransport(HashMap connectorProps, 78 HashMap connectionFactoryProps) 79 { 80 this(); 81 defaultConnectorProps = connectorProps; 82 defaultConnectionFactoryProps = connectionFactoryProps; 83 } 84 85 92 public void setupMessageContextImpl(MessageContext context, 93 Call message, 94 AxisEngine engine) 95 throws AxisFault 96 { 97 if (log.isDebugEnabled()) { 98 log.debug("Enter: JMSTransport::setupMessageContextImpl"); 99 } 100 101 JMSConnector connector = null; 102 HashMap connectorProperties = null; 103 HashMap connectionFactoryProperties = null; 104 105 JMSVendorAdapter vendorAdapter = null; 106 JMSURLHelper jmsurl = null; 107 108 String username = message.getUsername(); 110 String password = message.getPassword(); 111 112 String endpointAddr = message.getTargetEndpointAddress(); 115 if (endpointAddr != null) 116 { 117 try 118 { 119 jmsurl = new JMSURLHelper(new java.net.URL (endpointAddr)); 121 122 String vendorId = jmsurl.getVendor(); 124 if (vendorId == null) 125 vendorId = JMSConstants.JNDI_VENDOR_ID; 126 127 if (log.isDebugEnabled()) 128 log.debug("JMSTransport.setupMessageContextImpl(): endpt=" + endpointAddr + 129 ", vendor=" + vendorId); 130 131 vendorAdapter = JMSVendorAdapterFactory.getJMSVendorAdapter(vendorId); 132 if (vendorAdapter == null) 133 { 134 throw new AxisFault("cannotLoadAdapterClass:" + vendorId); 135 } 136 137 connectorProperties = vendorAdapter.getJMSConnectorProperties(jmsurl); 139 connectionFactoryProperties = vendorAdapter.getJMSConnectionFactoryProperties(jmsurl); 140 } 141 catch (java.net.MalformedURLException e) 142 { 143 log.error(Messages.getMessage("malformedURLException00"), e); 144 throw new AxisFault(Messages.getMessage("malformedURLException00"), e); 145 } 146 } 147 else 148 { 149 vendorAdapter = JMSVendorAdapterFactory.getJMSVendorAdapter(); 151 if (vendorAdapter == null) 152 { 153 throw new AxisFault("cannotLoadAdapterClass"); 154 } 155 156 connectorProperties = defaultConnectorProps; 158 connectionFactoryProperties = defaultConnectionFactoryProps; 159 } 160 161 try 162 { 163 connector = JMSConnectorManager.getInstance().getConnector(connectorProperties, connectionFactoryProperties, 164 username, password, vendorAdapter); 165 } 166 catch (Exception e) 167 { 168 log.error(Messages.getMessage("cannotConnectError"), e); 169 170 if(e instanceof AxisFault) 171 throw (AxisFault)e; 172 throw new AxisFault("cannotConnect", e); 173 } 174 175 context.setProperty(JMSConstants.CONNECTOR, connector); 177 context.setProperty(JMSConstants.VENDOR_ADAPTER, vendorAdapter); 178 179 vendorAdapter.setupMessageContext(context, message, jmsurl); 181 182 if (log.isDebugEnabled()) { 183 log.debug("Exit: JMSTransport::setupMessageContextImpl"); 184 } 185 } 186 187 190 public void shutdown() 191 { 192 if (log.isDebugEnabled()) { 193 log.debug("Enter: JMSTransport::shutdown"); 194 } 195 196 closeAllConnectors(); 197 198 if (log.isDebugEnabled()) { 199 log.debug("Exit: JMSTransport::shutdown"); 200 } 201 } 202 203 206 public static void closeAllConnectors() 207 { 208 if (log.isDebugEnabled()) { 209 log.debug("Enter: JMSTransport::closeAllConnectors"); 210 } 211 212 JMSConnectorManager.getInstance().closeAllConnectors(); 213 214 if (log.isDebugEnabled()) { 215 log.debug("Exit: JMSTransport::closeAllConnectors"); 216 } 217 } 218 219 226 public static void closeMatchingJMSConnectors(String endpointAddr, String username, String password) 227 { 228 if (log.isDebugEnabled()) { 229 log.debug("Enter: JMSTransport::closeMatchingJMSConnectors"); 230 } 231 232 try 233 { 234 JMSURLHelper jmsurl = new JMSURLHelper(new java.net.URL (endpointAddr)); 235 String vendorId = jmsurl.getVendor(); 236 237 JMSVendorAdapter vendorAdapter = null; 238 if (vendorId == null) 239 vendorId = JMSConstants.JNDI_VENDOR_ID; 240 vendorAdapter = JMSVendorAdapterFactory.getJMSVendorAdapter(vendorId); 241 242 if (vendorAdapter == null) 244 return; 245 246 HashMap connectorProps = vendorAdapter.getJMSConnectorProperties(jmsurl); 248 HashMap cfProps = vendorAdapter.getJMSConnectionFactoryProperties(jmsurl); 249 250 JMSConnectorManager.getInstance().closeMatchingJMSConnectors(connectorProps, cfProps, 251 username, password, 252 vendorAdapter); 253 } 254 catch (java.net.MalformedURLException e) 255 { 256 log.warn(Messages.getMessage("malformedURLException00"), e); 257 } 258 259 if (log.isDebugEnabled()) { 260 log.debug("Exit: JMSTransport::closeMatchingJMSConnectors"); 261 } 262 } 263 } | Popular Tags |