FileDocCategorySizeDatePackage
ServletWebServiceDelegate.javaAPI DocGlassfish v2 API9952Fri May 04 22:36:12 BST 2007com.sun.enterprise.webservice

ServletWebServiceDelegate

public class ServletWebServiceDelegate extends com.sun.xml.rpc.spi.runtime.ServletSecondDelegate
This class is delegated to by the container-provided servlet-class that is written into the web.xml at deployment time. It overrides the JAXRPC servlet delegate to register endpoint information and intercept certain events.

Fields Summary
private static Logger
logger
private com.sun.enterprise.deployment.WebServiceEndpoint
endpoint_
private ServletConfig
servletConfig_
private com.sun.xml.rpc.spi.runtime.ServletDelegate
rpcDelegate_
private com.sun.xml.rpc.spi.JaxRpcObjectFactory
rpcFactory_
private com.sun.enterprise.webservice.monitoring.WebServiceEngineImpl
wsEngine_
private com.sun.enterprise.webservice.monitoring.JAXRPCEndpointImpl
endpointImpl_
Constructors Summary
public ServletWebServiceDelegate(com.sun.xml.rpc.spi.runtime.ServletDelegate firstDelegate)

  

        
        rpcDelegate_ = firstDelegate;
        rpcFactory_ = JaxRpcObjectFactory.newInstance();
        wsEngine_ = WebServiceEngineImpl.getInstance();
    
Methods Summary
public com.sun.xml.rpc.spi.runtime.ImplementorCachecreateImplementorCache(javax.servlet.ServletConfig sc)

        ImplementorCache ic = rpcFactory_.createImplementorCache(sc);
        ImplementorCacheDelegate delegate =
                            new ImplementorCacheDelegateImpl(sc);
        ic.setDelegate(delegate);
        return ic;
    
public voiddestroy()

        wsEngine_.removeHandler(endpoint_);
    
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

        
        // normal WSDL retrieval invocation
        WsUtil wsUtil = new WsUtil();
        try {
            wsUtil.handleGet(request, response, endpoint_);
        } catch(Exception e) {
            logger.log(Level.WARNING, "Servlet web service endpoint '" +
               endpoint_.getEndpointName() + "' HTTP GET error", e);
        }
    
public voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

       
       
        rpcDelegate_.doPost(request, response);
        
    
public voidpostInit(javax.servlet.ServletConfig servletConfig)


        servletConfig_ = servletConfig;
        String servletName = "unknown";

        try {
            InvocationManager invManager = 
                Switch.getSwitch().getInvocationManager();
            ComponentInvocation inv = invManager.getCurrentInvocation();
            Object containerContext = inv.getContainerContext();

            WebBundleDescriptor webBundle = (WebBundleDescriptor)
                Switch.getSwitch().getDescriptorFor(containerContext);
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            servletName = servletConfig.getServletName();
            WebComponentDescriptor webComponent = 
                webBundle.getWebComponentByCanonicalName(servletName);

            if( webComponent != null ) {
                WebServicesDescriptor webServices = webBundle.getWebServices();
                Collection endpoints =                     
                    webServices.getEndpointsImplementedBy(webComponent);
                // Only 1 endpoint per servlet is supported, even though
                // data structure implies otherwise. 
                endpoint_ = (WebServiceEndpoint) endpoints.iterator().next();
                registerEndpoint(classLoader);

		// if a conventional authentication mechanism has NOT been configured
		// for the endpoint create and install system handler for web services 
		// security 
                SystemHandlerDelegate securityHandlerDelegate = null;
		if (!endpoint_.hasAuthMethod()) {
		    try {
			ServerAuthConfig config = ServerAuthConfig.getConfig
			    (com.sun.enterprise.security.jauth.AuthConfig.SOAP,
			     endpoint_.getMessageSecurityBinding(),
			     null);
			if (config != null) {
			    securityHandlerDelegate = 
				new ServletSystemHandlerDelegate(config, endpoint_);
			    rpcDelegate_.setSystemHandlerDelegate(securityHandlerDelegate);
			}
		    } catch (Exception e) {
			logger.log(Level.SEVERE,
				   "Servlet Webservice security configuration Failure", e);
		    }
		}
                // need to invoke the endpoint lifecylcle 
                endpointImpl_ = (JAXRPCEndpointImpl)wsEngine_.createHandler(securityHandlerDelegate, endpoint_);
                rpcDelegate_.setSystemHandlerDelegate(endpointImpl_);

            } else {
                throw new ServletException(servletName + " not found");
            }
        } catch(Throwable t) {
            logger.log(Level.WARNING, "Servlet web service endpoint '" +
                       servletName + "' failure", t);
            ServletException se = new ServletException();
            se.initCause(t);
            throw se;
        }
    
private voidregisterEndpoint(java.lang.ClassLoader loader)


        //
        // Convert J2EE deployment descriptor information into 
        // JAXRPC endpoint data structure
        //

        RuntimeEndpointInfo endpointInfo = 
	    rpcFactory_.createRuntimeEndpointInfo();
        
        Class serviceEndpointInterfaceClass =
            loader.loadClass(endpoint_.getServiceEndpointInterface());
        Class implementationClass = 
            loader.loadClass(endpoint_.getServletImplClass());
        String tieClassName = endpoint_.getTieClassName();
        if(tieClassName != null) {
            Class tieClass = loader.loadClass(tieClassName);
            endpointInfo.setTieClass(tieClass);
        }

        endpointInfo.setRemoteInterface(serviceEndpointInterfaceClass);
        endpointInfo.setImplementationClass(implementationClass);

        endpointInfo.setName(endpoint_.getEndpointName());

        WebService webService = endpoint_.getWebService();


        // No need to set model file name or wsdl file, since we override
        // the code that serves up the final WSDL.
        //endpointInfo.setModelFileName()
        //endpointInfo.setWSDLFileName()

        endpointInfo.setDeployed(true);
        endpointInfo.setPortName(endpoint_.getWsdlPort());

        endpointInfo.setServiceName(endpoint_.getServiceName());

        // For web components, this will be relative to the web app
        // context root.  Make sure there is a leading slash.
        String uri = endpoint_.getEndpointAddressUri();
        uri = uri.startsWith("/") ? uri : "/" + uri;
        endpointInfo.setUrlPattern(uri);

        rpcDelegate_.registerEndpointUrlPattern(endpointInfo);
    
public voidwarnMissingContextInformation()

        // context info not used within j2ee integration, so override
        // this method to prevent warning message