KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > EjbWebServiceRegistryListener


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.web;
25
26 import java.util.Iterator JavaDoc;
27 import java.net.MalformedURLException JavaDoc;
28 import java.net.URL JavaDoc;
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 /**
41  * Listener for EJB webservice endpoint registrations and unregistrations.
42  *
43  * Upon receiving an EJB webservice endpoint registration event, this
44  * listener will register the EJB webservice endpoint's path as an ad-hoc
45  * path with the web container, along with information about the
46  * ad-hoc servlet responsible for servicing any requests on this path.
47  *
48  * Upon receiving an EJB webservice endpoint unregistration event, this
49  * listener will unregister the EJB webservice endpoint's path as an
50  * ad-hoc path from the web container.
51  *
52  * @author Jan Luehe
53  */

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     /**
65      * Constructor.
66      *
67      * @param webContainer The web container with which this
68      * EjbWebServiceRegistryListener is associated
69      */

70     public EjbWebServiceRegistryListener(WebContainer webContainer) {
71         this.webContainer = webContainer;
72     }
73
74
75     /**
76      * Registers this EjbWebServiceRegistryListener with the EJB webservice
77      * registry.
78      */

79     public void register() {
80
81         WebServiceEngineImpl wsEngine = WebServiceEngineImpl.getInstance();
82
83         wsEngine.addLifecycleListener(this);
84
85         /*
86          * Process any webservice endpoints that had been added before we've
87          * started listening for registration events.
88          */

89         Iterator JavaDoc<Endpoint> endpoints = wsEngine.getEndpoints();
90         if (endpoints != null) {
91             while (endpoints.hasNext()) {
92                 endpointAdded(endpoints.next());
93             }
94         }
95     }
96
97
98     /**
99      * Unregisters this EjbWebServiceRegistryListener from the EJB webservice
100      * registry.
101      */

102     public void unregister() {
103         WebServiceEngineImpl.getInstance().removeLifecycleListener(this);
104     }
105
106
107     /**
108      * Receives and processes notification of a new webservice endpoint
109      * installation in the appserver.
110      *
111      * This method extracts the context root from the endpoint's URL, at
112      * which it registers an EjbWebServiceWebModule which handles all HTTP
113      * requests for the endpoint.
114      *
115      * @param endpoint The EJB webservice endpoint that was added
116      */

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 JavaDoc epURL = null;
128         try {
129             epURL = new URL JavaDoc(endpoint.getEndpointSelector());
130         } catch (MalformedURLException JavaDoc me) {
131             throw new IllegalArgumentException JavaDoc(me.toString());
132         }
133
134         String JavaDoc epURI = epURL.getPath();
135         String JavaDoc epCtxRoot = null;
136         String JavaDoc 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 JavaDoc epSubtree = epPath + "/__container$publishing$subctx/";
148
149         String JavaDoc 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     /**
170      * Receives and processes notification of a webservice endpoint
171      * removal from the appserver.
172      *
173      * This method extracts the context root from the endpoint's URL, and
174      * unregisters the corresponding EjbWebServiceWebModule from the web
175      * container
176      *
177      * @param endpoint The EJB webservice endpoint that was removed
178      */

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 JavaDoc epURL = null;
190         try {
191             epURL = new URL JavaDoc(endpoint.getEndpointSelector());
192         } catch (MalformedURLException JavaDoc me) {
193             throw new IllegalArgumentException JavaDoc(me.toString());
194         }
195
196         String JavaDoc epURI = epURL.getPath();
197         String JavaDoc epCtxRoot = null;
198         String JavaDoc 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 JavaDoc epSubtree = epPath + "/__container$publishing$subctx/";
209         webContainer.unregisterAdHocPathAndSubtree(epPath, epSubtree,
210                                                    epCtxRoot);
211     }
212
213 }
214
Popular Tags