1 8 9 package org.jboss.axis; 10 11 import org.jboss.axis.encoding.TypeMappingRegistry; 12 import org.jboss.axis.handlers.BasicHandler; 13 import org.jboss.axis.handlers.soap.SOAPService; 14 import org.jboss.axis.session.Session; 15 import org.jboss.axis.session.SimpleSession; 16 import org.jboss.axis.utils.JavaUtils; 17 import org.jboss.axis.utils.Messages; 18 import org.jboss.axis.utils.cache.ClassCache; 19 import org.jboss.logging.Logger; 20 21 import javax.xml.namespace.QName ; 22 import javax.xml.rpc.server.ServiceLifecycle ; 23 import java.util.ArrayList ; 24 import java.util.Enumeration ; 25 import java.util.Hashtable ; 26 27 28 36 public abstract class AxisEngine extends BasicHandler 37 { 38 private static Logger log = Logger.getLogger(AxisEngine.class.getName()); 39 40 public static final String PROP_XML_DECL = "sendXMLDeclaration"; 42 public static final String PROP_DEBUG_LEVEL = "debugLevel"; 43 public static final String PROP_DEBUG_FILE = "debugFile"; 44 public static final String PROP_DOMULTIREFS = "sendMultiRefs"; 45 public static final String PROP_PASSWORD = "adminPassword"; 46 public static final String PROP_SYNC_CONFIG = "syncConfiguration"; 47 public static final String PROP_SEND_XSI = "sendXsiTypes"; 48 public static final String PROP_ATTACHMENT_DIR = "attachments.Directory"; 49 public static final String PROP_ATTACHMENT_IMPLEMENTATION = "attachments.implementation"; 50 public static final String PROP_ATTACHMENT_CLEANUP = "attachment.DirectoryCleanUp"; 51 public static final String PROP_DEFAULT_CONFIG_CLASS = "axis.engineConfigClass"; 52 public static final String PROP_SOAP_VERSION = "defaultSOAPVersion"; 53 public static final String PROP_SOAP_ALLOWED_VERSION = "singleSOAPVersion"; 54 public static final String PROP_TWOD_ARRAY_ENCODING = "enable2DArrayEncoding"; 55 public static final String PROP_SEND_MINIMIZED_ELEMENTS = "axis.sendMinimizedElements"; 56 public static final String PROP_XML_ENCODING = "axis.xmlEncoding"; 57 58 public static final String DEFAULT_ATTACHMENT_IMPL = "org.jboss.axis.attachments.AttachmentsImpl"; 59 60 public static final String ENV_ATTACHMENT_DIR = "axis.attachments.Directory"; 61 public static final String ENV_SERVLET_REALPATH = "servlet.realpath"; 62 public static final String ENV_SERVLET_CONTEXT = "servletContext"; 63 64 private static final String DEFAULT_ADMIN_PASSWORD = "admin"; 66 67 68 71 protected EngineConfiguration config; 72 73 76 protected boolean _hasSafePassword = false; 77 78 81 protected boolean shouldSaveConfig = false; 82 83 84 86 91 private Session session = new SimpleSession(); 92 93 96 private ArrayList actorURIs = new ArrayList (); 97 98 102 private static ThreadLocal currentMessageContext = new ThreadLocal (); 103 104 109 public static void setCurrentMessageContext(MessageContext mc) 110 { 111 currentMessageContext.set(mc); 112 } 113 114 119 public static MessageContext getCurrentMessageContext() 120 { 121 return (MessageContext)currentMessageContext.get(); 122 } 123 124 129 public AxisEngine(EngineConfiguration config) 130 { 131 this.config = config; 132 init(); 133 } 134 135 138 public void init() 139 { 140 if (log.isDebugEnabled()) 141 { 142 log.debug("Enter: AxisEngine::init"); 143 } 144 145 148 try 149 { 150 config.configureEngine(this); 151 } 152 catch (Exception e) 153 { 154 throw new InternalException(e); 155 } 156 157 158 setOptionDefault(PROP_ATTACHMENT_IMPLEMENTATION, 159 AxisProperties.getProperty("axis." + PROP_ATTACHMENT_IMPLEMENTATION)); 160 161 setOptionDefault(PROP_ATTACHMENT_IMPLEMENTATION, DEFAULT_ATTACHMENT_IMPL); 162 163 if (log.isDebugEnabled()) 164 { 165 log.debug("Exit: AxisEngine::init"); 166 } 167 168 } 169 170 175 public void cleanup() 176 { 177 super.cleanup(); 178 179 Enumeration keys = session.getKeys(); 182 if (keys != null) 183 { 184 while (keys.hasMoreElements()) 185 { 186 String key = (String )keys.nextElement(); 187 Object obj = session.get(key); 188 if (obj != null && obj instanceof ServiceLifecycle ) 189 { 190 ((ServiceLifecycle )obj).destroy(); 191 } 192 session.remove(key); 193 } 194 } 195 } 196 197 200 public void saveConfiguration() 201 { 202 if (!shouldSaveConfig) 203 return; 204 205 try 206 { 207 config.writeEngineConfig(this); 208 } 209 catch (Exception e) 210 { 211 log.error(Messages.getMessage("saveConfigFail00"), e); 212 } 213 } 214 215 public EngineConfiguration getConfig() 216 { 217 return config; 218 } 219 220 public boolean hasSafePassword() 221 { 222 return _hasSafePassword; 223 } 224 225 public void setAdminPassword(String pw) 226 { 227 setOption(PROP_PASSWORD, pw); 228 _hasSafePassword = true; 229 saveConfiguration(); 230 } 231 232 public void setShouldSaveConfig(boolean shouldSaveConfig) 233 { 234 this.shouldSaveConfig = shouldSaveConfig; 235 } 236 237 public Handler getHandler(String name) throws AxisFault 238 { 239 try 240 { 241 return config.getHandler(new QName (null, name)); 242 } 243 catch (ConfigurationException e) 244 { 245 throw AxisFault.makeFault(e); 246 } 247 } 248 249 public SOAPService getService(String name) throws AxisFault 250 { 251 try 252 { 253 return config.getService(new QName (null, name)); 254 } 255 catch (ConfigurationException e) 256 { 257 throw AxisFault.makeFault(e); 258 } 259 } 260 261 public Handler getTransport(String name) throws AxisFault 262 { 263 try 264 { 265 return config.getTransport(new QName (null, name)); 266 } 267 catch (ConfigurationException e) 268 { 269 throw AxisFault.makeFault(e); 270 } 271 } 272 273 public TypeMappingRegistry getTypeMappingRegistry() 274 { 275 TypeMappingRegistry tmr = null; 276 try 277 { 278 tmr = config.getTypeMappingRegistry(); 279 } 280 catch (ConfigurationException e) 281 { 282 log.error(Messages.getMessage("axisConfigurationException00"), e); 283 } 284 285 return tmr; 286 } 287 288 public Handler getGlobalRequest() 289 throws ConfigurationException 290 { 291 return config.getGlobalRequest(); 292 } 293 294 public Handler getGlobalResponse() 295 throws ConfigurationException 296 { 297 return config.getGlobalResponse(); 298 } 299 300 public ArrayList getActorURIs() 301 { 302 return actorURIs; 303 } 304 305 public void addActorURI(String uri) 306 { 307 actorURIs.add(uri); 308 } 309 310 public void removeActorURI(String uri) 311 { 312 actorURIs.remove(uri); 313 } 314 315 326 327 public abstract AxisEngine getClientEngine(); 328 329 337 338 343 private static final String [] BOOLEAN_OPTIONS = new String []{ 344 PROP_DOMULTIREFS, PROP_SEND_XSI, PROP_XML_DECL, PROP_SEND_MINIMIZED_ELEMENTS 345 }; 346 347 354 public static void normaliseOptions(Handler handler) 355 { 356 359 for (int i = 0; i < BOOLEAN_OPTIONS.length; i++) 360 { 361 Object val = handler.getOption(BOOLEAN_OPTIONS[i]); 362 if (val != null) 363 { 364 if (val instanceof Boolean ) 365 continue; 366 if (JavaUtils.isFalse(val)) 367 { 368 handler.setOption(BOOLEAN_OPTIONS[i], Boolean.FALSE); 369 continue; 370 } 371 } 372 else 373 { 374 if (!(handler instanceof AxisEngine)) 375 continue; 376 } 377 handler.setOption(BOOLEAN_OPTIONS[i], Boolean.TRUE); 379 } 380 381 if (handler instanceof AxisEngine) 383 { 384 AxisEngine engine = (AxisEngine)handler; 385 if (!engine.setOptionDefault(PROP_PASSWORD, 386 DEFAULT_ADMIN_PASSWORD)) 387 { 388 engine.setAdminPassword((String )engine.getOption(PROP_PASSWORD)); 389 } 390 } 391 } 392 393 396 public void refreshGlobalOptions() throws ConfigurationException 397 { 398 Hashtable globalOptions = config.getGlobalOptions(); 399 if (globalOptions != null) 400 setOptions(globalOptions); 401 402 normaliseOptions(this); 403 } 404 405 410 public Session getApplicationSession() 411 { 412 return session; 413 } 414 415 public ClassCache getClassCache() 416 { 417 return null; 420 } 421 422 } 423 | Popular Tags |