[jbossws-commits] JBossWS SVN: r6471 - stack/cxf/trunk/src/main/java/org/jboss/wsf/stack/cxf.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Thu Apr 17 10:49:16 EDT 2008


Author: richard.opalka at jboss.com
Date: 2008-04-17 10:49:16 -0400 (Thu, 17 Apr 2008)
New Revision: 6471

Modified:
   stack/cxf/trunk/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java
Log:
refactoring - no functional change

Modified: stack/cxf/trunk/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java
===================================================================
--- stack/cxf/trunk/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java	2008-04-17 14:32:47 UTC (rev 6470)
+++ stack/cxf/trunk/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java	2008-04-17 14:49:16 UTC (rev 6471)
@@ -53,88 +53,110 @@
 {
    private static Logger log = Logger.getLogger(ServletControllerExt.class);
 
-   private ServletTransportFactory transport;
+   private ServletTransportFactory cxfTransport;
    private CXFServlet cxfServlet;
 
-   public ServletControllerExt(ServletTransportFactory transport, CXFServlet servlet)
+   public ServletControllerExt(ServletTransportFactory cxfTransport, CXFServlet cxfServlet)
    {
-      super(transport, servlet);
-      this.transport = transport;
-      this.cxfServlet = servlet;
+      super(cxfTransport, cxfServlet);
+      this.cxfTransport = cxfTransport;
+      this.cxfServlet = cxfServlet;
    }
-
-   public void invoke(HttpServletRequest req, HttpServletResponse res) throws ServletException
+   
+   /**
+    * Finds destination based on request URI
+    * @param requestURI to be recognized
+    * @return destination associated with the request URI
+    * @throws ServletException when destination wasn't found
+    */
+   private ServletDestination findDestination(HttpServletRequest req) throws ServletException
    {
-      try
+      // Find destination based on request URI
+      String requestURI = req.getRequestURI();
+      Collection<ServletDestination> destinations = cxfTransport.getDestinations();
+      for (ServletDestination destination : destinations)
       {
-         // Find destination based on request URI
-         String requestURI = req.getRequestURI();
-         ServletDestination dest = null;
-         Collection<ServletDestination> destinations = transport.getDestinations();
-         for (ServletDestination aux : destinations)
+         EndpointInfo endpointInfo = destination.getEndpointInfo();
+         String address = endpointInfo.getAddress();
+         
+         // Fix invalid leading slash
+         if (address.startsWith("/http://"))
          {
-            EndpointInfo ei = aux.getEndpointInfo();
-            String address = ei.getAddress();
-            
-            // Fix invalid leading slash
-            if (address.startsWith("/http://"))
-            {
-               address = address.substring(1);
-               ei.setAddress(address);
-            }
-            
-            String path = address;
-            try
-            {
-               path = new URL(address).getPath();
-            }
-            catch (MalformedURLException ex)
-            {
-               // ignore
-            }
-            
-            if (requestURI.startsWith(path))
-            {
-               dest = aux;
-               break;
-            }
+            address = address.substring(1);
+            endpointInfo.setAddress(address);
          }
-         if (dest == null)
-            throw new ServletException("Cannot obtain destination for: " + requestURI);
+         
+         String path = address;
+         try
+         {
+            path = new URL(address).getPath();
+         }
+         catch (MalformedURLException ex)
+         {
+            // ignore
+         }
+         
+         if (requestURI.startsWith(path))
+         {
+            return destination;
+         }
+      }
 
-         EndpointInfo ei = dest.getEndpointInfo();
-         Bus bus = cxfServlet.getBus();
-         if (null != req.getQueryString() && req.getQueryString().length() > 0 && bus.getExtension(QueryHandlerRegistry.class) != null)
+      throw new ServletException("Cannot obtain destination for: " + requestURI);
+   }
+   
+   /**
+    * When request includes query it tries to lookup the query handler and tries to handle the request message
+    * @param req request
+    * @param res response
+    * @param dest destination
+    * @return true if there was a query handler that successfully handled the request, false otherwise
+    * @throws ServletException if some problem occurs
+    */
+   private boolean handleQuery(HttpServletRequest req, HttpServletResponse res, ServletDestination dest)
+   throws ServletException
+   {
+      Bus bus = cxfServlet.getBus();
+      boolean hasQuery = (null != req.getQueryString()) && (req.getQueryString().length() > 0);
+      boolean queryHandlerRegistryExists = bus.getExtension(QueryHandlerRegistry.class) != null;
+      
+      if (hasQuery && queryHandlerRegistryExists)
+      {
+         String ctxUri = req.getRequestURI();
+         String baseUri = req.getRequestURL().toString() + "?" + req.getQueryString();
+         EndpointInfo endpointInfo = dest.getEndpointInfo();
+
+         for (QueryHandler queryHandler : bus.getExtension(QueryHandlerRegistry.class).getHandlers())
          {
-            String ctxUri = requestURI; //req.getPathInfo();
-            String baseUri = req.getRequestURL().toString() + "?" + req.getQueryString();
-
-            for (QueryHandler qh : bus.getExtension(QueryHandlerRegistry.class).getHandlers())
+            if (queryHandler.isRecognizedQuery(baseUri, ctxUri, endpointInfo))
             {
-               if (qh.isRecognizedQuery(baseUri, ctxUri, ei))
+               res.setContentType(queryHandler.getResponseContentType(baseUri, ctxUri));
+               try
                {
-
-                  res.setContentType(qh.getResponseContentType(baseUri, ctxUri));
                   OutputStream out = res.getOutputStream();
-                  try
-                  {
-                     qh.writeResponse(baseUri, ctxUri, ei, out);
-                     out.flush();
-                     return;
-                  }
-                  catch (Exception e)
-                  {
-                     throw new ServletException(e);
-                  }
+                  queryHandler.writeResponse(baseUri, ctxUri, endpointInfo, out);
+                  out.flush();
+                  return true;
                }
+               catch (Exception e)
+               {
+                  throw new ServletException(e);
+               }
             }
          }
+      }
+         
+      return false;
+   }
 
+   public void invoke(HttpServletRequest req, HttpServletResponse res) throws ServletException
+   {
+      ServletDestination dest = findDestination(req);
+      boolean requestHandled = handleQuery(req, res, dest); 
+      
+      if (false == requestHandled)
+      {
          invokeDestination(req, res, dest);
       }
-      catch (IOException e)
-      {
-         throw new ServletException(e);
-      }
    }
 }




More information about the jbossws-commits mailing list