1 16 17 package org.apache.axis; 18 19 import org.apache.axis.components.logger.LogFactory; 20 import org.apache.axis.encoding.TypeMappingRegistry; 21 import org.apache.axis.encoding.TypeMappingImpl; 22 import org.apache.axis.handlers.BasicHandler; 23 import org.apache.axis.handlers.soap.SOAPService; 24 import org.apache.axis.session.Session; 25 import org.apache.axis.session.SimpleSession; 26 import org.apache.axis.utils.JavaUtils; 27 import org.apache.axis.utils.Messages; 28 import org.apache.axis.utils.cache.ClassCache; 29 import org.apache.commons.logging.Log; 30 31 import javax.xml.namespace.QName ; 32 import javax.xml.rpc.server.ServiceLifecycle ; 33 import java.util.ArrayList ; 34 import java.util.Enumeration ; 35 import java.util.Hashtable ; 36 37 38 46 public abstract class AxisEngine extends BasicHandler 47 { 48 51 protected static Log log = 52 LogFactory.getLog(AxisEngine.class.getName()); 53 54 public static final String PROP_XML_DECL = "sendXMLDeclaration"; 56 public static final String PROP_DEBUG_LEVEL = "debugLevel"; 57 public static final String PROP_DEBUG_FILE = "debugFile"; 58 public static final String PROP_DOMULTIREFS = "sendMultiRefs"; 59 public static final String PROP_DISABLE_PRETTY_XML = "disablePrettyXML"; 60 public static final String PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION = "enableNamespacePrefixOptimization"; 61 public static final String PROP_PASSWORD = "adminPassword"; 62 public static final String PROP_SYNC_CONFIG = "syncConfiguration"; 63 public static final String PROP_SEND_XSI = "sendXsiTypes"; 64 public static final String PROP_ATTACHMENT_DIR = "attachments.Directory"; 65 public static final String PROP_ATTACHMENT_IMPLEMENTATION = "attachments.implementation" ; 66 public static final String PROP_ATTACHMENT_CLEANUP = "attachment.DirectoryCleanUp"; 67 public static final String PROP_DEFAULT_CONFIG_CLASS = "axis.engineConfigClass"; 68 public static final String PROP_SOAP_VERSION = "defaultSOAPVersion"; 69 public static final String PROP_SOAP_ALLOWED_VERSION = "singleSOAPVersion"; 70 public static final String PROP_TWOD_ARRAY_ENCODING = "enable2DArrayEncoding"; 71 public static final String PROP_XML_ENCODING = "axis.xmlEncoding"; 72 public static final String PROP_XML_REUSE_SAX_PARSERS = "axis.xml.reuseParsers"; 73 public static final String PROP_BYTE_BUFFER_BACKING = "axis.byteBuffer.backing"; 74 public static final String PROP_BYTE_BUFFER_CACHE_INCREMENT = "axis.byteBuffer.cacheIncrement"; 75 public static final String PROP_BYTE_BUFFER_RESIDENT_MAX_SIZE = "axis.byteBuffer.residentMaxSize"; 76 public static final String PROP_BYTE_BUFFER_WORK_BUFFER_SIZE = "axis.byteBuffer.workBufferSize"; 77 public static final String PROP_EMIT_ALL_TYPES = "emitAllTypesInWSDL"; 78 83 public static final String PROP_DOTNET_SOAPENC_FIX = "dotNetSoapEncFix"; 84 85 public static final String PROP_BP10_COMPLIANCE = "ws-i.bp10Compliance"; 86 87 public static final String DEFAULT_ATTACHMENT_IMPL="org.apache.axis.attachments.AttachmentsImpl"; 88 89 public static final String ENV_ATTACHMENT_DIR = "axis.attachments.Directory"; 90 public static final String ENV_SERVLET_REALPATH = "servlet.realpath"; 91 public static final String ENV_SERVLET_CONTEXT = "servletContext"; 92 93 private static final String DEFAULT_ADMIN_PASSWORD = "admin"; 95 96 97 98 protected EngineConfiguration config; 99 100 101 protected boolean _hasSafePassword = false; 102 103 107 protected boolean shouldSaveConfig = false; 108 109 110 protected transient ClassCache classCache = new ClassCache(); 111 112 117 private Session session = new SimpleSession(); 118 119 122 private ArrayList actorURIs = new ArrayList (); 123 124 128 private static ThreadLocal currentMessageContext = new ThreadLocal (); 129 130 135 protected static void setCurrentMessageContext(MessageContext mc) { 136 currentMessageContext.set(mc); 137 } 138 139 144 public static MessageContext getCurrentMessageContext() { 145 return (MessageContext) currentMessageContext.get(); 146 } 147 148 153 public AxisEngine(EngineConfiguration config) 154 { 155 this.config = config; 156 init(); 157 } 158 159 163 public void init() { 164 if (log.isDebugEnabled()) { 165 log.debug("Enter: AxisEngine::init"); 166 } 167 168 171 try { 172 config.configureEngine(this); 173 } catch (Exception e) { 174 throw new InternalException(e); 175 } 176 177 178 setOptionDefault(PROP_ATTACHMENT_IMPLEMENTATION, 179 AxisProperties.getProperty("axis." + PROP_ATTACHMENT_IMPLEMENTATION )); 180 181 setOptionDefault(PROP_ATTACHMENT_IMPLEMENTATION, DEFAULT_ATTACHMENT_IMPL); 182 183 final Object dotnet = getOption(PROP_DOTNET_SOAPENC_FIX); 187 if (JavaUtils.isTrue(dotnet)) { 188 TypeMappingImpl.dotnet_soapenc_bugfix = true; 192 } 193 194 if (log.isDebugEnabled()) { 195 log.debug("Exit: AxisEngine::init"); 196 } 197 198 } 199 200 206 public void cleanup() { 207 super.cleanup(); 208 209 Enumeration keys = session.getKeys(); 212 if (keys != null) { 213 while (keys.hasMoreElements()) { 214 String key = (String )keys.nextElement(); 215 Object obj = session.get(key); 216 if (obj != null && obj instanceof ServiceLifecycle ) { 217 ((ServiceLifecycle )obj).destroy(); 218 } 219 session.remove(key); 220 } 221 } 222 } 223 224 226 public void saveConfiguration() 227 { 228 if (!shouldSaveConfig) 229 return; 230 231 try { 232 config.writeEngineConfig(this); 233 } catch (Exception e) { 234 log.error(Messages.getMessage("saveConfigFail00"), e); 235 } 236 } 237 238 244 public EngineConfiguration getConfig() { 245 return config; 246 } 247 248 253 public boolean hasSafePassword() 254 { 255 return _hasSafePassword; 256 } 257 258 263 public void setAdminPassword(String pw) 264 { 265 setOption(PROP_PASSWORD, pw); 266 _hasSafePassword = true; 267 saveConfiguration(); 268 } 269 270 276 public void setShouldSaveConfig(boolean shouldSaveConfig) 277 { 278 this.shouldSaveConfig = shouldSaveConfig; 279 } 280 281 290 public Handler getHandler(String name) throws AxisFault 291 { 292 try { 293 return config.getHandler(new QName (null, name)); 294 } catch (ConfigurationException e) { 295 throw new AxisFault(e); 296 } 297 } 298 299 308 public SOAPService getService(String name) throws AxisFault 309 { 310 try { 311 return config.getService(new QName (null, name)); 312 } catch (ConfigurationException e) { 313 try { 314 return config.getServiceByNamespaceURI(name); 315 } catch (ConfigurationException e1) { 316 throw new AxisFault(e); 317 } 318 } 319 } 320 321 329 public Handler getTransport(String name) throws AxisFault 330 { 331 try { 332 return config.getTransport(new QName (null, name)); 333 } catch (ConfigurationException e) { 334 throw new AxisFault(e); 335 } 336 } 337 338 344 public TypeMappingRegistry getTypeMappingRegistry() 345 { 346 TypeMappingRegistry tmr = null; 347 try { 348 tmr = config.getTypeMappingRegistry(); 349 } catch (ConfigurationException e) { 350 log.error(Messages.getMessage("axisConfigurationException00"), e); 351 } 352 353 return tmr; 354 } 355 356 362 public Handler getGlobalRequest() 363 throws ConfigurationException 364 { 365 return config.getGlobalRequest(); 366 } 367 368 374 public Handler getGlobalResponse() 375 throws ConfigurationException 376 { 377 return config.getGlobalResponse(); 378 } 379 380 388 public ArrayList getActorURIs() 389 { 390 return (ArrayList )actorURIs.clone(); 391 } 392 393 398 public void addActorURI(String uri) 399 { 400 actorURIs.add(uri); 401 } 402 403 408 public void removeActorURI(String uri) 409 { 410 actorURIs.remove(uri); 411 } 412 413 424 425 public abstract AxisEngine getClientEngine (); 426 427 434 435 440 private static final String [] BOOLEAN_OPTIONS = new String [] { 441 PROP_DOMULTIREFS, PROP_SEND_XSI, PROP_XML_DECL, 442 PROP_DISABLE_PRETTY_XML, 443 PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION 444 }; 445 446 456 public static void normaliseOptions(Handler handler) { 457 460 for (int i = 0; i < BOOLEAN_OPTIONS.length; i++) { 461 Object val = handler.getOption(BOOLEAN_OPTIONS[i]); 462 if (val != null) { 463 if (val instanceof Boolean ) 464 continue; 465 if (JavaUtils.isFalse(val)) { 466 handler.setOption(BOOLEAN_OPTIONS[i], Boolean.FALSE); 467 continue; 468 } 469 } else { 470 if (!(handler instanceof AxisEngine)) 471 continue; 472 } 473 handler.setOption(BOOLEAN_OPTIONS[i], Boolean.TRUE); 475 } 476 477 if (handler instanceof AxisEngine) { 479 AxisEngine engine = (AxisEngine)handler; 480 if (!engine.setOptionDefault(PROP_PASSWORD, 481 DEFAULT_ADMIN_PASSWORD)) { 482 engine.setAdminPassword( 483 (String )engine.getOption(PROP_PASSWORD)); 484 } 485 } 486 } 487 488 493 public void refreshGlobalOptions() throws ConfigurationException { 494 Hashtable globalOptions = config.getGlobalOptions(); 495 if (globalOptions != null) 496 setOptions(globalOptions); 497 498 normaliseOptions(this); 499 500 actorURIs = new ArrayList (config.getRoles()); 503 } 504 505 511 public Session getApplicationSession () { 512 return session; 513 } 514 515 520 public ClassCache getClassCache() { 521 return classCache; 522 } 523 524 } 525 | Popular Tags |