1 55 56 package org.jboss.axis.server; 57 58 import org.jboss.axis.AxisEngine; 59 import org.jboss.axis.AxisFault; 60 import org.jboss.axis.AxisProperties; 61 import org.jboss.axis.Constants; 62 import org.jboss.axis.EngineConfiguration; 63 import org.jboss.axis.Handler; 64 import org.jboss.axis.Message; 65 import org.jboss.axis.MessageContext; 66 import org.jboss.axis.SimpleTargetedChain; 67 import org.jboss.axis.client.AxisClient; 68 import org.jboss.axis.configuration.EngineConfigurationFactoryFinder; 69 import org.jboss.axis.soap.SOAPConstants; 70 import org.jboss.axis.utils.ClassUtils; 71 import org.jboss.axis.utils.Messages; 72 import org.jboss.logging.Logger; 73 74 import java.util.Map ; 75 76 80 public class AxisServer extends AxisEngine 81 { 82 private static Logger log = Logger.getLogger(AxisServer.class.getName()); 83 private static Logger tlog = Logger.getLogger("org.jboss.axis.TIME"); 84 85 private static AxisServerFactory factory = null; 86 87 public static AxisServer getServer(Map environment) throws AxisFault 88 { 89 if (factory == null) 90 { 91 String factoryClassName = AxisProperties.getProperty("axis.ServerFactory"); 92 if (factoryClassName != null) 93 { 94 try 95 { 96 Class factoryClass = ClassUtils.forName(factoryClassName); 97 if (AxisServerFactory.class.isAssignableFrom(factoryClass)) 98 factory = (AxisServerFactory)factoryClass.newInstance(); 99 } 100 catch (Exception e) 101 { 102 log.error(Messages.getMessage("exception00"), e); 105 } 106 } 107 108 if (factory == null) 109 { 110 factory = new DefaultAxisServerFactory(); 111 } 112 } 113 114 return factory.getServer(environment); 115 } 116 117 120 private AxisEngine clientEngine; 121 122 public AxisServer() 123 { 124 this(EngineConfigurationFactoryFinder.newFactory().getServerEngineConfig()); 125 } 126 127 public AxisServer(EngineConfiguration config) 128 { 129 super(config); 130 setShouldSaveConfig(true); 132 } 133 134 138 private boolean running = true; 139 140 public boolean isRunning() 141 { 142 return running; 143 } 144 145 148 public void start() 149 { 150 init(); 152 running = true; 153 } 154 155 158 public void stop() 159 { 160 running = false; 161 } 162 163 167 public synchronized AxisEngine getClientEngine() 168 { 169 if (clientEngine == null) 170 { 171 clientEngine = new AxisClient(); } 173 return clientEngine; 174 } 175 176 180 public void invoke(MessageContext msgContext) throws AxisFault 181 { 182 long t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0; 183 if (tlog.isDebugEnabled()) 184 { 185 t0 = System.currentTimeMillis(); 186 } 187 188 if (log.isDebugEnabled()) 189 { 190 log.debug("Enter: AxisServer::invoke"); 191 } 192 193 if (!isRunning()) 194 { 195 throw new AxisFault("Server.disabled", 196 Messages.getMessage("serverDisabled00"), 197 null, null); 198 } 199 200 String hName = null; 201 Handler h = null; 202 203 MessageContext previousContext = getCurrentMessageContext(); 205 206 try 207 { 208 setCurrentMessageContext(msgContext); 210 211 hName = msgContext.getStrProp(MessageContext.ENGINE_HANDLER); 212 if (hName != null) 213 { 214 if ((h = getHandler(hName)) == null) 215 { 216 ClassLoader cl = msgContext.getClassLoader(); 217 try 218 { 219 log.debug(Messages.getMessage("tryingLoad00", hName)); 220 Class cls = ClassUtils.forName(hName, true, cl); 221 h = (Handler)cls.newInstance(); 222 } 223 catch (Exception e) 224 { 225 h = null; 226 } 227 } 228 if (tlog.isDebugEnabled()) 229 { 230 t1 = System.currentTimeMillis(); 231 } 232 if (h != null) 233 h.invoke(msgContext); 234 else 235 throw new AxisFault("Server.error", 236 Messages.getMessage("noHandler00", hName), 237 null, null); 238 if (tlog.isDebugEnabled()) 239 { 240 t2 = System.currentTimeMillis(); 241 tlog.debug("AxisServer.invoke " + hName + " invoke=" + 242 (t2 - t1) + " pre=" + (t1 - t0)); 243 } 244 245 } 246 else 247 { 248 251 252 253 254 255 256 257 258 259 260 261 262 if (log.isDebugEnabled()) 264 { 265 log.debug(Messages.getMessage("defaultLogic00")); 266 } 267 268 284 285 286 287 hName = msgContext.getTransportName(); 288 SimpleTargetedChain transportChain = null; 289 290 if (log.isDebugEnabled()) 291 log.debug(Messages.getMessage("transport01", "AxisServer.invoke", hName)); 292 293 if (tlog.isDebugEnabled()) 294 { 295 t1 = System.currentTimeMillis(); 296 } 297 if (hName != null && (h = getTransport(hName)) != null) 298 { 299 if (h instanceof SimpleTargetedChain) 300 { 301 transportChain = (SimpleTargetedChain)h; 302 h = transportChain.getRequestHandler(); 303 if (h != null) 304 h.invoke(msgContext); 305 } 306 } 307 308 if (tlog.isDebugEnabled()) 309 { 310 t2 = System.currentTimeMillis(); 311 } 312 313 314 if ((h = getGlobalRequest()) != null) 315 { 316 h.invoke(msgContext); 317 } 318 319 325 h = msgContext.getService(); 326 if (h == null) 327 { 328 Message rm = msgContext.getRequestMessage(); 334 rm.getSOAPEnvelope().getFirstBody(); 335 336 h = msgContext.getService(); 337 if (h == null) 338 throw new AxisFault("Server.NoService", 339 Messages.getMessage("noService05", 340 "" + msgContext.getTargetService()), 341 null, null); 342 } 343 if (tlog.isDebugEnabled()) 344 { 345 t3 = System.currentTimeMillis(); 346 } 347 348 if (msgContext.getRequestMessage().getSOAPEnvelope().getSOAPConstants() != null) 350 { 351 SOAPConstants soapConstants = msgContext.getRequestMessage().getSOAPEnvelope().getSOAPConstants(); 352 msgContext.setSOAPConstants(soapConstants); 353 } 354 355 h.invoke(msgContext); 356 357 if (tlog.isDebugEnabled()) 358 { 359 t4 = System.currentTimeMillis(); 360 } 361 362 363 364 if ((h = getGlobalResponse()) != null) 365 h.invoke(msgContext); 366 367 368 369 if (transportChain != null) 370 { 371 h = transportChain.getResponseHandler(); 372 if (h != null) 373 h.invoke(msgContext); 374 } 375 376 if (tlog.isDebugEnabled()) 377 { 378 t5 = System.currentTimeMillis(); 379 tlog.debug("AxisServer.invoke2 " + 380 " preTr=" + 381 (t1 - t0) + " tr=" + (t2 - t1) + 382 " preInvoke=" + (t3 - t2) + 383 " invoke=" + (t4 - t3) + 384 " postInvoke=" + (t5 - t4) + 385 " " + msgContext.getTargetService() + "." + 386 ((msgContext.getOperation() == null) ? 387 "" : msgContext.getOperation().getName())); 388 } 389 390 } 391 } 392 catch (AxisFault e) 393 { 394 throw e; 395 } 396 catch (Exception e) 397 { 398 throw AxisFault.makeFault(e); 400 401 } 402 finally 403 { 404 setCurrentMessageContext(previousContext); 406 } 407 408 if (log.isDebugEnabled()) 409 { 410 log.debug("Exit: AxisServer::invoke"); 411 } 412 } 413 414 417 public void generateWSDL(MessageContext msgContext) throws AxisFault 418 { 419 if (log.isDebugEnabled()) 420 { 421 log.debug("Enter: AxisServer::generateWSDL"); 422 } 423 424 if (!isRunning()) 425 { 426 throw new AxisFault("Server.disabled", 427 Messages.getMessage("serverDisabled00"), 428 null, null); 429 } 430 431 String hName = null; 432 Handler h = null; 433 434 MessageContext previousContext = getCurrentMessageContext(); 436 437 try 438 { 439 setCurrentMessageContext(msgContext); 441 442 hName = msgContext.getStrProp(MessageContext.ENGINE_HANDLER); 443 if (hName != null) 444 { 445 if ((h = getHandler(hName)) == null) 446 { 447 ClassLoader cl = msgContext.getClassLoader(); 448 try 449 { 450 log.debug(Messages.getMessage("tryingLoad00", hName)); 451 Class cls = ClassUtils.forName(hName, true, cl); 452 h = (Handler)cls.newInstance(); 453 } 454 catch (Exception e) 455 { 456 throw new AxisFault("Server.error", 457 Messages.getMessage("noHandler00", hName), 458 null, null); 459 } 460 } 461 h.generateWSDL(msgContext); 462 } 463 else 464 { 465 468 469 470 471 472 473 474 475 476 477 478 479 log.debug(Messages.getMessage("defaultLogic00")); 481 482 498 499 500 501 hName = msgContext.getTransportName(); 502 SimpleTargetedChain transportChain = null; 503 504 if (log.isDebugEnabled()) 505 log.debug(Messages.getMessage("transport01", 506 "AxisServer.generateWSDL", 507 hName)); 508 if (hName != null && (h = getTransport(hName)) != null) 509 { 510 if (h instanceof SimpleTargetedChain) 511 { 512 transportChain = (SimpleTargetedChain)h; 513 h = transportChain.getRequestHandler(); 514 if (h != null) 515 { 516 h.generateWSDL(msgContext); 517 } 518 } 519 } 520 521 522 523 if ((h = getGlobalRequest()) != null) 524 h.generateWSDL(msgContext); 525 526 532 h = msgContext.getService(); 533 if (h == null) 534 { 535 Message rm = msgContext.getRequestMessage(); 541 if (rm != null) 542 { 543 rm.getSOAPEnvelope().getFirstBody(); 544 h = msgContext.getService(); 545 } 546 if (h == null) 547 { 548 throw new AxisFault(Constants.QNAME_NO_SERVICE_FAULT_CODE, 549 Messages.getMessage("noService05", 550 "" + msgContext.getTargetService()), 551 null, null); 552 } 553 } 554 555 h.generateWSDL(msgContext); 556 557 558 559 if ((h = getGlobalResponse()) != null) 560 h.generateWSDL(msgContext); 561 562 563 564 if (transportChain != null) 565 { 566 h = transportChain.getResponseHandler(); 567 if (h != null) 568 { 569 h.generateWSDL(msgContext); 570 } 571 } 572 } 573 } 574 catch (AxisFault e) 575 { 576 throw e; 577 } 578 catch (Exception e) 579 { 580 throw AxisFault.makeFault(e); 582 } 583 finally 584 { 585 setCurrentMessageContext(previousContext); 587 } 588 589 if (log.isDebugEnabled()) 590 { 591 log.debug("Exit: AxisServer::generateWSDL"); 592 } 593 } 594 } 595 | Popular Tags |