Author: thomas.diesler(a)jboss.com
Date: 2007-05-11 00:35:04 -0400 (Fri, 11 May 2007)
New Revision: 3048
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/server/AbstractServiceEndpointServlet.java
trunk/jbossws-core/src/java/org/jboss/ws/core/server/RequestHandlerImpl.java
Log:
Use HttpRequestHandler
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/server/AbstractServiceEndpointServlet.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/server/AbstractServiceEndpointServlet.java 2007-05-11
04:31:34 UTC (rev 3047)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/server/AbstractServiceEndpointServlet.java 2007-05-11
04:35:04 UTC (rev 3048)
@@ -24,19 +24,14 @@
// $Id$
import java.io.IOException;
-import java.io.Writer;
import javax.management.ObjectName;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
-import javax.servlet.ServletInputStream;
-import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.xml.rpc.JAXRPCException;
-import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
import org.jboss.ws.integration.Endpoint;
import org.jboss.ws.integration.RequestHandler;
@@ -52,9 +47,6 @@
*/
public abstract class AbstractServiceEndpointServlet extends HttpServlet
{
- // provide logging
- private static final Logger log =
Logger.getLogger(AbstractServiceEndpointServlet.class);
-
protected Endpoint endpoint;
protected EndpointRegistry epRegistry;
@@ -64,11 +56,6 @@
epRegistry = EndpointRegistryFactory.getEndpointRegistry();
}
- public void destroy()
- {
- super.destroy();
- }
-
public void service(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
{
if (endpoint == null)
@@ -76,87 +63,11 @@
String contextPath = req.getContextPath();
initServiceEndpoint(contextPath);
}
- super.service(req, res);
- }
- public void doGet(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
- {
- // Process a WSDL request
- if (req.getParameter("wsdl") != null ||
req.getParameter("WSDL") != null)
- {
- res.setContentType("text/xml");
- ServletOutputStream out = res.getOutputStream();
- try
- {
- RequestHandler requestHandler = endpoint.getRequestHandler();
- ServletRequestContext context = new
ServletRequestContext(getServletContext(), req, res);
- requestHandler.handleWSDLRequest(endpoint, out, context);
- }
- catch (Exception ex)
- {
- handleException(ex);
- }
- finally
- {
- try
- {
- out.close();
- }
- catch (IOException ioex)
- {
- log.error("Cannot close output stream");
- }
- }
- }
- else
- {
- res.setStatus(405);
- res.setContentType("text/plain");
- Writer out = res.getWriter();
- out.write("HTTP GET not supported");
- out.close();
- }
+ RequestHandler requestHandler = (RequestHandler)endpoint.getRequestHandler();
+ requestHandler.handleHttpRequest(endpoint, req, res, getServletContext());
}
- public void doPost(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
- {
- log.debug("doPost: " + req.getRequestURI());
-
- ServletInputStream in = req.getInputStream();
- ServletOutputStream out = res.getOutputStream();
- try
- {
- RequestHandler requestHandler = endpoint.getRequestHandler();
- ServletRequestContext context = new ServletRequestContext(getServletContext(),
req, res);
- requestHandler.handleRequest(endpoint, in, out, context);
- }
- catch (Exception ex)
- {
- handleException(ex);
- }
- finally
- {
- try
- {
- out.close();
- }
- catch (IOException ioex)
- {
- log.error("Cannot close output stream");
- }
- }
- }
-
- private void handleException(Exception ex) throws ServletException
- {
- log.error("Error processing web service request", ex);
-
- if (ex instanceof JAXRPCException)
- throw (JAXRPCException)ex;
-
- throw new ServletException(ex);
- }
-
/** Initialize the service endpoint
*/
protected void initServiceEndpoint(String contextPath)
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/server/RequestHandlerImpl.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/server/RequestHandlerImpl.java 2007-05-11
04:31:34 UTC (rev 3047)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/server/RequestHandlerImpl.java 2007-05-11
04:35:04 UTC (rev 3048)
@@ -27,6 +27,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
@@ -34,9 +35,13 @@
import javax.activation.DataHandler;
import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
+import javax.xml.rpc.JAXRPCException;
import javax.xml.rpc.soap.SOAPFaultException;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPEnvelope;
@@ -92,8 +97,91 @@
// provide logging
private static final Logger log = Logger.getLogger(RequestHandlerImpl.class);
- public void handleRequest(Endpoint endpoint, InputStream inputStream, OutputStream
outputStream, InvocationContext context)
+ public void handleHttpRequest(Endpoint endpoint, HttpServletRequest req,
HttpServletResponse res, ServletContext context) throws ServletException, IOException
{
+ String method = req.getMethod();
+ if (method.equals("POST"))
+ {
+ doPost(endpoint, req, res, context);
+ }
+ else if (method.equals("GET"))
+ {
+ doGet(endpoint, req, res, context);
+ }
+ else
+ {
+ throw new WSException("Unsupported method: " + method);
+ }
+ }
+
+ private void doGet(Endpoint endpoint, HttpServletRequest req, HttpServletResponse res,
ServletContext context) throws ServletException, IOException
+ {
+ // Process a WSDL request
+ if (req.getParameter("wsdl") != null ||
req.getParameter("WSDL") != null)
+ {
+ res.setContentType("text/xml");
+ ServletOutputStream out = res.getOutputStream();
+ try
+ {
+ ServletRequestContext reqContext = new ServletRequestContext(context, req,
res);
+ handleWSDLRequest(endpoint, out, reqContext);
+ }
+ catch (Exception ex)
+ {
+ handleException(ex);
+ }
+ finally
+ {
+ try
+ {
+ out.close();
+ }
+ catch (IOException ioex)
+ {
+ log.error("Cannot close output stream");
+ }
+ }
+ }
+ else
+ {
+ res.setStatus(405);
+ res.setContentType("text/plain");
+ Writer out = res.getWriter();
+ out.write("HTTP GET not supported");
+ out.close();
+ }
+ }
+
+ private void doPost(Endpoint endpoint, HttpServletRequest req, HttpServletResponse
res, ServletContext context) throws ServletException, IOException
+ {
+ log.debug("doPost: " + req.getRequestURI());
+
+ ServletInputStream in = req.getInputStream();
+ ServletOutputStream out = res.getOutputStream();
+ try
+ {
+ ServletRequestContext reqContext = new ServletRequestContext(context, req,
res);
+ handleRequest(endpoint, in, out, reqContext);
+ }
+ catch (Exception ex)
+ {
+ handleException(ex);
+ }
+ finally
+ {
+ try
+ {
+ out.close();
+ }
+ catch (IOException ioex)
+ {
+ log.error("Cannot close output stream");
+ }
+ }
+ }
+
+ public void handleRequest(Endpoint endpoint, InputStream inStream, OutputStream
outStream, InvocationContext context)
+ {
log.debug("handleRequest: " + endpoint.getName());
ServerEndpointMetaData sepMetaData =
endpoint.getMetaData(ServerEndpointMetaData.class);
@@ -139,7 +227,7 @@
try
{
- MessageAbstraction resMessage = processRequest(endpoint, headerSource,
reqContext, inputStream);
+ MessageAbstraction resMessage = processRequest(endpoint, headerSource,
reqContext, inStream);
// Replace the message context with the response context
msgContext = MessageContextAssociation.peekMessageContext();
@@ -172,7 +260,7 @@
}
}
- sendResponse(outputStream, msgContext, isFault);
+ sendResponse(outStream, msgContext, isFault);
}
catch (Exception ex)
{
@@ -406,4 +494,14 @@
throw new WSException(ex);
}
}
+
+ private void handleException(Exception ex) throws ServletException
+ {
+ log.error("Error processing web service request", ex);
+
+ if (ex instanceof JAXRPCException)
+ throw (JAXRPCException)ex;
+
+ throw new ServletException(ex);
+ }
}