cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r788822 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs...
Date Fri, 26 Jun 2009 19:18:44 GMT
Author: dkulp
Date: Fri Jun 26 19:18:43 2009
New Revision: 788822

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

........
  r787849 | sergeyb | 2009-06-23 17:54:08 -0400 (Tue, 23 Jun 2009) | 1 line
  
  JAXRS : support for overriding HTTP methods
........

Added:
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
      - copied unchanged from r787849, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestPreprocessorTest.java
    cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/RETRIEVE.java
      - copied unchanged from r787849, cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/RETRIEVE.java
Removed:
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/SystemQueryHandler.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/SystemQueryHandlerTest.java
Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.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:18:43 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,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,788451

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Jun 26 19:18:43 2009
@@ -1 +1 @@
-/cxf/trunk:1-782619,782728-782730,783097,783294,783396,784059,784181-784184,784893-785866,785932,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,788451
+/cxf/trunk:1-782619,782728-782730,783097,783294,783396,784059,784181-784184,784893-785866,785932,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788451

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java?rev=788822&r1=788821&r2=788822&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
Fri Jun 26 19:18:43 2009
@@ -20,9 +20,12 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.cxf.jaxrs.utils.HttpUtils;
@@ -30,9 +33,27 @@
 
 public class RequestPreprocessor {
     
+    private static final String ACCEPT_QUERY = "_type";
+    private static final String METHOD_QUERY = "_method";
+    private static final String METHOD_HEADER = "X-HTTP-Method-Override";
+    
+    
+    private static final Map<String, String> SHORTCUTS;
+    static {
+        SHORTCUTS = new HashMap<String, String>();
+        SHORTCUTS.put("json", "application/json");
+        SHORTCUTS.put("text", "text/*");
+        SHORTCUTS.put("xml", "application/xml");
+        // more to come
+    }
+    
     private Map<Object, Object> languageMappings;
     private Map<Object, Object> extensionMappings;
     
+    public RequestPreprocessor() {
+        this(null, null);
+    }
+    
     public RequestPreprocessor(Map<Object, Object> languageMappings,
                            Map<Object, Object> extensionMappings) {
         this.languageMappings =
@@ -44,6 +65,10 @@
     public String preprocess(Message m, UriInfo u) {
         handleExtensionMappings(m, u);
         handleLanguageMappings(m, u);
+        
+        MultivaluedMap<String, String> queries = u.getQueryParameters();
+        handleTypeQuery(m, queries);
+        handleMethod(m, queries, new HttpHeadersImpl(m));
         return new UriInfoImpl(m, null).getPath();
     }
     
@@ -70,27 +95,54 @@
         
     }
     
-    private void updateAcceptTypeHeader(Message m, String anotherValue) {
-        m.put(Message.ACCEPT_CONTENT_TYPE, anotherValue);
-    }
-    
     @SuppressWarnings("unchecked")
     private void updateAcceptLanguageHeader(Message m, String anotherValue) {
         List<String> acceptLanguage =
-            ((Map<String, List<String>>)m.get(Message.PROTOCOL_HEADERS)).get("Accept-Language");
+            ((Map<String, List<String>>)m.get(Message.PROTOCOL_HEADERS)).get(HttpHeaders.ACCEPT_LANGUAGE);
         if (acceptLanguage == null) {
             acceptLanguage = new ArrayList<String>(); 
         }
         
         acceptLanguage.add(anotherValue);
         ((Map<String, List<String>>)m.get(Message.PROTOCOL_HEADERS))
-            .put("Accept-Language", acceptLanguage);
+            .put(HttpHeaders.ACCEPT_LANGUAGE, acceptLanguage);
     }
     
     private void updatePath(Message m, String path, String suffix) {
         String newPath = path.substring(0, path.length() - (suffix.length() + 1));
         HttpUtils.updatePath(m, newPath);
-        //m.put(Message.REQUEST_URI, newPath);
+    }
+    
+    private void handleMethod(Message m, 
+                              MultivaluedMap<String, String> queries,
+                              HttpHeaders headers) {
+        String method = queries.getFirst(METHOD_QUERY);
+        if (method == null) {
+            List<String> values = headers.getRequestHeader(METHOD_HEADER);
+            if (values.size() == 1) {
+                method = values.get(0);
+            }
+        }
+        if (method != null) {
+            m.put(Message.HTTP_REQUEST_METHOD, method);
+        }
+    }
+    
+    private void handleTypeQuery(Message m, MultivaluedMap<String, String> queries)
{
+        String type = queries.getFirst(ACCEPT_QUERY);
+        if (type != null) {
+            if (SHORTCUTS.containsKey(type)) {
+                type = SHORTCUTS.get(type);
+            }
+            updateAcceptTypeHeader(m, type);
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void updateAcceptTypeHeader(Message m, String acceptValue) {
+        m.put(Message.ACCEPT_CONTENT_TYPE, acceptValue);
+        ((Map<String, List<String>>)m.get(Message.PROTOCOL_HEADERS))
+        .put(HttpHeaders.ACCEPT, Collections.singletonList(acceptValue));
     }
     
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=788822&r1=788821&r2=788822&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Fri Jun 26 19:18:43 2009
@@ -42,7 +42,6 @@
 import org.apache.cxf.jaxrs.ext.ParameterHandler;
 import org.apache.cxf.jaxrs.ext.RequestHandler;
 import org.apache.cxf.jaxrs.ext.ResponseHandler;
-import org.apache.cxf.jaxrs.ext.SystemQueryHandler;
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
 import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
@@ -78,7 +77,6 @@
                                     new PrimitiveTextProvider(),
                                     new MultipartProvider(),
                                     new WebApplicationExceptionMapper(),
-                                    new SystemQueryHandler(),
                                     new WadlGenerator());
     }
     

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=788822&r1=788821&r2=788822&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:18:43 2009
@@ -127,6 +127,13 @@
         return b;
     }
     
