1 23 24 package com.sun.enterprise.deployment; 25 26 32 33 34 import com.sun.enterprise.deployment.runtime.common.MessageSecurityBindingDescriptor; 35 import com.sun.enterprise.deployment.web.SecurityConstraint; 36 import com.sun.enterprise.deployment.web.UserDataConstraint; 37 import java.io.File ; 38 import java.net.MalformedURLException ; 39 import java.net.URL ; 40 import java.util.ArrayList ; 41 import java.util.Collection ; 42 import java.util.Iterator ; 43 import java.util.LinkedList ; 44 import java.util.List ; 45 import java.util.Set ; 46 import javax.servlet.http.HttpServletRequest ; 47 import javax.xml.ws.soap.SOAPBinding; 48 import javax.xml.namespace.QName ; 49 50 import com.sun.enterprise.deployment.types.HandlerChainContainer; 51 52 53 56 public class WebServiceEndpoint extends Descriptor 57 implements HandlerChainContainer { 58 59 public static final String TRANSPORT_NONE = "NONE"; 60 public static final String TRANSPORT_INTEGRAL = "INTEGRAL"; 61 public static final String TRANSPORT_CONFIDENTIAL = "CONFIDENTIAL"; 62 public static final String CLIENT_CERT = "CLIENT-CERT"; 63 64 private static final String PUBLISHING_SUBCONTEXT = 65 "__container$publishing$subctx"; 66 67 private String endpointName; 69 70 private String serviceEndpointInterface; 71 72 private QName wsdlPort; 73 private String wsdlPortNamespacePrefix; 74 75 private QName wsdlService; 76 private String wsdlServiceNamespacePrefix; 77 78 private String mtomEnabled = null; 79 80 private String protocolBinding = null; 81 82 private String ejbLink; 85 private EjbDescriptor ejbComponentImpl; 86 private String webComponentLink; 87 private WebComponentDescriptor webComponentImpl; 88 89 private LinkedList handlers; 93 94 private LinkedList <WebServiceHandlerChain> handlerChains; 96 97 private WebService webService; 99 100 104 private String endpointAddressUri; 132 133 private String authMethod; 139 140 private String realm; 143 144 private String transportGuarantee; 146 147 private String serviceNamespaceUri; 150 private String serviceLocalPart; 151 152 private String servletImplClass; 156 157 private String tieClassName; 159 160 private MessageSecurityBindingDescriptor messageSecBindingDesc = null; 162 163 private String debuggingEnabled = "true"; 165 166 private List props = null; 168 169 public WebServiceEndpoint(WebServiceEndpoint other) { 171 super(other); 172 endpointName = other.endpointName; serviceEndpointInterface = other.serviceEndpointInterface; wsdlPort = other.wsdlPort; wsdlPortNamespacePrefix = other.wsdlPortNamespacePrefix; 176 wsdlService = other.wsdlService; 177 wsdlServiceNamespacePrefix = other.wsdlServiceNamespacePrefix; 178 mtomEnabled = other.mtomEnabled; 179 protocolBinding = other.protocolBinding; 180 ejbLink = other.ejbLink; ejbComponentImpl = other.ejbComponentImpl; webComponentLink = other.webComponentLink; webComponentImpl = other.webComponentImpl; handlers = other.handlers; if (other.handlers != null) { 186 handlers = new LinkedList (); 187 for (Iterator i = other.handlers.iterator(); i.hasNext();) { 188 WebServiceHandler wsh = (WebServiceHandler)i.next(); 189 handlers.addLast(new WebServiceHandler(wsh)); 190 } 191 } else { 192 handlers = null; 193 } 194 if (other.handlerChains!= null) { 195 handlerChains = new LinkedList (); 196 for (Iterator i = other.handlerChains.iterator(); i.hasNext();) { 197 WebServiceHandlerChain wsh = (WebServiceHandlerChain)i.next(); 198 handlerChains.addLast(new WebServiceHandlerChain(wsh)); 199 } 200 } else { 201 handlers = null; 202 } 203 204 webService = other.webService; endpointAddressUri = other.endpointAddressUri; authMethod = other.authMethod; transportGuarantee = other.transportGuarantee; serviceNamespaceUri = other.serviceNamespaceUri; serviceLocalPart = other.serviceLocalPart; servletImplClass = other.servletImplClass; tieClassName = other.tieClassName; } 213 214 public WebServiceEndpoint() { 215 handlers = new LinkedList (); 216 handlerChains = new LinkedList (); 217 authMethod = null; 218 wsdlPort = null; 219 } 220 221 public void setWebService(WebService service) { 222 webService = service; 223 super.changed(); 224 } 225 226 public WebService getWebService() { 227 return webService; 228 } 229 230 public void setEndpointName(String name) { 231 endpointName = name; 232 super.changed(); 233 } 234 235 public String getEndpointName() { 236 return endpointName; 237 } 238 239 public void setServiceEndpointInterface(String endpointInterface) { 240 serviceEndpointInterface = endpointInterface; 241 super.changed(); 242 } 243 244 public String getServiceEndpointInterface() { 245 return serviceEndpointInterface; 246 } 247 248 public void setProtocolBinding(String value) { 249 protocolBinding = value; 250 super.changed(); 251 } 252 253 public String getProtocolBinding() { 254 return ((protocolBinding==null) ? 255 javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING : protocolBinding); 256 } 257 258 public boolean hasUserSpecifiedProtocolBinding() { 259 return ((protocolBinding==null) ? false : true); 260 } 261 262 public void setMtomEnabled(String value) { 263 mtomEnabled =value; 264 super.changed(); 265 } 266 267 public String getMtomEnabled() { 268 return mtomEnabled; 269 } 270 271 public void setWsdlService(QName svc, String prefix) { 272 wsdlService = svc; 273 wsdlServiceNamespacePrefix = prefix; 274 serviceNamespaceUri = svc.getNamespaceURI(); 275 serviceLocalPart = svc.getLocalPart(); 276 super.changed(); 277 } 278 279 public void setWsdlService(QName service) { 280 wsdlService = service; 281 wsdlServiceNamespacePrefix = service.getPrefix(); 282 serviceNamespaceUri = service.getNamespaceURI(); 283 serviceLocalPart = service.getLocalPart(); 284 super.changed(); 285 } 286 287 public String getWsdlServiceNamespacePrefix() { 288 return wsdlServiceNamespacePrefix; 289 } 290 291 public boolean hasWsdlServiceNamespacePrefix() { 292 return (wsdlServiceNamespacePrefix != null); 293 } 294 295 public QName getWsdlService() { 296 return wsdlService; 297 } 298 299 public void setWsdlPort(QName port, String prefix) { 300 wsdlPort = port; 301 wsdlPortNamespacePrefix = prefix; 302 super.changed(); 303 } 304 305 public void setWsdlPort(QName port) { 306 wsdlPort = port; 307 wsdlPortNamespacePrefix = port.getPrefix(); 308 super.changed(); 309 } 310 311 public String getWsdlPortNamespacePrefix() { 312 return wsdlPortNamespacePrefix; 313 } 314 315 public boolean hasWsdlPortNamespacePrefix() { 316 return (wsdlPortNamespacePrefix != null); 317 } 318 319 public boolean hasWsdlPort() { 320 return (wsdlPort != null); 321 } 322 323 public QName getWsdlPort() { 324 return wsdlPort; 325 } 326 327 public void setMessageSecurityBinding( 328 MessageSecurityBindingDescriptor messageSecBindingDesc) { 329 this.messageSecBindingDesc = messageSecBindingDesc; 330 } 331 332 public MessageSecurityBindingDescriptor getMessageSecurityBinding() { 333 return messageSecBindingDesc; 334 } 335 336 337 341 public boolean resolveComponentLink() { 342 boolean resolved = false; 343 if( ejbLink != null ) { 344 EjbBundleDescriptor ejbBundle = getEjbBundle(); 345 if( ejbBundle.hasEjbByName(ejbLink) ) { 346 resolved = true; 347 EjbDescriptor ejb = ejbBundle.getEjbByName(ejbLink); 348 setEjbComponentImpl(ejb); 349 } 350 } else if( webComponentLink != null ) { 351 WebBundleDescriptor webBundle = getWebBundle(); 352 WebComponentDescriptor webComponent = 353 (WebComponentDescriptor) webBundle. 354 getWebComponentByCanonicalName(webComponentLink); 355 if( webComponent != null ) { 356 resolved = true; 357 setWebComponentImpl(webComponent); 358 } 359 } 360 super.changed(); 361 return resolved; 362 } 363 364 public BundleDescriptor getBundleDescriptor() { 365 return getWebService().getBundleDescriptor(); 366 } 367 368 private EjbBundleDescriptor getEjbBundle() { 369 return (EjbBundleDescriptor) getBundleDescriptor(); 370 } 371 372 private WebBundleDescriptor getWebBundle() { 373 return (WebBundleDescriptor) getBundleDescriptor(); 374 } 375 376 379 public boolean implementedByEjbComponent() { 380 return (ejbLink != null); 381 } 382 383 386 public boolean implementedByEjbComponent(EjbDescriptor ejb) { 387 return (ejbLink != null) && ejbLink.equals(ejb.getName()); 388 } 389 390 393 public boolean implementedByWebComponent() { 394 return (webComponentLink != null); 395 } 396 397 400 public boolean implementedByWebComponent(WebComponentDescriptor webComp) { 401 return ( (webComponentLink != null) && 402 (webComponentLink.equals(webComp.getCanonicalName())) ); 403 } 404 405 public String getLinkName() { 406 String linkName = null; 407 if( implementedByEjbComponent() ) { 408 linkName = ejbLink; 409 } else if( implementedByWebComponent() ) { 410 linkName = webComponentLink; 411 } 412 return linkName; 413 } 414 415 public void setEjbLink(String link) { 416 ejbLink = link; 417 super.changed(); 418 } 419 420 public String getEjbLink() { 421 return ejbLink; 422 } 423 424 public void setEjbComponentImpl(EjbDescriptor ejbComponent) { 425 webComponentImpl = null; 426 webComponentLink = null; 427 428 ejbLink = ejbComponent.getName(); 429 ejbComponentImpl = ejbComponent; 430 super.changed(); 431 } 432 433 public EjbDescriptor getEjbComponentImpl() { 434 return ejbComponentImpl; 435 } 436 437 public void setWebComponentLink(String link) { 438 webComponentLink = link; 439 super.changed(); 440 } 441 442 public String getWebComponentLink() { 443 return webComponentLink; 444 } 445 446 public void setWebComponentImpl(WebComponentDescriptor webComponent) { 447 ejbComponentImpl = null; 448 ejbLink = null; 449 webComponentLink = webComponent.getCanonicalName(); 450 webComponentImpl = webComponent; 451 super.changed(); 452 } 453 454 public WebComponentDescriptor getWebComponentImpl() { 455 return webComponentImpl; 456 } 457 458 462 public boolean hasHandlers() { 463 return ( handlers.size() > 0 ); 464 } 465 466 469 public void addHandler(WebServiceHandler handler) { 470 handlers.addLast(handler); 471 super.changed(); 472 } 473 474 public void removeHandler(WebServiceHandler handler) { 475 handlers.remove(handler); 476 super.changed(); 477 } 478 479 public void removeHandlerByName(String handlerName) { 480 for(Iterator iter = handlers.iterator(); iter.hasNext();) { 481 WebServiceHandler next = (WebServiceHandler) iter.next(); 482 if( next.getHandlerName().equals(handlerName) ) { 483 iter.remove(); 484 super.changed(); 485 break; 486 } 487 } 488 } 489 490 493 public LinkedList getHandlers() { 494 return handlers; 495 } 496 497 500 public LinkedList <WebServiceHandlerChain> getHandlerChain() { 501 return handlerChains; 502 } 503 504 507 public boolean hasHandlerChain() { 508 return ( handlerChains.size() > 0 ); 509 } 510 511 514 public void addHandlerChain(WebServiceHandlerChain handlerChain) { 515 handlerChains.addLast(handlerChain); 516 super.changed(); 517 } 518 519 public void removeHandlerChain(WebServiceHandlerChain handlerChain) { 520 handlerChains.remove(handlerChain); 521 super.changed(); 522 } 523 524 528 public boolean hasEndpointAddressUri() { 529 return (endpointAddressUri != null); 530 } 531 532 public void setEndpointAddressUri(String uri) { 533 endpointAddressUri = uri; 534 super.changed(); 535 } 536 537 public String getEndpointAddressUri() { 538 return endpointAddressUri; 539 } 540 541 public boolean isSecure() { 542 return ( hasTransportGuarantee() && 543 (transportGuarantee.equals(TRANSPORT_INTEGRAL) || 544 transportGuarantee.equals(TRANSPORT_CONFIDENTIAL)) ); 545 } 546 547 552 public URL composeEndpointAddress(URL root) 553 throws MalformedURLException { 554 555 String uri = null; 556 557 if( implementedByWebComponent() ) { 562 if (endpointAddressUri == null) { 563 updateServletEndpointRuntime(); 564 } 565 566 WebBundleDescriptor webBundle = 569 webComponentImpl.getWebBundleDescriptor(); 570 String contextRoot = webBundle.getContextRoot(); 571 572 if( contextRoot != null ) { 573 if( !contextRoot.startsWith("/") ) { 574 contextRoot = "/" + contextRoot; 575 } 576 577 uri = contextRoot + 578 (endpointAddressUri.startsWith("/") ? 579 endpointAddressUri : ("/" + endpointAddressUri)); 580 } 581 } else { 582 if( hasEndpointAddressUri() ) { 583 uri = endpointAddressUri.startsWith("/") ? 584 endpointAddressUri : ("/" + endpointAddressUri); 585 } else { 586 uri = "/" + getWebService().getName() + "/" + 588 getEndpointName(); 589 setEndpointAddressUri(uri); 590 } 591 } 592 593 URL endpointAddressURL = 594 new URL (root.getProtocol(), root.getHost(), root.getPort(), uri); 595 596 return endpointAddressURL; 597 } 598 599 603 public URL composeFinalWsdlUrl(URL root) throws MalformedURLException { 604 605 URL context = composeEndpointAddress(root); 611 String mainFile = context.getFile() + "/" + 612 PUBLISHING_SUBCONTEXT + "/" + webService.getWsdlFileUri(); 613 URL finalWsdlUrl = new URL (context.getProtocol(), context.getHost(), 614 context.getPort(), mainFile); 615 return finalWsdlUrl; 616 } 617 618 625 public String getPublishingUri() { 626 627 String uri = endpointAddressUri.startsWith("/") ? 628 endpointAddressUri.substring(1) : endpointAddressUri; 629 630 return uri + "/" + PUBLISHING_SUBCONTEXT; 631 } 632 633 639 public boolean matchesEjbPublishRequest(String requestUriRaw, String query) 640 { 641 String requestUri = (requestUriRaw.charAt(0) == '/') ? 643 requestUriRaw.substring(1) : requestUriRaw; 644 645 boolean matches = false; 646 647 if( query != null ) { 649 String toMatch = (endpointAddressUri.charAt(0) == '/') ? 650 endpointAddressUri.substring(1) : endpointAddressUri; 651 652 matches = (query.equalsIgnoreCase("WSDL") && 653 requestUri.equals(toMatch)); 654 } else { 655 String publishingUri = getPublishingUri() + "/"; 657 matches = requestUri.startsWith(publishingUri); 658 } 659 660 return matches; 661 } 662 663 668 public String getWsdlContentPath(String requestUri) { 669 670 String uri = (requestUri.charAt(0) == '/') ? requestUri.substring(1) : 672 requestUri; 673 674 String publishingUriRaw = getPublishingUri(); 677 678 String publishingRoot = null; 681 682 if( implementedByWebComponent() ) { 683 WebBundleDescriptor webBundle = 684 webComponentImpl.getWebBundleDescriptor(); 685 String contextRoot = webBundle.getContextRoot(); 686 if( contextRoot.startsWith("/") ) { 687 contextRoot = contextRoot.substring(1); 688 } 689 publishingRoot = contextRoot + "/" + 690 publishingUriRaw + "/"; 691 } else { 692 publishingRoot = publishingUriRaw + "/"; 693 } 694 695 String wsdlPath = uri.startsWith(publishingRoot) ? 696 uri.substring(publishingRoot.length()) : null; 697 698 return wsdlPath; 699 } 700 701 public void setAuthMethod(String authType) { 703 authMethod = authType; 704 super.changed(); 705 } 706 707 public String getAuthMethod() { 708 return authMethod; 709 } 710 711 public boolean hasAuthMethod() { 712 return (authMethod != null); 713 } 714 715 public boolean hasBasicAuth() { 716 return ( (authMethod != null) && 717 (authMethod.equals(HttpServletRequest.BASIC_AUTH)) ); 718 } 719 720 public boolean hasClientCertAuth() { 721 return ( (authMethod != null) && 722 (authMethod.equals(CLIENT_CERT)) ); 723 } 724 725 public void setRealm(String realm) { 726 this.realm = realm; 727 } 728 729 public String getRealm() { 730 return realm; 731 } 732 733 public void setTransportGuarantee(String guarantee) { 735 transportGuarantee = guarantee; 736 super.changed(); 737 } 738 739 public String getTransportGuarantee() { 740 return transportGuarantee; 741 } 742 743 public boolean hasTransportGuarantee() { 744 return (transportGuarantee != null); 745 } 746 747 public void setServiceNamespaceUri(String uri) { 748 serviceNamespaceUri = uri; 749 super.changed(); 750 } 751 752 public void setServiceLocalPart(String localpart) { 753 serviceLocalPart = localpart; 754 super.changed(); 755 } 756 757 public boolean hasServiceName() { 758 return ((serviceNamespaceUri != null) && (serviceLocalPart != null)); 759 } 760 761 764 public QName getServiceName() { 765 return hasServiceName() ? 768 new QName (serviceNamespaceUri, serviceLocalPart) : 769 null; 770 } 771 772 778 public void saveServletImplClass() { 779 if( implementedByWebComponent() ) { 780 servletImplClass = ((WebComponentDescriptor) webComponentImpl). 781 getWebComponentImplementation(); 782 } else { 783 throw new IllegalStateException ("requires ejb"); 784 } 785 super.changed(); 786 } 787 788 public boolean hasServletImplClass() { 789 return (servletImplClass != null); 790 } 791 792 public void setServletImplClass(String implClass) { 793 servletImplClass = implClass; 794 super.changed(); 795 } 796 797 public String getServletImplClass() { 798 return servletImplClass; 799 } 800 801 public boolean hasTieClassName() { 802 return (tieClassName != null); 803 } 804 805 public void setTieClassName(String tieClass) { 806 tieClassName = tieClass; 807 } 808 809 public String getTieClassName() { 810 return tieClassName; 811 } 812 813 public String getDebugging() { 814 return debuggingEnabled; 815 } 816 817 public void setDebugging(String debuggingEnabled) { 818 this.debuggingEnabled = debuggingEnabled; 819 } 820 821 public void addProperty(NameValuePairDescriptor newProp) { 822 if (props==null) { 823 props = new ArrayList (); 824 } 825 props.add(newProp); 826 } 827 828 public Iterator getProperties() { 829 if (props == null) { 830 return null; 831 } 832 return props.iterator(); 833 } 834 835 private void updateServletEndpointRuntime() { 836 837 saveServletImplClass(); 842 843 WebComponentDescriptor webComp = 844 (WebComponentDescriptor) getWebComponentImpl(); 845 846 WebBundleDescriptor bundle = webComp.getWebBundleDescriptor(); 847 WebServicesDescriptor webServices = bundle.getWebServices(); 848 Collection endpoints = 849 webServices.getEndpointsImplementedBy(webComp); 850 851 if( endpoints.size() > 1 ) { 852 String msg = "Servlet " + getWebComponentLink() + 853 " implements " + endpoints.size() + " web service endpoints " + 854 " but must only implement 1"; 855 throw new IllegalStateException (msg); 856 } 857 858 if( getEndpointAddressUri() == null ) { 859 Set urlPatterns = webComp.getUrlPatternsSet(); 860 if( urlPatterns.size() == 1 ) { 861 862 String uri = (String ) urlPatterns.iterator().next(); 865 setEndpointAddressUri(uri); 866 867 Collection constraints = 871 bundle.getSecurityConstraintsForUrlPattern(uri); 872 for(Iterator i = constraints.iterator(); i.hasNext();) { 873 SecurityConstraint next = (SecurityConstraint) i.next(); 874 875 UserDataConstraint dataConstraint = 876 next.getUserDataConstraint(); 877 String guarantee = (dataConstraint != null) ? 878 dataConstraint.getTransportGuarantee() : null; 879 880 if( (guarantee != null) && 881 ( guarantee.equals 882 (UserDataConstraint.INTEGRAL_TRANSPORT) || 883 guarantee.equals 884 (UserDataConstraint.CONFIDENTIAL_TRANSPORT) ) ) { 885 setTransportGuarantee(guarantee); 886 break; 887 } 888 } 889 } else { 890 String msg = "Endpoint " + getEndpointName() + 891 " has not been assigned an endpoint address " + 892 " and is associated with servlet " + 893 webComp.getCanonicalName() + " , which has " + 894 urlPatterns.size() + " url patterns"; 895 throw new IllegalStateException (msg); 896 } 897 } 898 } 899 900 public String getSoapAddressPrefix() { 901 if((SOAPBinding.SOAP12HTTP_BINDING.equals(protocolBinding)) || 902 (SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(protocolBinding)) || 903 ("##SOAP12_HTTP".equals(protocolBinding)) || 904 ("##SOAP12_HTTP_MTOM".equals(protocolBinding))) { 905 return "soap12"; 906 } 907 return "soap"; 909 } 910 911 public void print(StringBuffer toStringBuffer) { 912 super.print(toStringBuffer); 913 toStringBuffer.append("\n endpoint name = ").append(endpointName); 914 toStringBuffer.append( "\n endpoint intf = ").append(serviceEndpointInterface); 915 toStringBuffer.append( "\n wsdl Port = ").append(wsdlPort); 916 toStringBuffer.append( "\n ejb Link = ").append(ejbLink); 917 toStringBuffer.append( "\n web Link = ").append(webComponentLink); 918 } 919 } 920 | Popular Tags |