1 16 17 package org.apache.axis.server ; 18 19 import org.apache.axis.AxisEngine; 20 import org.apache.axis.AxisFault; 21 import org.apache.axis.AxisProperties; 22 import org.apache.axis.Constants; 23 import org.apache.axis.EngineConfiguration; 24 import org.apache.axis.Handler; 25 import org.apache.axis.Message; 26 import org.apache.axis.MessageContext; 27 import org.apache.axis.SimpleTargetedChain; 28 import org.apache.axis.message.SOAPEnvelope; 29 import org.apache.axis.soap.SOAPConstants; 30 import org.apache.axis.client.AxisClient; 31 import org.apache.axis.components.logger.LogFactory; 32 import org.apache.axis.configuration.EngineConfigurationFactoryFinder; 33 import org.apache.axis.utils.ClassUtils; 34 import org.apache.axis.utils.Messages; 35 import org.apache.commons.logging.Log; 36 37 import java.util.Map ; 38 43 public class AxisServer extends AxisEngine 44 { 45 protected static Log log = 46 LogFactory.getLog(AxisServer.class.getName()); 47 private static Log tlog = 48 LogFactory.getLog("org.apache.axis.TIME"); 49 50 private static AxisServerFactory factory = null; 51 52 public static AxisServer getServer(Map environment) throws AxisFault 53 { 54 if (factory == null) { 55 String factoryClassName = AxisProperties.getProperty("axis.ServerFactory"); 56 if (factoryClassName != null) { 57 try { 58 Class factoryClass = ClassUtils.forName(factoryClassName); 59 if (AxisServerFactory.class.isAssignableFrom(factoryClass)) 60 factory = (AxisServerFactory)factoryClass.newInstance(); 61 } catch (Exception e) { 62 log.error(Messages.getMessage("exception00"), e); 65 } 66 } 67 68 if (factory == null) { 69 factory = new DefaultAxisServerFactory(); 70 } 71 } 72 73 return factory.getServer(environment); 74 } 75 76 79 private AxisEngine clientEngine; 80 81 public AxisServer() 82 { 83 this(EngineConfigurationFactoryFinder.newFactory().getServerEngineConfig()); 84 } 85 86 public AxisServer(EngineConfiguration config) 87 { 88 super(config); 89 setShouldSaveConfig(true); 91 } 92 93 96 private boolean running = true; 97 98 public boolean isRunning() { return running; } 99 100 102 public void start() 103 { 104 init(); 106 running = true; 107 } 108 109 111 public void stop() 112 { 113 running = false; 114 } 115 116 120 public synchronized AxisEngine getClientEngine () { 121 if (clientEngine == null) { 122 clientEngine = new AxisClient(); } 124 return clientEngine; 125 } 126 127 131 public void invoke(MessageContext msgContext) throws AxisFault { 132 long t0=0, t1=0, t2=0, t3=0, t4=0, t5=0; 133 if( tlog.isDebugEnabled() ) { 134 t0=System.currentTimeMillis(); 135 } 136 137 if (log.isDebugEnabled()) { 138 log.debug("Enter: AxisServer::invoke"); 139 } 140 141 if (!isRunning()) { 142 throw new AxisFault("Server.disabled", 143 Messages.getMessage("serverDisabled00"), 144 null, null); 145 } 146 147 String hName = null ; 148 Handler h = null ; 149 150 MessageContext previousContext = getCurrentMessageContext(); 152 153 try { 154 setCurrentMessageContext(msgContext); 156 157 hName = msgContext.getStrProp( MessageContext.ENGINE_HANDLER ); 158 if ( hName != null ) { 159 if ( (h = getHandler(hName)) == null ) { 160 ClassLoader cl = msgContext.getClassLoader(); 161 try { 162 log.debug( Messages.getMessage("tryingLoad00", hName) ); 163 Class cls = ClassUtils.forName(hName, true, cl); 164 h = (Handler) cls.newInstance(); 165 } 166 catch( Exception e ) { 167 h = null ; 168 } 169 } 170 if( tlog.isDebugEnabled() ) { 171 t1=System.currentTimeMillis(); 172 } 173 if ( h != null ) 174 h.invoke(msgContext); 175 else 176 throw new AxisFault( "Server.error", 177 Messages.getMessage("noHandler00", hName), 178 null, null ); 179 if( tlog.isDebugEnabled() ) { 180 t2=System.currentTimeMillis(); 181 tlog.debug( "AxisServer.invoke " + hName + " invoke=" + 182 ( t2-t1 ) + " pre=" + (t1-t0 )); 183 } 184 185 } 186 else { 187 190 191 192 193 194 195 196 197 198 199 200 201 if (log.isDebugEnabled()) { 203 log.debug(Messages.getMessage("defaultLogic00") ); 204 } 205 206 222 223 224 225 hName = msgContext.getTransportName(); 226 SimpleTargetedChain transportChain = null; 227 228 if (log.isDebugEnabled()) 229 log.debug(Messages.getMessage("transport01", "AxisServer.invoke", hName)); 230 231 if( tlog.isDebugEnabled() ) { 232 t1=System.currentTimeMillis(); 233 } 234 if ( hName != null && (h = getTransport( hName )) != null ) { 235 if (h instanceof SimpleTargetedChain) { 236 transportChain = (SimpleTargetedChain)h; 237 h = transportChain.getRequestHandler(); 238 if (h != null) 239 h.invoke(msgContext); 240 } 241 } 242 243 if( tlog.isDebugEnabled() ) { 244 t2=System.currentTimeMillis(); 245 } 246 247 248 if ((h = getGlobalRequest()) != null ) { 249 h.invoke(msgContext); 250 } 251 252 258 h = msgContext.getService(); 259 if (h == null) { 260 Message rm = msgContext.getRequestMessage(); 266 rm.getSOAPEnvelope().getFirstBody(); 267 268 h = msgContext.getService(); 269 if (h == null) 270 throw new AxisFault("Server.NoService", 271 Messages.getMessage("noService05", 272 "" + msgContext.getTargetService()), 273 null, null ); 274 } 275 if( tlog.isDebugEnabled() ) { 276 t3=System.currentTimeMillis(); 277 } 278 279 initSOAPConstants(msgContext); 280 try { 281 h.invoke(msgContext); 282 } catch (AxisFault ae) { 283 if ((h = getGlobalRequest()) != null ) { 284 h.onFault(msgContext); 285 } 286 throw ae; 287 } 288 289 if( tlog.isDebugEnabled() ) { 290 t4=System.currentTimeMillis(); 291 } 292 293 294 295 if ((h = getGlobalResponse()) != null) 296 h.invoke(msgContext); 297 298 299 300 if (transportChain != null) { 301 h = transportChain.getResponseHandler(); 302 if (h != null) 303 h.invoke(msgContext); 304 } 305 306 if( tlog.isDebugEnabled() ) { 307 t5=System.currentTimeMillis(); 308 tlog.debug( "AxisServer.invoke2 " + 309 " preTr=" + 310 ( t1-t0 ) + " tr=" + (t2-t1 ) + 311 " preInvoke=" + ( t3-t2 ) + 312 " invoke=" + ( t4-t3 ) + 313 " postInvoke=" + ( t5-t4 ) + 314 " " + msgContext.getTargetService() + "." + 315 ((msgContext.getOperation( ) == null) ? 316 "" : msgContext.getOperation().getName()) ); 317 } 318 319 } 320 } catch (AxisFault e) { 321 throw e; 322 } catch (Exception e) { 323 throw AxisFault.makeFault(e); 325 326 } finally { 327 setCurrentMessageContext(previousContext); 329 } 330 331 if (log.isDebugEnabled()) { 332 log.debug("Exit: AxisServer::invoke"); 333 } 334 } 335 336 341 private void initSOAPConstants(MessageContext msgContext) throws AxisFault { 342 Message msg = msgContext.getRequestMessage(); 343 if (msg == null) 344 return; 345 SOAPEnvelope env = msg.getSOAPEnvelope(); 346 if (env == null) 347 return; 348 SOAPConstants constants = env.getSOAPConstants(); 349 if (constants == null) 350 return; 351 msgContext.setSOAPConstants(constants); 353 } 354 355 358 public void generateWSDL(MessageContext msgContext) throws AxisFault { 359 if (log.isDebugEnabled()) { 360 log.debug("Enter: AxisServer::generateWSDL"); 361 } 362 363 if (!isRunning()) { 364 throw new AxisFault("Server.disabled", 365 Messages.getMessage("serverDisabled00"), 366 null, null); 367 } 368 369 String hName = null ; 370 Handler h = null ; 371 372 MessageContext previousContext = getCurrentMessageContext(); 374 375 try { 376 setCurrentMessageContext(msgContext); 378 379 hName = msgContext.getStrProp( MessageContext.ENGINE_HANDLER ); 380 if ( hName != null ) { 381 if ( (h = getHandler(hName)) == null ) { 382 ClassLoader cl = msgContext.getClassLoader(); 383 try { 384 log.debug( Messages.getMessage("tryingLoad00", hName) ); 385 Class cls = ClassUtils.forName(hName, true, cl); 386 h = (Handler) cls.newInstance(); 387 } 388 catch( Exception e ) { 389 throw new AxisFault( 390 "Server.error", 391 Messages.getMessage("noHandler00", hName), 392 null, null ); 393 } 394 } 395 h.generateWSDL(msgContext); 396 } 397 else { 398 401 402 403 404 405 406 407 408 409 410 411 412 log.debug( Messages.getMessage("defaultLogic00") ); 414 415 431 432 433 434 hName = msgContext.getTransportName(); 435 SimpleTargetedChain transportChain = null; 436 437 if (log.isDebugEnabled()) 438 log.debug(Messages.getMessage("transport01", 439 "AxisServer.generateWSDL", 440 hName)); 441 if ( hName != null && (h = getTransport( hName )) != null ) { 442 if (h instanceof SimpleTargetedChain) { 443 transportChain = (SimpleTargetedChain)h; 444 h = transportChain.getRequestHandler(); 445 if (h != null) { 446 h.generateWSDL(msgContext); 447 } 448 } 449 } 450 451 452 453 if ((h = getGlobalRequest()) != null ) 454 h.generateWSDL(msgContext); 455 456 462 h = msgContext.getService(); 463 if (h == null) { 464 Message rm = msgContext.getRequestMessage(); 470 if (rm != null) { 471 rm.getSOAPEnvelope().getFirstBody(); 472 h = msgContext.getService(); 473 } 474 if (h == null) { 475 throw new AxisFault(Constants.QNAME_NO_SERVICE_FAULT_CODE, 476 Messages.getMessage("noService05", 477 "" + msgContext.getTargetService()), 478 null, null ); 479 } 480 } 481 482 h.generateWSDL(msgContext); 483 484 485 486 if ((h = getGlobalResponse()) != null ) 487 h.generateWSDL(msgContext); 488 489 490 491 if (transportChain != null) { 492 h = transportChain.getResponseHandler(); 493 if (h != null) { 494 h.generateWSDL(msgContext); 495 } 496 } 497 } 498 } catch (AxisFault e) { 499 throw e; 500 } catch(Exception e) { 501 throw AxisFault.makeFault(e); 503 } finally { 504 setCurrentMessageContext(previousContext); 506 } 507 508 if (log.isDebugEnabled()) { 509 log.debug("Exit: AxisServer::generateWSDL"); 510 } 511 } 512 } 513 | Popular Tags |