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

WebServiceEjbEndpointRegistry

public class WebServiceEjbEndpointRegistry extends Object
This class acts as a registry of all the webservice EJB end points enabled in this application server. This a singleton class, use getRegistry() to obtain the registry instance
author
Jerome Dochez

Fields Summary
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Logger
logger
private static final WebServiceEjbEndpointRegistry
registry
private Hashtable
webServiceEjbEndpoints
private Set
ejbContextRoots
private HashMap
adapterListMap
Constructors Summary
private WebServiceEjbEndpointRegistry()
Creates a new instance of WebServiceEjbEndpointRegistry

    
           
      
    
Methods Summary
public EjbRuntimeEndpointInfocreateEjbEndpointInfo(com.sun.enterprise.deployment.WebServiceEndpoint webServiceEndpoint, com.sun.ejb.containers.StatelessSessionContainer ejbContainer, java.lang.Object servant, java.lang.Class tieClass)
Creates a new EjbRuntimeEndpointInfo instance depending on the type and version of the web service implementation.

param

        EjbRuntimeEndpointInfo info;
        if ("1.1".compareTo(webServiceEndpoint.getWebService().getWebServicesDescriptor().getSpecVersion())>=0) {
            info = new Ejb2RuntimeEndpointInfo(webServiceEndpoint, ejbContainer, servant, tieClass);
        } else {
            info = new EjbRuntimeEndpointInfo(webServiceEndpoint, ejbContainer, servant);
        }
        return info;
    
private java.lang.StringgetContextRootForUri(java.lang.String uri)

        StringTokenizer tokenizer = new StringTokenizer(uri, "/");
        if (tokenizer.hasMoreTokens()) {
            return tokenizer.nextToken();
        } else {
            return null;
        }
        
    
public EjbRuntimeEndpointInfogetEjbWebServiceEndpoint(java.lang.String uriRaw, java.lang.String method, java.lang.String query)

        EjbRuntimeEndpointInfo endpoint = null;
        
        if (uriRaw==null || uriRaw.length()==0) {
            return null;
        }
        
        // Strip off any leading slash.
        String uri = (uriRaw.charAt(0) == '/") ? uriRaw.substring(1) : uriRaw;

        synchronized(webServiceEjbEndpoints) {

            if( method.equals("GET") ) {
                // First check for a context root match so we avoid iterating  
                // through all ejb endpoints.  This logic will be used for
                // all HTTP GETs, so it's important to reduce the overhead in
                // the likely most common case that the request is for a web 
                // component.
                String contextRoot = getContextRootForUri(uri);
                if( ejbContextRoots.contains(contextRoot) ) {
                    // Now check for a match with a specific ejb endpoint.
                    Collection values = webServiceEjbEndpoints.values();
                    for(Iterator iter = values.iterator(); iter.hasNext();) {
                        EjbRuntimeEndpointInfo next = (EjbRuntimeEndpointInfo)
                            iter.next();
                        if( next.getEndpoint().matchesEjbPublishRequest
                            (uri, query)) {
                            endpoint = next;
                            break;
                        }
                    }
                }
            } else {
                // In this case the uri must match exactly to be an ejb web
                // service invocation, so do a direct table lookup.
                endpoint = (EjbRuntimeEndpointInfo) 
                    webServiceEjbEndpoints.get(uri);
            }
        }
        return endpoint;
    
public java.util.CollectiongetEjbWebServiceEndpoints()

        return webServiceEjbEndpoints.entrySet();
    
public static com.sun.enterprise.webservice.WebServiceEjbEndpointRegistrygetRegistry()

return
the registry instance

        return registry;        
    
private voidregenerateEjbContextRoots()

        synchronized(webServiceEjbEndpoints) {
            Set contextRoots = new HashSet();
            for(Iterator iter = webServiceEjbEndpoints.keySet().iterator(); 
                iter.hasNext();) {
                String uri = (String) iter.next();
                String contextRoot = getContextRootForUri(uri);
                if( (contextRoot != null) && !contextRoot.equals("") ) {
                    contextRoots.add(contextRoot);
                }
            }
            ejbContextRoots = contextRoots;
        }
    
public voidregisterEjbWebServiceEndpoint(EjbRuntimeEndpointInfo endpoint)

        String ctxtRoot;
        synchronized(webServiceEjbEndpoints) {
            String uriRaw = endpoint.getEndpointAddressUri();
            String uri = (uriRaw.charAt(0)=='/") ? uriRaw.substring(1) : uriRaw;
            if (webServiceEjbEndpoints.containsKey(uri)) {
                logger.log(Level.SEVERE, 
                        localStrings.getString("enterprise.webservice.duplicateService", 
                        new Object[]{uri}));
            }            
            webServiceEjbEndpoints.put(uri, endpoint);
            regenerateEjbContextRoots();
            ctxtRoot = getContextRootForUri(uri);
            if(adapterListMap.get(ctxtRoot) == null) {
                ServletAdapterList list = new ServletAdapterList();
                adapterListMap.put(ctxtRoot, list);
            }
        }
        
        // notify monitoring layers that a new endpoint is being created.
        WebServiceEngineImpl engine = (WebServiceEngineImpl) WebServiceEngineFactory.getInstance().getEngine();
        if (endpoint.getEndpoint().getWebService().getMappingFileUri()!=null) {
            engine.createHandler((com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate)null, endpoint.getEndpoint());
        } else {
            engine.createHandler(endpoint.getEndpoint());
            // Safe to assume that it's a JAXWS endpoint
            endpoint.initRuntimeInfo((ServletAdapterList)adapterListMap.get(ctxtRoot));
        }
    
public voidunregisterEjbWebServiceEndpoint(java.lang.String endpointAddressUri)

        
        EjbRuntimeEndpointInfo endpoint = null;
        
        synchronized(webServiceEjbEndpoints) {
            String uriRaw = endpointAddressUri;
            String uri = (uriRaw.charAt(0)=='/") ? uriRaw.substring(1) : uriRaw;
            String ctxtRoot = getContextRootForUri(uri);
            ServletAdapterList list = (ServletAdapterList)adapterListMap.get(ctxtRoot);
            if(list != null) {
                for(ServletAdapter x : list) {
                    x.getEndpoint().dispose();
                }
            }
            endpoint = (EjbRuntimeEndpointInfo) webServiceEjbEndpoints.remove(uri);
            regenerateEjbContextRoots();
        }
        
        if (endpoint==null) {
            return;
        }
        
        // notify the monitoring layers that an endpoint is destroyed
        WebServiceEngineImpl engine = (WebServiceEngineImpl) WebServiceEngineFactory.getInstance().getEngine();
        engine.removeHandler(endpoint.getEndpoint());