KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > webservice > JAXRPCServlet


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.webservice;
25
26 import javax.servlet.*;
27 import javax.servlet.http.*;
28
29 import com.sun.xml.rpc.spi.JaxRpcObjectFactory;
30 import com.sun.xml.rpc.spi.runtime.ServletDelegate;
31 import com.sun.xml.rpc.spi.runtime.ServletSecondDelegate;
32
33 import com.sun.enterprise.webservice.monitoring.WebServiceEngineImpl;
34 import com.sun.enterprise.webservice.monitoring.HttpResponseInfoImpl;
35 import com.sun.enterprise.webservice.monitoring.ThreadLocalInfo;
36 import com.sun.enterprise.webservice.monitoring.EndpointImpl;
37 import com.sun.enterprise.webservice.monitoring.WebServiceTesterServlet;
38 import com.sun.enterprise.webservice.monitoring.Endpoint;
39 import com.sun.enterprise.webservice.monitoring.EndpointType;
40
41 // catalina
42
import org.apache.catalina.Loader;
43
44 /**
45  * The JAX-RPC dispatcher servlet.
46  *
47  */

48 public class JAXRPCServlet extends HttpServlet {
49
50     private ServletDelegate delegate_;
51     private ServletWebServiceDelegate myDelegate_=null;
52
53     public void init(ServletConfig servletConfig) throws ServletException {
54         try {
55             super.init(servletConfig);
56             JaxRpcObjectFactory rpcFactory = JaxRpcObjectFactory.newInstance();
57             delegate_ =
58         (ServletDelegate) rpcFactory.createServletDelegate();
59             myDelegate_ = new ServletWebServiceDelegate(delegate_);
60             delegate_.setSecondDelegate(myDelegate_);
61             delegate_.init(servletConfig);
62
63         } catch (ServletException e) {
64             throw e;
65         } catch (Throwable JavaDoc e) {
66             throw new ServletException(e);
67         }
68     }
69
70     public void destroy() {
71         if (delegate_ != null) {
72             delegate_.destroy();
73         }
74         if (myDelegate_ != null) {
75             myDelegate_.destroy();
76         }
77     }
78
79     protected void doPost(HttpServletRequest request,
80                           HttpServletResponse response)
81         throws ServletException {
82         
83         WebServiceEngineImpl wsEngine_ = WebServiceEngineImpl.getInstance();
84         
85         if ("Tester".equalsIgnoreCase(request.getQueryString())) {
86             Endpoint endpt = wsEngine_.getEndpoint(request.getRequestURL().toString());
87             if (endpt!=null && Boolean.parseBoolean(endpt.getDescriptor().getDebugging())) {
88                 WebServiceTesterServlet.invoke(request, response,
89                         endpt.getDescriptor());
90                 return;
91             }
92         }
93                 
94         if (delegate_ != null) {
95             // check if we need to trace this...
96
String JavaDoc messageId=null;
97             if (wsEngine_.getGlobalMessageListener()!=null) {
98                 Endpoint endpt = wsEngine_.getEndpoint(request.getRequestURL().toString());
99                 messageId = wsEngine_.preProcessRequest(endpt);
100                 if (messageId!=null) {
101                     ThreadLocalInfo config = new ThreadLocalInfo(messageId, request);
102                     wsEngine_.getThreadLocal().set(config);
103                 }
104             }
105             
106             delegate_.doPost(request, response);
107             
108             if (messageId!=null) {
109                 HttpResponseInfoImpl info = new HttpResponseInfoImpl(response);
110                 wsEngine_.postProcessResponse(messageId, info);
111             }
112         }
113     }
114
115     protected void doGet(HttpServletRequest request,
116                          HttpServletResponse response)
117         throws ServletException {
118         
119         // test for tester servlet invocation.
120
if ("Tester".equalsIgnoreCase(request.getQueryString())) {
121             
122             Endpoint endpt = WebServiceEngineImpl.getInstance().getEndpoint(request.getRequestURL().toString());
123             if (endpt!=null && Boolean.parseBoolean(endpt.getDescriptor().getDebugging())) {
124                 Loader loader = (Loader) endpt.getDescriptor().getBundleDescriptor().getExtraAttribute("WEBLOADER");
125                 if (loader != null) {
126                     endpt.getDescriptor().getBundleDescriptor().setClassLoader(loader.getClassLoader());
127                     endpt.getDescriptor().getBundleDescriptor().removeExtraAttribute("WEBLOADER");
128                 }
129                 WebServiceTesterServlet.invoke(request, response,
130                         endpt.getDescriptor());
131                 return;
132             }
133         }
134         if (delegate_ != null) {
135             delegate_.doGet(request, response);
136         }
137     }
138
139 }
140
Popular Tags