1 54 55 package org.jboss.axis.handlers.soap; 56 57 import org.jboss.axis.AxisEngine; 58 import org.jboss.axis.AxisFault; 59 import org.jboss.axis.Constants; 60 import org.jboss.axis.Handler; 61 import org.jboss.axis.MessageContext; 62 import org.jboss.axis.SimpleTargetedChain; 63 import org.jboss.axis.attachments.Attachments; 64 import org.jboss.axis.description.ServiceDesc; 65 import org.jboss.axis.encoding.TypeMappingRegistry; 66 import org.jboss.axis.enums.Style; 67 import org.jboss.axis.enums.Use; 68 import org.jboss.axis.handlers.BasicHandler; 69 import org.jboss.axis.handlers.HandlerChainImpl; 70 import org.jboss.axis.handlers.HandlerInfoChainFactory; 71 import org.jboss.axis.message.SOAPEnvelopeAxisImpl; 72 import org.jboss.axis.message.SOAPHeaderElementAxisImpl; 73 import org.jboss.axis.providers.BasicProvider; 74 import org.jboss.axis.soap.SOAPConstants; 75 import org.jboss.axis.utils.LockableHashtable; 76 import org.jboss.axis.utils.Messages; 77 import org.jboss.axis.utils.XMLUtils; 78 import org.jboss.logging.Logger; 79 import org.w3c.dom.Document ; 80 81 import javax.xml.namespace.QName ; 82 import java.io.File ; 83 import java.io.FileInputStream ; 84 import java.io.IOException ; 85 import java.io.InputStream ; 86 import java.util.ArrayList ; 87 import java.util.Enumeration ; 88 import java.util.Hashtable ; 89 import java.util.Vector ; 90 91 92 100 public class SOAPService extends SimpleTargetedChain 101 { 102 private static Logger log = Logger.getLogger(SOAPService.class.getName()); 103 104 111 private Vector validTransports = null; 112 113 117 private boolean highFidelityRecording = true; 118 119 125 private int sendType = Attachments.SEND_TYPE_NOTSET; 126 127 131 private ServiceDesc serviceDescription = new ServiceDesc(); 132 private AxisEngine engine; 133 134 137 ArrayList actors = new ArrayList (); 138 139 144 public ArrayList getServiceActors() 145 { 146 return actors; 147 } 148 149 155 public ArrayList getActors() 156 { 157 ArrayList acts = (ArrayList )actors.clone(); 159 if (engine != null) 163 { 164 acts.addAll(engine.getActorURIs()); 165 } 166 return acts; 167 } 168 169 170 174 private class SOAPResponseHandler extends BasicHandler 175 { 176 public SOAPResponseHandler() 177 { 178 } 179 180 public void invoke(MessageContext msgContext) throws AxisFault 181 { 182 if (log.isDebugEnabled()) 184 { 185 log.debug(Messages.getMessage("semanticCheck00")); 186 } 187 188 checkMustUnderstand(msgContext); 189 } 190 191 199 private void checkMustUnderstand(MessageContext msgContext) throws AxisFault 200 { 201 String svcActor = ""; 203 SOAPEnvelopeAxisImpl env = msgContext.getRequestMessage().getSOAPEnvelope(); 205 Vector headers = env.getHeaders(); Vector misunderstoodHeaders = null; 207 Enumeration en = headers.elements(); 208 while (en.hasMoreElements()) 209 { 210 SOAPHeaderElementAxisImpl header = (SOAPHeaderElementAxisImpl)en. 211 nextElement(); 212 219 if (header.getActor() != null && header.getMustUnderstand() && 220 header.getActor() != svcActor) 221 { 222 if (misunderstoodHeaders == null) 223 misunderstoodHeaders = new Vector (); 224 misunderstoodHeaders.addElement(header); 225 } 226 } 227 228 SOAPConstants soapConstants = msgContext.getSOAPConstants(); 229 232 if (misunderstoodHeaders != null) 233 { 234 AxisFault fault = 235 new AxisFault(soapConstants.getMustunderstandFaultQName(), 236 null, null, 237 null, null, 238 null); 239 240 StringBuffer whatWasMissUnderstood = new StringBuffer (256); 241 242 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) 244 { 245 en = misunderstoodHeaders.elements(); 246 while (en.hasMoreElements()) 247 { 248 SOAPHeaderElementAxisImpl badHeader = (SOAPHeaderElementAxisImpl)en. 249 nextElement(); 250 QName badQName = new QName (badHeader.getNamespaceURI(), 251 badHeader.getName()); 252 253 if (whatWasMissUnderstood.length() != 0) whatWasMissUnderstood.append(", "); 254 whatWasMissUnderstood.append(badQName.toString()); 255 256 SOAPHeaderElementAxisImpl newHeader = new 257 SOAPHeaderElementAxisImpl(Constants.URI_SOAP12_ENV, 258 Constants.ELEM_NOTUNDERSTOOD); 259 newHeader.addAttribute(null, 260 Constants.ATTR_QNAME, 261 badQName); 262 263 fault.addHeader(newHeader); 264 } 265 } 266 267 fault.setFaultString(Messages.getMessage("noUnderstand00", 268 whatWasMissUnderstood.toString())); 269 270 throw fault; 271 } 272 } 273 } 274 275 278 public SOAPService() 279 { 280 setOptionsLockable(true); 281 initHashtable(); 282 283 actors.add(""); 285 } 286 287 292 public SOAPService(Handler reqHandler, Handler pivHandler, 293 Handler respHandler) 294 { 295 this(); 296 init(reqHandler, null, pivHandler, new SOAPResponseHandler(), respHandler); 297 } 298 299 public TypeMappingRegistry getTypeMappingRegistry() 300 { 301 return serviceDescription.getTypeMappingRegistry(); 302 } 303 304 308 public SOAPService(Handler serviceHandler) 309 { 310 init(null, null, serviceHandler, new SOAPResponseHandler(), null); 311 } 312 313 316 public void setEngine(AxisEngine engine) 317 { 318 if (engine == null) 319 throw new IllegalArgumentException (Messages.getMessage("nullEngine")); 320 321 this.engine = engine; 322 getTypeMappingRegistry().delegate(engine.getTypeMappingRegistry()); 323 } 324 325 public AxisEngine getEngine() 326 { 327 return engine; 328 } 329 330 public boolean availableFromTransport(String transportName) 331 { 332 if (validTransports != null) 333 { 334 for (int i = 0; i < validTransports.size(); i++) 335 { 336 if (validTransports.elementAt(i).equals(transportName)) 337 return true; 338 } 339 return false; 340 } 341 342 return true; 343 } 344 345 public Style getStyle() 346 { 347 return serviceDescription.getStyle(); 348 } 349 350 public void setStyle(Style style) 351 { 352 serviceDescription.setStyle(style); 353 } 354 355 public Use getUse() 356 { 357 return serviceDescription.getUse(); 358 } 359 360 public void setUse(Use style) 361 { 362 serviceDescription.setUse(style); 363 } 364 365 public ServiceDesc getServiceDescription() 366 { 367 return serviceDescription; 368 } 369 370 374 public synchronized ServiceDesc getInitializedServiceDesc(MessageContext msgContext) 375 throws AxisFault 376 { 377 378 if (serviceDescription.getImplClass() == null) 379 { 380 381 if (pivotHandler instanceof BasicProvider) 387 { 388 ((BasicProvider)pivotHandler).initServiceDesc(this, msgContext); 389 } 390 391 } 392 393 return serviceDescription; 394 } 395 396 public void setServiceDescription(ServiceDesc serviceDescription) 397 { 398 if (serviceDescription == null) 399 { 400 return; 402 } 403 this.serviceDescription = serviceDescription; 404 } 405 406 public void setPropertyParent(Hashtable parent) 407 { 408 if (options == null) 409 { 410 options = new LockableHashtable(); 411 } 412 ((LockableHashtable)options).setParent(parent); 413 } 414 415 421 public void generateWSDL(MessageContext msgContext) throws AxisFault 422 { 423 if (serviceDescription == null || 424 serviceDescription.getWSDLFile() == null) 425 { 426 super.generateWSDL(msgContext); 427 return; 428 } 429 InputStream instream = null; 430 431 try 433 { 434 String filename = serviceDescription.getWSDLFile(); 435 File file = new File (filename); 436 if (file.exists()) 437 { 438 instream = new FileInputStream (filename); 440 } 441 else 442 { 443 ClassLoader classLoader = msgContext.getClassLoader(); 445 if (classLoader == null) 446 classLoader = getClass().getClassLoader(); 447 448 instream = classLoader.getResourceAsStream(filename); 449 if (instream == null) 450 { 451 String errorText = Messages.getMessage("wsdlFileMissing", filename); 452 throw new AxisFault(errorText); 453 } 454 } 455 Document doc = XMLUtils.newDocument(instream); 456 msgContext.setProperty("WSDL", doc); 457 } 458 catch (Exception e) 459 { 460 throw AxisFault.makeFault(e); 461 } 462 finally 463 { 464 if (instream != null) 465 { 466 try 467 { 468 instream.close(); 469 } 470 catch (IOException e) 471 { 472 } 473 } 474 } 475 } 476 484 485 488 public void start() 489 { 490 } 491 492 495 public void stop() 496 { 497 } 498 499 502 public void enableTransport(String transportName) 503 { 504 if (log.isDebugEnabled()) 505 { 506 log.debug(Messages.getMessage("enableTransport00", "" + this, transportName)); 507 } 508 509 if (validTransports == null) 510 validTransports = new Vector (); 511 validTransports.addElement(transportName); 512 } 513 514 517 public void disableTransport(String transportName) 518 { 519 if (validTransports != null) 520 { 521 validTransports.removeElement(transportName); 522 } 523 } 524 525 public boolean needsHighFidelityRecording() 526 { 527 return highFidelityRecording; 528 } 529 530 public void setHighFidelityRecording(boolean highFidelityRecording) 531 { 532 this.highFidelityRecording = highFidelityRecording; 533 } 534 535 public int getSendType() 537 { 538 return sendType; 539 } 540 541 public void setSendType(int sendType) 542 { 543 this.sendType = sendType; 544 } 545 546 public void invoke(MessageContext msgContext) throws AxisFault 547 { 548 HandlerInfoChainFactory handlerFactory = (HandlerInfoChainFactory)this.getOption(Constants.ATTR_HANDLERINFOCHAIN); 549 HandlerChainImpl handlerImpl = null; 550 if (handlerFactory != null) handlerImpl = (HandlerChainImpl)handlerFactory.createHandlerChain(); 551 boolean result = true; 552 553 if (handlerImpl != null) 554 { 555 result = handlerImpl.handleRequest(msgContext); 556 } 557 558 if (result) 559 { 560 super.invoke(msgContext); 561 } 562 else 563 { 564 msgContext.setPastPivot(true); 565 } 566 567 if (handlerImpl != null) 568 { 569 handlerImpl.handleResponse(msgContext); 570 handlerImpl.destroy(); 571 } 572 } 573 } 574 | Popular Tags |