1 23 24 package com.sun.enterprise.web; 25 26 import java.util.Iterator ; 27 import java.net.MalformedURLException ; 28 import java.net.URL ; 29 30 import com.sun.enterprise.deployment.Application; 31 import com.sun.enterprise.deployment.BundleDescriptor; 32 import com.sun.enterprise.deployment.WebServiceEndpoint; 33 34 import com.sun.enterprise.webservice.monitoring.Endpoint; 35 import com.sun.enterprise.webservice.monitoring.TransportType; 36 import com.sun.enterprise.webservice.monitoring.EndpointType; 37 import com.sun.enterprise.webservice.monitoring.EndpointLifecycleListener; 38 import com.sun.enterprise.webservice.monitoring.WebServiceEngineImpl; 39 40 54 public class EjbWebServiceRegistryListener 55 implements EndpointLifecycleListener { 56 57 58 private static final EjbWebServiceServletInfo 59 EJB_WEB_SERVICE_SERVLET_INFO = new EjbWebServiceServletInfo(); 60 61 62 private WebContainer webContainer; 63 64 70 public EjbWebServiceRegistryListener(WebContainer webContainer) { 71 this.webContainer = webContainer; 72 } 73 74 75 79 public void register() { 80 81 WebServiceEngineImpl wsEngine = WebServiceEngineImpl.getInstance(); 82 83 wsEngine.addLifecycleListener(this); 84 85 89 Iterator <Endpoint> endpoints = wsEngine.getEndpoints(); 90 if (endpoints != null) { 91 while (endpoints.hasNext()) { 92 endpointAdded(endpoints.next()); 93 } 94 } 95 } 96 97 98 102 public void unregister() { 103 WebServiceEngineImpl.getInstance().removeLifecycleListener(this); 104 } 105 106 107 117 public void endpointAdded(Endpoint endpoint) { 118 119 if (!TransportType.HTTP.equals(endpoint.getTransport())) { 120 return; 121 } 122 123 if (!EndpointType.EJB_ENDPOINT.equals(endpoint.getEndpointType())) { 124 return; 125 } 126 127 URL epURL = null; 128 try { 129 epURL = new URL (endpoint.getEndpointSelector()); 130 } catch (MalformedURLException me) { 131 throw new IllegalArgumentException (me.toString()); 132 } 133 134 String epURI = epURL.getPath(); 135 String epCtxRoot = null; 136 String epPath = null; 137 138 int index = epURI.indexOf('/', 1); 139 if (index < 0) { 140 epCtxRoot = epURI; 141 epPath = ""; 142 } else { 143 epCtxRoot = epURI.substring(0, index); 144 epPath = epURI.substring(index); 145 } 146 147 String epSubtree = epPath + "/__container$publishing$subctx/"; 148 149 String epAppName = null; 150 WebServiceEndpoint wse = endpoint.getDescriptor(); 151 if (wse != null) { 152 BundleDescriptor bd = wse.getBundleDescriptor(); 153 if (bd != null) { 154 Application app = bd.getApplication(); 155 if (app != null) { 156 epAppName = app.getRegistrationName(); 157 } 158 } 159 } 160 161 webContainer.registerAdHocPathAndSubtree( 162 epPath, 163 epSubtree, 164 epCtxRoot, 165 epAppName, 166 EJB_WEB_SERVICE_SERVLET_INFO); 167 } 168 169 179 public void endpointRemoved(Endpoint endpoint) { 180 181 if (!TransportType.HTTP.equals(endpoint.getTransport())) { 182 return; 183 } 184 185 if (!EndpointType.EJB_ENDPOINT.equals(endpoint.getEndpointType())) { 186 return; 187 } 188 189 URL epURL = null; 190 try { 191 epURL = new URL (endpoint.getEndpointSelector()); 192 } catch (MalformedURLException me) { 193 throw new IllegalArgumentException (me.toString()); 194 } 195 196 String epURI = epURL.getPath(); 197 String epCtxRoot = null; 198 String epPath = null; 199 int index = epURI.indexOf('/', 1); 200 if (index < 0) { 201 epCtxRoot = epURI; 202 epPath = ""; 203 } else { 204 epCtxRoot = epURI.substring(0, index); 205 epPath = epURI.substring(index); 206 } 207 208 String epSubtree = epPath + "/__container$publishing$subctx/"; 209 webContainer.unregisterAdHocPathAndSubtree(epPath, epSubtree, 210 epCtxRoot); 211 } 212 213 } 214 | Popular Tags |