1 55 package org.jboss.axis.deployment.wsdd; 56 57 import org.jboss.axis.AxisEngine; 58 import org.jboss.axis.AxisFault; 59 import org.jboss.axis.ConfigurationException; 60 import org.jboss.axis.Constants; 61 import org.jboss.axis.EngineConfiguration; 62 import org.jboss.axis.FaultableHandler; 63 import org.jboss.axis.Handler; 64 import org.jboss.axis.MessageContext; 65 import org.jboss.axis.attachments.Attachments; 66 import org.jboss.axis.attachments.AttachmentsImpl; 67 import org.jboss.axis.description.ServiceDesc; 68 import org.jboss.axis.encoding.DeserializerFactory; 69 import org.jboss.axis.encoding.SerializationContext; 70 import org.jboss.axis.encoding.SerializerFactory; 71 import org.jboss.axis.encoding.TypeMapping; 72 import org.jboss.axis.encoding.TypeMappingRegistry; 73 import org.jboss.axis.encoding.TypeMappingRegistryImpl; 74 import org.jboss.axis.encoding.ser.BaseDeserializerFactory; 75 import org.jboss.axis.encoding.ser.BaseSerializerFactory; 76 import org.jboss.axis.enums.Style; 77 import org.jboss.axis.enums.Use; 78 import org.jboss.axis.handlers.HandlerInfoChainFactory; 79 import org.jboss.axis.handlers.soap.SOAPService; 80 import org.jboss.axis.providers.java.JavaProvider; 81 import org.jboss.axis.utils.Messages; 82 import org.jboss.axis.utils.XMLUtils; 83 import org.jboss.logging.Logger; 84 import org.w3c.dom.Element ; 85 import org.xml.sax.helpers.AttributesImpl ; 86 87 import javax.xml.namespace.QName ; 88 import java.io.IOException ; 89 import java.util.ArrayList ; 90 import java.util.StringTokenizer ; 91 import java.util.Vector ; 92 93 98 public class WSDDService 99 extends WSDDTargetedChain 100 implements WSDDTypeMappingContainer 101 { 102 103 private static Logger log = Logger.getLogger(WSDDService.class.getName()); 104 105 private TypeMappingRegistry tmr = null; 106 107 private Vector faultFlows = new Vector (); 108 private Vector typeMappings = new Vector (); 109 private Vector operations = new Vector (); 110 111 114 private Vector namespaces = new Vector (); 115 116 private String descriptionURL; 117 118 121 private Style style = Style.DEFAULT; 122 125 private Use use = Use.DEFAULT; 126 127 private SOAPService cachedService = null; 128 129 133 private QName providerQName; 134 135 private WSDDJAXRPCHandlerInfoChain _wsddHIchain; 137 138 ServiceDesc desc = new ServiceDesc(); 139 140 144 private boolean streaming = false; 145 146 149 private int sendType = Attachments.SEND_TYPE_NOTSET; 150 151 154 public WSDDService() 155 { 156 } 157 158 162 public WSDDService(Element e) 163 throws WSDDException 164 { 165 super(e); 166 167 desc.setName(getQName().getLocalPart()); 168 169 String styleStr = e.getAttribute(ATTR_STYLE); 170 if (styleStr != null && !styleStr.equals("")) 171 { 172 style = Style.getStyle(styleStr, Style.DEFAULT); 173 desc.setStyle(style); 174 providerQName = style.getProvider(); 175 } 176 177 String useStr = e.getAttribute(ATTR_USE); 178 if (useStr != null && !useStr.equals("")) 179 { 180 use = Use.getUse(useStr, Use.DEFAULT); 181 desc.setUse(use); 182 } 183 else 184 { 185 if (style != Style.RPC) 186 { 187 use = Use.LITERAL; 189 desc.setUse(use); 190 } 191 } 192 193 String streamStr = e.getAttribute(ATTR_STREAMING); 194 if (streamStr != null && streamStr.equals("on")) 195 { 196 streaming = true; 197 } 198 199 String attachmentStr = e.getAttribute(ATTR_ATTACHMENT_FORMAT); 200 if (attachmentStr != null && !attachmentStr.equals("")) 201 { 202 sendType = AttachmentsImpl.getSendType(attachmentStr); 203 } 204 205 Element [] operationElements = getChildElements(e, ELEM_WSDD_OPERATION); 206 for (int i = 0; i < operationElements.length; i++) 207 { 208 WSDDOperation operation = new WSDDOperation(operationElements[i], 209 desc); 210 addOperation(operation); 211 } 212 213 Element [] typeMappingElements = getChildElements(e, ELEM_WSDD_TYPEMAPPING); 214 for (int i = 0; i < typeMappingElements.length; i++) 215 { 216 WSDDTypeMapping mapping = 217 new WSDDTypeMapping(typeMappingElements[i]); 218 typeMappings.add(mapping); 219 } 220 221 Element [] beanMappingElements = getChildElements(e, ELEM_WSDD_BEANMAPPING); 222 for (int i = 0; i < beanMappingElements.length; i++) 223 { 224 WSDDBeanMapping mapping = 225 new WSDDBeanMapping(beanMappingElements[i]); 226 typeMappings.add(mapping); 227 } 228 229 Element [] namespaceElements = getChildElements(e, ELEM_WSDD_NAMESPACE); 230 for (int i = 0; i < namespaceElements.length; i++) 231 { 232 String ns = XMLUtils.getChildCharacterData(namespaceElements[i]); 234 namespaces.add(ns); 235 } 236 if (!namespaces.isEmpty()) 237 desc.setNamespaceMappings(namespaces); 238 239 Element wsdlElem = getChildElement(e, ELEM_WSDD_WSDLFILE); 240 if (wsdlElem != null) 241 { 242 String fileName = XMLUtils.getChildCharacterData(wsdlElem); 243 desc.setWSDLFile(fileName); 244 } 245 246 Element urlElem = getChildElement(e, ELEM_WSDD_ENDPOINTURL); 247 if (urlElem != null) 248 { 249 String endpointURL = XMLUtils.getChildCharacterData(urlElem); 250 desc.setEndpointURL(endpointURL); 251 } 252 253 String providerStr = e.getAttribute(ATTR_PROVIDER); 254 if (providerStr != null && !providerStr.equals("")) 255 { 256 providerQName = XMLUtils.getQNameFromString(providerStr, e); 257 if (WSDDConstants.QNAME_JAVAMSG_PROVIDER.equals(providerQName)) 258 { 259 desc.setStyle(Style.MESSAGE); 261 } 262 } 263 264 Element hcEl = getChildElement(e, ELEM_WSDD_JAXRPC_CHAIN); 266 if (hcEl != null) 267 { 268 _wsddHIchain = new WSDDJAXRPCHandlerInfoChain(hcEl); 269 } 270 271 initTMR(); 273 274 validateDescriptors(); 276 } 277 278 285 protected void initTMR() throws WSDDException 286 { 287 if (tmr == null) 290 { 291 tmr = new TypeMappingRegistryImpl(); 292 for (int i = 0; i < typeMappings.size(); i++) 293 { 294 deployTypeMapping((WSDDTypeMapping) 295 typeMappings.get(i)); 296 } 297 } 298 } 299 300 301 306 public void validateDescriptors() throws WSDDException 307 { 308 if (tmr == null) 309 { 310 initTMR(); 311 } 312 desc.setTypeMappingRegistry(tmr); 313 desc.setTypeMapping(getTypeMapping(desc.getUse().getEncoding())); 314 315 String allowedMethods = getParameter(JavaProvider.OPTION_ALLOWEDMETHODS); 316 if (allowedMethods != null && !"*".equals(allowedMethods)) 317 { 318 ArrayList methodList = new ArrayList (); 319 StringTokenizer tokenizer = new StringTokenizer (allowedMethods, " ,"); 320 while (tokenizer.hasMoreTokens()) 321 { 322 methodList.add(tokenizer.nextToken()); 323 } 324 desc.setAllowedMethods(methodList); 325 } 326 } 327 328 333 public void addTypeMapping(WSDDTypeMapping mapping) 334 { 335 typeMappings.add(mapping); 336 } 337 338 343 public void addOperation(WSDDOperation operation) 344 { 345 operations.add(operation); 346 desc.addOperationDesc(operation.getOperationDesc()); 347 } 348 349 protected QName getElementName() 350 { 351 return QNAME_SERVICE; 352 } 353 354 360 public String getServiceDescriptionURL() 361 { 362 return descriptionURL; 363 } 364 365 370 public void setServiceDescriptionURL(String sdUrl) 371 { 372 descriptionURL = sdUrl; 373 } 374 375 public QName getProviderQName() 376 { 377 return providerQName; 378 } 379 380 public void setProviderQName(QName providerQName) 381 { 382 this.providerQName = providerQName; 383 } 384 385 public ServiceDesc getServiceDesc() 386 { 387 return desc; 388 } 389 390 393 public Style getStyle() 394 { 395 return style; 396 } 397 398 401 public void setStyle(Style style) 402 { 403 this.style = style; 404 } 405 406 409 public Use getUse() 410 { 411 return use; 412 } 413 414 417 public void setUse(Use use) 418 { 419 this.use = use; 420 } 421 422 425 public WSDDFaultFlow[] getFaultFlows() 426 { 427 WSDDFaultFlow[] t = new WSDDFaultFlow[faultFlows.size()]; 428 faultFlows.toArray(t); 429 return t; 430 } 431 432 438 public Vector getNamespaces() 439 { 440 return namespaces; 441 } 442 443 447 public WSDDFaultFlow getFaultFlow(QName name) 448 { 449 WSDDFaultFlow[] t = getFaultFlows(); 450 451 for (int n = 0; n < t.length; n++) 452 { 453 if (t[n].getQName().equals(name)) 454 { 455 return t[n]; 456 } 457 } 458 459 return null; 460 } 461 462 467 public Handler makeNewInstance(EngineConfiguration registry) 468 throws ConfigurationException 469 { 470 if (cachedService != null) 471 { 472 return cachedService; 473 } 474 475 initTMR(); 477 478 Handler reqHandler = null; 479 WSDDChain request = getRequestFlow(); 480 481 if (request != null) 482 { 483 reqHandler = request.getInstance(registry); 484 } 485 486 Handler providerHandler = null; 487 488 if (providerQName != null) 489 { 490 try 491 { 492 providerHandler = WSDDProvider.getInstance(providerQName, 493 this, 494 registry); 495 } 496 catch (Exception e) 497 { 498 throw new ConfigurationException(e); 499 } 500 if (providerHandler == null) 501 throw new WSDDException(Messages.getMessage("couldntConstructProvider00")); 502 } 503 504 Handler respHandler = null; 505 WSDDChain response = getResponseFlow(); 506 507 if (response != null) 508 { 509 respHandler = response.getInstance(registry); 510 } 511 512 SOAPService service = new SOAPService(reqHandler, providerHandler, 513 respHandler); 514 service.setStyle(style); 515 service.setUse(use); 516 service.setHighFidelityRecording(!streaming); 517 service.setSendType(sendType); 518 519 if (getQName() != null) 520 service.setName(getQName().getLocalPart()); 521 service.setOptions(getParametersTable()); 522 523 service.setEngine(((WSDDDeployment)registry).getEngine()); 524 525 if (use != Use.ENCODED) 526 { 527 service.setOption(AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE); 530 service.setOption(AxisEngine.PROP_SEND_XSI, Boolean.FALSE); 531 } 532 533 if (_wsddHIchain != null) 535 { 536 HandlerInfoChainFactory hiChainFactory = _wsddHIchain.getHandlerChainFactory(); 537 538 service.setOption(Constants.ATTR_HANDLERINFOCHAIN, hiChainFactory); 539 } 540 541 AxisEngine.normaliseOptions(service); 542 tmr.delegate(registry.getTypeMappingRegistry()); 543 544 WSDDFaultFlow[] faultFlows = getFaultFlows(); 545 if (faultFlows != null && faultFlows.length > 0) 546 { 547 FaultableHandler wrapper = new FaultableHandler(service); 548 for (int i = 0; i < faultFlows.length; i++) 549 { 550 WSDDFaultFlow flow = faultFlows[i]; 551 Handler faultHandler = flow.getInstance(registry); 552 wrapper.setOption("fault-" + flow.getQName().getLocalPart(), 553 faultHandler); 554 } 555 } 556 557 service.setServiceDescription(desc); 558 try 559 { 560 service.getInitializedServiceDesc(MessageContext.getCurrentContext()); 561 } 562 catch (AxisFault axisFault) 563 { 564 throw new ConfigurationException(axisFault); 565 } 566 567 cachedService = service; 568 return service; 569 } 570 571 public void deployTypeMapping(WSDDTypeMapping mapping) 572 throws WSDDException 573 { 574 if (!typeMappings.contains(mapping)) 575 { 576 typeMappings.add(mapping); 577 } 578 if (tmr == null) 579 { 580 tmr = new TypeMappingRegistryImpl(); 581 } 582 try 583 { 584 String encodingStyle = mapping.getEncodingStyle(); 587 if (encodingStyle == null) 588 { 589 encodingStyle = use.getEncoding(); 590 } 591 TypeMapping tm = tmr.getOrMakeTypeMapping(encodingStyle); 592 desc.setTypeMappingRegistry(tmr); 593 desc.setTypeMapping(tm); 594 595 SerializerFactory ser = null; 596 DeserializerFactory deser = null; 597 598 if (mapping.getSerializerName() != null && 607 !mapping.getSerializerName().equals("")) 608 { 609 ser = BaseSerializerFactory.createFactory(mapping.getSerializer(), 610 mapping.getLanguageSpecificType(), 611 mapping.getQName()); 612 } 613 614 if (mapping.getDeserializerName() != null && 615 !mapping.getDeserializerName().equals("")) 616 { 617 deser = BaseDeserializerFactory.createFactory(mapping.getDeserializer(), 618 mapping.getLanguageSpecificType(), 619 mapping.getQName()); 620 } 621 tm.register(mapping.getLanguageSpecificType(), mapping.getQName(), ser, deser); 622 } 623 catch (ClassNotFoundException e) 624 { 625 log.error(Messages.getMessage("unabletoDeployTypemapping00", "" + mapping.getQName()), e); 626 throw new WSDDNonFatalException(e); 627 } 628 catch (Exception e) 629 { 630 throw new WSDDException(e); 631 } 632 } 633 634 637 public void writeToContext(SerializationContext context) 638 throws IOException 639 { 640 AttributesImpl attrs = new AttributesImpl (); 641 QName name = getQName(); 642 if (name != null) 643 { 644 attrs.addAttribute("", ATTR_NAME, ATTR_NAME, 645 "CDATA", context.qName2String(name)); 646 } 647 if (providerQName != null) 648 { 649 attrs.addAttribute("", ATTR_PROVIDER, ATTR_PROVIDER, 650 "CDATA", context.qName2String(providerQName)); 651 } 652 if (style != Style.DEFAULT) 653 { 654 attrs.addAttribute("", ATTR_STYLE, ATTR_STYLE, 655 "CDATA", style.getName()); 656 } 657 658 if (use != Use.DEFAULT) 659 { 660 attrs.addAttribute("", ATTR_USE, ATTR_USE, 661 "CDATA", use.getName()); 662 } 663 664 if (streaming) 665 { 666 attrs.addAttribute("", ATTR_STREAMING, ATTR_STREAMING, 667 "CDATA", "on"); 668 } 669 670 if (sendType != Attachments.SEND_TYPE_NOTSET) 671 { 672 attrs.addAttribute("", ATTR_ATTACHMENT_FORMAT, 673 ATTR_ATTACHMENT_FORMAT, "CDATA", 674 AttachmentsImpl.getSendTypeString(sendType)); 675 } 676 context.startElement(WSDDConstants.QNAME_SERVICE, attrs); 677 678 if (desc.getWSDLFile() != null) 679 { 680 context.startElement(QNAME_WSDLFILE, null); 681 context.writeSafeString(desc.getWSDLFile()); 682 context.endElement(); 683 } 684 685 for (int i = 0; i < operations.size(); i++) 686 { 687 WSDDOperation operation = (WSDDOperation)operations.elementAt(i); 688 operation.writeToContext(context); 689 } 690 writeFlowsToContext(context); 691 writeParamsToContext(context); 692 693 694 for (int i = 0; i < typeMappings.size(); i++) 695 { 696 ((WSDDTypeMapping)typeMappings.elementAt(i)).writeToContext(context); 697 } 698 699 for (int i = 0; i < namespaces.size(); i++) 700 { 701 context.startElement(QNAME_NAMESPACE, null); 702 context.writeString((String )namespaces.get(i)); 703 context.endElement(); 704 } 705 706 String endpointURL = desc.getEndpointURL(); 707 if (endpointURL != null) 708 { 709 context.startElement(QNAME_ENDPOINTURL, null); 710 context.writeSafeString(endpointURL); 711 context.endElement(); 712 } 713 714 if (_wsddHIchain != null) 715 { 716 _wsddHIchain.writeToContext(context); 717 718 } 719 720 context.endElement(); 721 722 723 } 724 725 public void setCachedService(SOAPService service) 726 { 727 cachedService = service; 728 } 729 730 public Vector getTypeMappings() 731 { 732 return typeMappings; 733 } 734 735 public void setTypeMappings(Vector typeMappings) 736 { 737 this.typeMappings = typeMappings; 738 } 739 740 public void deployToRegistry(WSDDDeployment registry) 741 { 742 registry.addService(this); 743 744 registry.registerNamespaceForService(getQName().getLocalPart(), this); 747 748 for (int i = 0; i < namespaces.size(); i++) 749 { 750 String namespace = (String )namespaces.elementAt(i); 751 registry.registerNamespaceForService(namespace, this); 752 } 753 754 super.deployToRegistry(registry); 755 } 756 757 public void removeNamespaceMappings(WSDDDeployment registry) 758 { 759 for (int i = 0; i < namespaces.size(); i++) 760 { 761 String namespace = (String )namespaces.elementAt(i); 762 registry.removeNamespaceMapping(namespace); 763 } 764 registry.removeNamespaceMapping(getQName().getLocalPart()); 765 } 766 767 public TypeMapping getTypeMapping(String encodingStyle) 768 { 769 if (tmr == null) 771 { 772 return null; 773 } 774 return (TypeMapping)tmr.getTypeMapping(encodingStyle); 775 } 776 777 778 public WSDDJAXRPCHandlerInfoChain getHandlerInfoChain() 779 { 780 return _wsddHIchain; 781 } 782 783 public void setHandlerInfoChain(WSDDJAXRPCHandlerInfoChain hichain) 784 { 785 _wsddHIchain = hichain; 786 } 787 } 788 | Popular Tags |