1 55 56 package org.jboss.axis.transport.jms; 57 58 import org.jboss.axis.AxisEngine; 59 import org.jboss.axis.AxisFault; 60 import org.jboss.axis.MessageContext; 61 import org.jboss.axis.client.Call; 62 import org.jboss.axis.client.Transport; 63 import org.jboss.axis.utils.Messages; 64 import org.jboss.logging.Logger; 65 66 import javax.jms.Destination ; 67 import java.util.HashMap ; 68 import java.util.Iterator ; 69 70 81 public class JMSTransport extends Transport 82 { 83 protected static Logger log = Logger.getLogger(JMSTransport.class); 84 85 private HashMap connectors; 86 private HashMap connectorProps; 87 private HashMap connectionFactoryProps; 88 private JMSConnector defaultConnector; 89 private HashMap passwords; 90 private Object connectorLock; 91 92 public JMSTransport(HashMap connectorProps, 93 HashMap connectionFactoryProps) 94 { 95 transportName = "JMSTransport"; 96 connectors = new HashMap (); 97 passwords = new HashMap (); 98 this.connectorProps = connectorProps; 99 this.connectionFactoryProps = connectionFactoryProps; 100 connectorLock = new Object (); 101 } 102 103 110 public void setupMessageContextImpl(MessageContext context, 111 Call message, 112 AxisEngine engine) 113 throws AxisFault 114 { 115 String username = message.getUsername(); 116 JMSConnector connector = null; 117 try 118 { 119 if (username == null) 120 { 121 initConnectorIfNecessary(); 122 connector = defaultConnector; 123 } 124 else 125 { 126 String password = message.getPassword(); 127 synchronized (connectorLock) 128 { 129 if (connectors.containsKey(username)) 130 { 131 String oldPassword = (String )passwords.get(username); 132 if (password.equals(oldPassword)) 133 connector = (JMSConnector)connectors.get(username); 134 else 135 throw new AxisFault("badUserPass"); 136 } 137 else 138 { 139 connector = createConnector(username, password); 140 connectors.put(username, connector); 141 passwords.put(username, password); 143 } 144 } 145 } 146 } 147 catch (Exception e) 148 { 149 log.error(Messages.getMessage("cannotConnectError"), e); 150 151 if (e instanceof AxisFault) 152 throw (AxisFault)e; 153 throw new AxisFault("cannotConnect", e); 154 } 155 156 context.setProperty(JMSConstants.CONNECTOR, connector); 157 158 162 Object tmp = message.getProperty(JMSConstants.DESTINATION); 163 if (tmp != null && (tmp instanceof String || tmp instanceof Destination )) 164 context.setProperty(JMSConstants.DESTINATION, tmp); 165 else 166 context.removeProperty(JMSConstants.DESTINATION); 167 168 tmp = message.getProperty(JMSConstants.WAIT_FOR_RESPONSE); 169 if (tmp != null && tmp instanceof Boolean ) 170 context.setProperty(JMSConstants.WAIT_FOR_RESPONSE, tmp); 171 else 172 context.removeProperty(JMSConstants.WAIT_FOR_RESPONSE); 173 174 tmp = message.getProperty(JMSConstants.DELIVERY_MODE); 175 if (tmp != null && tmp instanceof Integer ) 176 context.setProperty(JMSConstants.DELIVERY_MODE, tmp); 177 else 178 context.removeProperty(JMSConstants.DELIVERY_MODE); 179 180 tmp = message.getProperty(JMSConstants.PRIORITY); 181 if (tmp != null && tmp instanceof Integer ) 182 context.setProperty(JMSConstants.PRIORITY, tmp); 183 else 184 context.removeProperty(JMSConstants.PRIORITY); 185 186 tmp = message.getProperty(JMSConstants.TIME_TO_LIVE); 187 if (tmp != null && tmp instanceof Long ) 188 context.setProperty(JMSConstants.TIME_TO_LIVE, tmp); 189 else 190 context.removeProperty(JMSConstants.TIME_TO_LIVE); 191 192 } 193 194 private void initConnectorIfNecessary() 195 throws Exception 196 { 197 if (defaultConnector != null) 198 return; 199 synchronized (connectorLock) 200 { 201 if (defaultConnector != null) 204 return; 205 defaultConnector = createConnector(null, null); 206 } 207 } 208 209 private JMSConnector createConnector(String username, String password) 210 throws Exception 211 { 212 JMSConnector connector = JMSConnectorFactory. 213 createClientConnector(connectorProps, connectionFactoryProps, 214 username, password); 215 connector.start(); 216 return connector; 217 } 218 219 222 public void shutdown() 223 { 224 synchronized (connectorLock) 225 { 226 if (defaultConnector != null) 227 defaultConnector.shutdown(); 228 229 Iterator connectorIter = connectors.values().iterator(); 230 while (connectorIter.hasNext()) 231 { 232 ((JMSConnector)connectorIter.next()).shutdown(); 233 } 234 } 235 } 236 237 } | Popular Tags |