+    @RETRIEVE
+    @Path("books/aegis/retrieve")
+    @Produces({"application/html;q=1.0", "application/xml;q=0.5", "application/json;q=0.5"
})
+    public Book getBookAegisRetrieve() {
+        return getBookAegis();
+    }
+    
     @GET
     @Path("books/xslt/{id}")
     @Produces({"text/html", "application/xhtml+xml", "application/xml" })

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=788822&r1=788821&r2=788822&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:18:43 2009
@@ -31,6 +31,7 @@
 
 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;
@@ -61,6 +62,21 @@
     }
     
     @Test
+    public void testGetBookXSLTHtml() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:9080/the/thebooks5/bookstore/books/xslt";
+        WebClient wc = WebClient.create(endpointAddress);
+        wc.accept("application/xhtml+xml").path(666).matrix("name2", 2).query("name", "Action
- ");
+        XMLSource source = wc.get(XMLSource.class);
+        Map<String, String> namespaces = new HashMap<String, String>();
+        namespaces.put("xhtml", "http://www.w3.org/1999/xhtml");
+        Book2 b = source.getNode("xhtml:html/xhtml:body/xhtml:ul/xhtml:Book", namespaces,
Book2.class);
+        assertEquals(666, b.getId());
+        assertEquals("CXF in Action - 2", b.getName());
+    }
+
+    @Test
     public void testGetBookByUriInfo2() throws Exception {
         String endpointAddress =
             "http://localhost:9080/the/thebooks3/bookstore/bookinfo?"
@@ -122,10 +138,18 @@
     }
     
     private void getBook(String endpointAddress, String resource, String type) throws Exception
{
+        getBook(endpointAddress, resource, type, null);
+    }
+    
+    private void getBook(String endpointAddress, String resource, String type, String mHeader)

+        throws Exception {
         URL url = new URL(endpointAddress);
         URLConnection connect = url.openConnection();
         connect.addRequestProperty("Content-Type", "*/*");
         connect.addRequestProperty("Accept", type);
+        if (mHeader != null) {
+            connect.addRequestProperty("X-HTTP-Method-Override", mHeader);
+        }
         InputStream in = connect.getInputStream();           
 
         InputStream expected = getClass().getResourceAsStream(resource);
@@ -192,6 +216,39 @@
     }
     
     @Test
+    public void testRetrieveBookAegis1() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:9080/the/thebooks4/bookstore/books/aegis/retrieve?_method=RETRIEVE";

+        getBook(endpointAddress, "resources/expected_add_book_aegis.txt", "application/xml");

+    }
+    
+    @Test
+    public void testRetrieveBookAegis2() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:9080/the/thebooks4/bookstore/books/aegis/retrieve"; 
+        getBook(endpointAddress, "resources/expected_add_book_aegis.txt", "application/xml",
"RETRIEVE"); 
+    }
+    
+    @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();
+        }
+    }
+    
+    @Test
     public void testGetBookUserResource() throws Exception {
         
         String endpointAddress =
@@ -270,21 +327,6 @@
     }
     
     @Test
-    public void testGetBookXSLTHtml() throws Exception {
-        
-        String endpointAddress =
-            "http://localhost:9080/the/thebooks5/bookstore/books/xslt";
-        WebClient wc = WebClient.create(endpointAddress);
-        wc.accept("application/xhtml+xml").path(666).matrix("name2", 2).query("name", "Action
- ");
-        XMLSource source = wc.get(XMLSource.class);
-        Map<String, String> namespaces = new HashMap<String, String>();
-        namespaces.put("xhtml", "http://www.w3.org/1999/xhtml");
-        Book2 b = source.getNode("xhtml:html/xhtml:body/xhtml:ul/xhtml:Book", namespaces,
Book2.class);
-        assertEquals(666, b.getId());
-        assertEquals("CXF in Action - 2", b.getName());
-    }
-    
-    @Test
     public void testAddValidBookJson() throws Exception {
         doPost("http://localhost:9080/the/bookstore/books/convert",
                200,
@@ -340,6 +382,7 @@
         return bos.getOut().toString();        
     }
 
+        
     @Ignore
     @XmlRootElement(name = "Book", namespace = "http://www.w3.org/1999/xhtml")
     public static class Book2 {



Mime
View raw message