1 23 24 package com.sun.enterprise.webservice; 25 26 import java.util.*; 27 import java.util.logging.Logger ; 28 import java.util.logging.Level ; 29 30 import com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate; 32 33 import com.sun.enterprise.deployment.WebServiceEndpoint; 34 import com.sun.enterprise.webservice.monitoring.WebServiceEngineImpl; 35 import com.sun.enterprise.webservice.monitoring.WebServiceEngineFactory; 36 import com.sun.ejb.containers.StatelessSessionContainer; 37 import com.sun.logging.LogDomains; 38 import com.sun.enterprise.util.i18n.StringManager; 39 40 47 public class WebServiceEjbEndpointRegistry { 48 49 private static StringManager localStrings = 50 StringManager.getManager( WebServiceEjbEndpointRegistry.class ); 51 Logger logger = LogDomains.getLogger(LogDomains.EJB_LOGGER); 52 53 private static WebServiceEjbEndpointRegistry registry = null; 54 55 private Hashtable webServiceEjbEndpoints = new Hashtable(); 57 58 private Set ejbContextRoots = new HashSet(); 65 66 67 68 private WebServiceEjbEndpointRegistry() { 69 } 70 71 74 public static WebServiceEjbEndpointRegistry getRegistry() { 75 if (registry==null) { 76 synchronized(WebServiceEjbEndpointRegistry.class) { 77 if (registry==null) { 78 registry = new WebServiceEjbEndpointRegistry(); 79 } 80 } 81 } 82 return registry; 83 } 84 85 public void registerEjbWebServiceEndpoint(EjbRuntimeEndpointInfo endpoint) throws Exception { 86 synchronized(webServiceEjbEndpoints) { 87 String uriRaw = endpoint.getEndpointAddressUri(); 88 String uri = (uriRaw.charAt(0)=='/') ? uriRaw.substring(1) : uriRaw; 89 if (webServiceEjbEndpoints.containsKey(uri)) { 90 logger.log(Level.SEVERE, 91 localStrings.getString("enterprise.webservice.duplicateService", 92 new Object []{uri})); 93 } 94 webServiceEjbEndpoints.put(uri, endpoint); 95 regenerateEjbContextRoots(); 96 } 97 98 WebServiceEngineImpl engine = (WebServiceEngineImpl) WebServiceEngineFactory.getInstance().getEngine(); 100 if (endpoint.getEndpoint().getWebService().getMappingFileUri()!=null) { 101 engine.createHandler((com.sun.xml.rpc.spi.runtime.SystemHandlerDelegate)null, endpoint.getEndpoint()); 102 } else { 103 engine.createHandler((com.sun.xml.ws.spi.runtime.SystemHandlerDelegate)null, endpoint.getEndpoint()); 104 endpoint.initRuntimeInfo(); 106 } 107 } 108 109 public void unregisterEjbWebServiceEndpoint(String endpointAddressUri) { 110 111 EjbRuntimeEndpointInfo endpoint = null; 112 113 synchronized(webServiceEjbEndpoints) { 114 String uriRaw = endpointAddressUri; 115 String uri = (uriRaw.charAt(0)=='/') ? uriRaw.substring(1) : uriRaw; 116 endpoint = (EjbRuntimeEndpointInfo) webServiceEjbEndpoints.remove(uri); 117 regenerateEjbContextRoots(); 118 } 119 120 if (endpoint==null) { 121 return; 122 } 123 124 WebServiceEngineImpl engine = (WebServiceEngineImpl) WebServiceEngineFactory.getInstance().getEngine(); 126 engine.removeHandler(endpoint.getEndpoint()); 127 } 128 129 134 public EjbRuntimeEndpointInfo createEjbEndpointInfo(WebServiceEndpoint webServiceEndpoint, 135 StatelessSessionContainer ejbContainer, 136 Object servant, Class tieClass) { 137 EjbRuntimeEndpointInfo info; 138 if ("1.1".compareTo(webServiceEndpoint.getWebService().getWebServicesDescriptor().getSpecVersion())>=0) { 139 info = new Ejb2RuntimeEndpointInfo(webServiceEndpoint, ejbContainer, servant, tieClass); 140 } else { 141 info = new EjbRuntimeEndpointInfo(webServiceEndpoint, ejbContainer, servant); 142 } 143 return info; 144 } 145 146 public EjbRuntimeEndpointInfo getEjbWebServiceEndpoint 147 (String uriRaw, String method, String query) { 148 EjbRuntimeEndpointInfo endpoint = null; 149 150 if (uriRaw==null || uriRaw.length()==0) { 151 return null; 152 } 153 154 String uri = (uriRaw.charAt(0) == '/') ? uriRaw.substring(1) : uriRaw; 156 157 synchronized(webServiceEjbEndpoints) { 158 159 if( method.equals("GET") ) { 160 String contextRoot = getContextRootForUri(uri); 166 if( ejbContextRoots.contains(contextRoot) ) { 167 Collection values = webServiceEjbEndpoints.values(); 169 for(Iterator iter = values.iterator(); iter.hasNext();) { 170 EjbRuntimeEndpointInfo next = (EjbRuntimeEndpointInfo) 171 iter.next(); 172 if( next.getEndpoint().matchesEjbPublishRequest 173 (uri, query)) { 174 endpoint = next; 175 break; 176 } 177 } 178 } 179 } else { 180 endpoint = (EjbRuntimeEndpointInfo) 183 webServiceEjbEndpoints.get(uri); 184 } 185 } 186 return endpoint; 187 } 188 189 public Collection getEjbWebServiceEndpoints() { 190 return webServiceEjbEndpoints.entrySet(); 191 } 192 193 private String getContextRootForUri(String uri) { 194 StringTokenizer tokenizer = new StringTokenizer(uri, "/"); 195 if (tokenizer.hasMoreTokens()) { 196 return tokenizer.nextToken(); 197 } else { 198 return null; 199 } 200 201 } 202 203 private void regenerateEjbContextRoots() { 204 synchronized(webServiceEjbEndpoints) { 205 Set contextRoots = new HashSet(); 206 for(Iterator iter = webServiceEjbEndpoints.keySet().iterator(); 207 iter.hasNext();) { 208 String uri = (String ) iter.next(); 209 String contextRoot = getContextRootForUri(uri); 210 if( (contextRoot != null) && !contextRoot.equals("") ) { 211 contextRoots.add(contextRoot); 212 } 213 } 214 ejbContextRoots = contextRoots; 215 } 216 } 217 218 } 219 | Popular Tags |