KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > webservice > server > ServiceEndpointServlet


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.webservice.server;
8
9 // $Id: ServiceEndpointServlet.java,v 1.8.2.5 2005/04/12 16:07:49 starksm Exp $
10

11 import org.jboss.axis.AxisEngine;
12 import org.jboss.axis.AxisFault;
13 import org.jboss.axis.MessageContext;
14 import org.jboss.axis.handlers.soap.SOAPService;
15 import org.jboss.logging.Logger;
16 import org.jboss.webservice.ServiceDeployer;
17
18 import javax.servlet.ServletException JavaDoc;
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23
24 /**
25  * An JBossWS AxisServlet.
26  *
27  * It gets the server config via JMX from the AxisService.
28  * Supports URL wsdl lookup with imports
29  *
30  * @author Thomas.Diesler@jboss.org
31  * @since 15-April-2004
32  */

33 public class ServiceEndpointServlet extends AbstractServlet
34 {
35    /** @since 4.0.2 */
36    static final long serialVersionUID = 3806847653370058302L;
37
38    // provide logging
39
protected final Logger log = Logger.getLogger(getClass());
40
41    /**
42     * Process GET requests.
43     */

44    public void doGet(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
45            throws ServletException JavaDoc, IOException JavaDoc
46    {
47       String JavaDoc url = req.getRequestURL().toString();
48       String JavaDoc queryString = req.getQueryString();
49       log.debug("doGet: " + url + (queryString != null ? "?" + queryString : ""));
50
51       PrintWriter JavaDoc writer = res.getWriter();
52       try
53       {
54          AxisEngine engine = getEngine();
55
56          // Get the SOAP servie
57
String JavaDoc serviceName = getServiceName(req);
58          SOAPService service = (serviceName != null ? engine.getService(serviceName) : null);
59
60          boolean wsdlRequested = req.getParameter("wsdl") != null || req.getParameter("WSDL") != null;
61
62          if (!wsdlRequested)
63          {
64             log.debug("Report available services");
65
66             // If the user requested the servlet (i.e. /ws4ee/services)
67
// with no service name, present the user with a list of deployed services to be helpful
68
// Don't do this if we are doing WSDL or list.
69
reportAvailableServices(res, writer, req);
70             return;
71          }
72
73          if (service == null)
74          {
75             log.error("Cannot get axis service: " + serviceName);
76             reportCantGetAxisService(req, res, writer);
77             return;
78          }
79
80          // get message context w/ various properties set
81
MessageContext msgContext = createMessageContext(engine, req, res);
82
83          // we found the service, so we can set it in the msg context
84
// whoever comes after, won't have to retry finding it
85
if (service != null)
86             msgContext.setTargetService(serviceName);
87
88          String JavaDoc transportURL = getTransportURL(req, serviceName);
89          if (transportURL != null)
90          {
91             msgContext.setProperty(MessageContext.TRANS_URL, transportURL);
92             log.debug("Set transport.url=" + transportURL);
93          }
94
95          if (wsdlRequested)
96          {
97             String JavaDoc wsdlResource = req.getParameter("resource");
98             if (wsdlResource != null)
99             {
100                log.debug("Process wsdl import request: " + wsdlResource);
101                msgContext.setProperty(MessageContext.WSDLGEN_RESOURCE, wsdlResource);
102             }
103             else
104             {
105                log.debug("Process wsdl request");
106             }
107
108             processWsdlRequest(msgContext, res, writer);
109             return;
110          }
111
112          // If nothing else was done previously
113
log.debug("Report service info");
114          reportServiceInfo(res, writer, service, serviceName);
115       }
116       catch (AxisFault fault)
117       {
118          reportTrouble(fault, res, writer);
119       }
120       catch (Exception JavaDoc e)
121       {
122          reportTrouble(e, res, writer);
123       }
124       finally
125       {
126          // Make sure the MessageContext is removed from the calling ThreadLocal
127
AxisEngine.setCurrentMessageContext(null);
128          writer.close();
129       }
130    }
131
132    /**
133     * Get the service name as it is known to Axis
134     * <p/>
135     * For JSE service endpoints it is obtained from the generated init parameter in web.xml
136     */

137    protected String JavaDoc getServiceName(HttpServletRequest JavaDoc req)
138    {
139       String JavaDoc serviceName = getServletConfig().getInitParameter(ServiceDeployer.INIT_PARAM_WEBSERVICE_ID);
140       return serviceName;
141    }
142 }
143
Popular Tags