cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1125116 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/s...
Date Thu, 19 May 2011 21:23:29 GMT
Author: sergeyb
Date: Thu May 19 21:23:29 2011
New Revision: 1125116

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

........
  r1125115 | sergeyb | 2011-05-19 22:20:09 +0100 (Thu, 19 May 2011) | 1 line
  
  [CXF-3530] Support for Options on subresources
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu May 19 21:23:29 2011
@@ -1 +1 @@
-/cxf/trunk:1099767,1100898,1101399,1102198,1103904,1104144,1104180,1104217,1104230,1124357
+/cxf/trunk:1099767,1100898,1101399,1102198,1103904,1104144,1104180,1104217,1104230,1124357,1125115

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

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1125116&r1=1125115&r2=1125116&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
Thu May 19 21:23:29 2011
@@ -193,7 +193,7 @@ public class JAXRSInvoker extends Abstra
                 Thread.currentThread().setContextClassLoader(contextLoader);
             }
         }
-
+        ClassResourceInfo subCri = null;
         if (ori.isSubResourceLocator()) {
             try {
                 Message msg = exchange.getInMessage();
@@ -209,7 +209,7 @@ public class JAXRSInvoker extends Abstra
 
                 result = checkResultObject(result, subResourcePath);
 
-                ClassResourceInfo subCri = cri.getSubResource(
+                subCri = cri.getSubResource(
                      methodToInvoke.getReturnType(),
                      ClassHelper.getRealClass(result));
                 if (subCri == null) {
@@ -241,8 +241,13 @@ public class JAXRSInvoker extends Abstra
 
                 return this.invoke(exchange, newParams, result);
             } catch (WebApplicationException ex) {
-                Response excResponse = JAXRSUtils.convertFaultToResponse(ex, 
-                                                                         exchange.getInMessage());
+                Response excResponse;
+                if (JAXRSUtils.noResourceMethodForOptions(ex.getResponse(), 
+                        (String)exchange.getInMessage().get(Message.HTTP_REQUEST_METHOD)))
{
+                    excResponse = JAXRSUtils.createResponse(subCri, 200, true);
+                } else {
+                    excResponse = JAXRSUtils.convertFaultToResponse(ex, exchange.getInMessage());
+                }
                 return new MessageContentsList(excResponse);
             }
         }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=1125116&r1=1125115&r2=1125116&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Thu May 19 21:23:29 2011
@@ -206,9 +206,8 @@ public class JAXRSInInterceptor extends 
                                             httpMethod, values, requestContentType, acceptContentTypes,
true);
                 setExchangeProperties(message, ori, values, resources.size());
             } catch (WebApplicationException ex) {
-                if (ex.getResponse() != null && ex.getResponse().getStatus() == 405

-                    && "OPTIONS".equalsIgnoreCase(httpMethod)) {
-                    Response response = JAXRSUtils.createResponseBuilder(resource, 200, true).build();
+                if (JAXRSUtils.noResourceMethodForOptions(ex.getResponse(), httpMethod))
{
+                    Response response = JAXRSUtils.createResponse(resource, 200, true);
                     message.getExchange().put(Response.class, response);
                     return;
                 } else {

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1125116&r1=1125115&r2=1125116&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Thu May 19 21:23:29 2011
@@ -405,11 +405,16 @@ public final class JAXRSUtils {
         if (!"OPTIONS".equalsIgnoreCase(httpMethod) && logNow) {
             LOG.warning(errorMsg.toString());
         }
-        ResponseBuilder rb = createResponseBuilder(resource, status, methodMatched == 0);
-        throw new WebApplicationException(rb.build());
+        Response response = createResponse(resource, status, methodMatched == 0);
+        throw new WebApplicationException(response);
         
     }    
     
+    public static boolean noResourceMethodForOptions(Response exResponse, String httpMethod)
{
+        return exResponse != null && exResponse.getStatus() == 405 
+            && "OPTIONS".equalsIgnoreCase(httpMethod);
+    }
+    
     private static void logNoMatchMessage(OperationResourceInfo ori, 
         String path, String httpMethod, MediaType requestType, List<MediaType> acceptContentTypes)
{
         if (!LOG.isLoggable(Level.FINE)) {
@@ -430,7 +435,7 @@ public final class JAXRSUtils {
         LOG.fine(errorMsg.toString());
     }
 
-    public static ResponseBuilder createResponseBuilder(ClassResourceInfo cri, int status,
boolean addAllow) {
+    public static Response createResponse(ClassResourceInfo cri, int status, boolean addAllow)
{
         ResponseBuilder rb = Response.status(status);
         if (addAllow) {
             Set<String> allowedMethods = cri.getAllowedMethods();
@@ -445,7 +450,7 @@ public final class JAXRSUtils {
                 rb.header("Allow", "HEAD");
             }
         }
-        return rb;
+        return rb.build();
     }
     
     private static boolean matchHttpMethod(String expectedMethod, String httpMethod) {

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java?rev=1125116&r1=1125115&r2=1125116&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book.java
Thu May 19 21:23:29 2011
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -60,6 +61,17 @@ public class Book {
         return id;
     }
     
+    @PUT
+    public void cloneState(Book book) {
+        id = book.getId();
+        name = book.getName();
+    }
+    
+    @GET
+    public Book getState() {
+        return this;
+    }
+    
     @GET
     @Path("chapters/{chapterid}/")    
     @Produces("application/xml;charset=ISO-8859-1")

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1125116&r1=1125115&r2=1125116&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Thu May 19 21:23:29 2011
@@ -45,6 +45,7 @@ import javax.ws.rs.GET;
 import javax.ws.rs.HEAD;
 import javax.ws.rs.HeaderParam;
 import javax.ws.rs.MatrixParam;
+import javax.ws.rs.OPTIONS;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
@@ -248,6 +249,16 @@ public class BookStore {
         return doGetBook(url2.substring(index + 1));
     }
     
+    @OPTIONS
+    @Path("/options")
+    public Response getOptions() throws Exception {
+        return Response.ok().header("Allow", "POST")
+                            .header("Allow", "PUT")
+                            .header("Allow", "GET")
+                            .header("Allow", "DELETE")
+                            .build();
+    }
+    
     @POST
     @Path("post401")
     public Response get401WithText() throws Exception {

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1125116&r1=1125115&r2=1125116&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Thu May 19 21:23:29 2011
@@ -485,6 +485,38 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testExplicitOptions() throws Exception {
+        WebClient wc = 
+            WebClient.create("http://localhost:" 
+                             + PORT + "/bookstore/options");
+        Response response = wc.options();
+        List<Object> values = response.getMetadata().get("Allow");
+        assertNotNull(values);
+        assertTrue(values.contains("POST") && values.contains("GET")
+                   && values.contains("DELETE") && values.contains("PUT"));
+        assertEquals(0, ((InputStream)response.getEntity()).available());
+        List<Object> date = response.getMetadata().get("Date");
+        assertNotNull(date);
+        assertEquals(1, date.size());
+    }
+    
+    @Test
+    public void testOptionsOnSubresource() throws Exception {
+        WebClient wc = 
+            WebClient.create("http://localhost:" 
+                             + PORT + "/bookstore/booksubresource/123");
+        Response response = wc.options();
+        List<Object> values = response.getMetadata().get("Allow");
+        assertNotNull(values);
+        assertTrue(!values.contains("POST") && values.contains("GET")
+                   && !values.contains("DELETE") && values.contains("PUT"));
+        assertEquals(0, ((InputStream)response.getEntity()).available());
+        List<Object> date = response.getMetadata().get("Date");
+        assertNotNull(date);
+        assertEquals(1, date.size());
+    }
+    
+    @Test
     public void testEmptyPost() throws Exception {
         WebClient wc = 
             WebClient.create("http://localhost:" 



Mime
View raw message