cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r788823 - in /cxf/branches/2.2.x-fixes: ./ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/ systests/src/test/java/org/apache/cxf/systest/jaxrs/ systests/s...
Date Fri, 26 Jun 2009 19:20:09 GMT
Author: dkulp
Date: Fri Jun 26 19:20:08 2009
New Revision: 788823

URL: http://svn.apache.org/viewvc?rev=788823&view=rev
Log:
Merged revisions 788030 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r788030 | sergeyb | 2009-06-24 10:05:50 -0400 (Wed, 24 Jun 2009) | 1 line
  
  Updating AbstractCxfServlet to support arbitrary HTTP methods
........

Added:
    cxf/branches/2.2.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/
      - copied from r788030, cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/
    cxf/branches/2.2.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/AbstractCXFServletTest.java
      - copied unchanged from r788030, cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/servlet/AbstractCXFServletTest.java
    cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/retrieveRequest.txt
      - copied unchanged from r788030, cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/retrieveRequest.txt
Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
    cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
    cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jun 26 19:20:08 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788451
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788451

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java?rev=788823&r1=788822&r2=788823&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractCXFServlet.java
Fri Jun 26 19:20:08 2009
@@ -20,12 +20,16 @@
 
 import java.io.IOException;
 import java.lang.ref.WeakReference;
+import java.util.Arrays;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -40,9 +44,16 @@
 
 
 public abstract class AbstractCXFServlet extends HttpServlet {
+    
     static final Map<String, WeakReference<Bus>> BUS_MAP = new Hashtable<String,
WeakReference<Bus>>();
     static final Logger LOG = getLogger();
     
+    /**
+     * List of well-known HTTP 1.1 verbs, with POST and GET being the most used verbs at
the top 
+     */
+    private static final List<String> KNOWN_HTTP_VERBS = 
+        Arrays.asList(new String[]{"POST", "GET", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE"});
+    
     protected Bus bus;
     protected ServletTransportFactory servletTransportFactory;
     protected ServletController controller;
@@ -137,11 +148,13 @@
         bus.shutdown(true);
     }
     
-    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
+    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
+        throws ServletException {
         invoke(request, response);
     }
 
-    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
+    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
+        throws ServletException {
         invoke(request, response);
     }
 
@@ -152,12 +165,56 @@
     }
 
     @Override
-    protected void doPut(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
-        IOException {
+    protected void doPut(HttpServletRequest request, HttpServletResponse response) 
+        throws ServletException, IOException {
+        invoke(request, response);
+    }
+    
+    @Override
+    protected void doHead(HttpServletRequest request, HttpServletResponse response) 
+        throws ServletException, IOException {
+        invoke(request, response);
+    }
+    
+    @Override
+    protected void doOptions(HttpServletRequest request, HttpServletResponse response) 
+        throws ServletException, IOException {
         invoke(request, response);
     }
     
-    private  void invoke(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
+    
+    
+    /**
+     * {@inheritDoc}
+     * 
+     * javax.http.servlet.HttpServlet does not let to override the code which deals with
+     * unrecognized HTTP verbs such as PATCH (being standardized), WebDav ones, etc.
+     * Thus we let CXF servlets process unrecognized HTTP verbs directly, otherwise we delegate
+     * to HttpService  
+     */
+    @Override
+    public void service(ServletRequest req, ServletResponse res)
+        throws ServletException, IOException {
+        
+        HttpServletRequest      request;
+        HttpServletResponse     response;
+        
+        try {
+            request = (HttpServletRequest) req;
+            response = (HttpServletResponse) res;
+        } catch (ClassCastException e) {
+            throw new ServletException("Unrecognized HTTP request or response object");
+        }
+        
+        String method = request.getMethod();
+        if (KNOWN_HTTP_VERBS.contains(method)) {
+            super.service(request, response);
+        } else {
+            invoke(request, response);
+        }
+    }
+    
+    protected void invoke(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
         try {
             BusFactory.setThreadDefaultBus(getBus());
             controller.invoke(request, response);

Modified: cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java?rev=788823&r1=788822&r2=788823&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
Fri Jun 26 19:20:08 2009
@@ -129,7 +129,7 @@
     
     @RETRIEVE
     @Path("books/aegis/retrieve")
-    @Produces({"application/html;q=1.0", "application/xml;q=0.5", "application/json;q=0.5"
})
+    @Produces({"application/html;q=0.5", "application/xml;q=1.0", "application/json;q=0.5"
})
     public Book getBookAegisRetrieve() {
         return getBookAegis();
     }

Modified: cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=788823&r1=788822&r2=788823&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
Fri Jun 26 19:20:08 2009
@@ -19,8 +19,11 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.Socket;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.HashMap;
@@ -31,7 +34,6 @@
 
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.FileRequestEntity;
-import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.cxf.helpers.IOUtils;
@@ -232,20 +234,29 @@
     }
     
     @Test
-    @Ignore
     public void testRetrieveBookAegis3() throws Exception {
-        GetMethod get = new GetMethod("http://localhost:9080/the/thebooks4/bookstore/books/aegis/retrieve");
-        get.setRequestHeader("Content-Type", "*/*");
-        get.setRequestHeader("Accept", "application/xml");
-        HttpClient httpClient = new HttpClient();
-        try {
-            httpClient.executeMethod(get);           
-            String aegisData = getStringFromInputStream(get.getResponseBodyAsStream());
-            InputStream expected = getClass().getResourceAsStream("resources/expected_add_book_aegis.txt");
-            assertEquals(getStringFromInputStream(expected), aegisData);
-        } finally {
-            get.releaseConnection();
+        
+        Socket s = new Socket("localhost", 9080);
+        
+        InputStream is = this.getClass().getResourceAsStream("resources/retrieveRequest.txt");
+        byte[] bytes = IOUtils.readBytesFromStream(is);
+        s.getOutputStream().write(bytes);
+        s.getOutputStream().flush();
+        
+        BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
+        StringBuilder sb = new StringBuilder();
+        String str = null;
+        while ((str = r.readLine()) != null) {
+            sb.append(str);
         }
+        
+        String aegisData = sb.toString();
+        s.getInputStream().close();
+        s.close();
+        String expected = getStringFromInputStream(
+                              getClass().getResourceAsStream("resources/expected_add_book_aegis.txt"));
+        assertTrue(aegisData.contains(expected));
+        
     }
     
     @Test



Mime
View raw message