cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r1222009 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/cors/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/
Date Thu, 22 Dec 2011 02:38:56 GMT
Author: bimargulies
Date: Thu Dec 22 02:38:56 2011
New Revision: 1222009

URL: http://svn.apache.org/viewvc?rev=1222009&view=rev
Log:
CXF-3995: fall back to class-level annotations lacking method-level annotations.

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/cors/CrossOriginResourceSharingFilter.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/AnnotatedCorsServer.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/cors/CrossOriginResourceSharingFilter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/cors/CrossOriginResourceSharingFilter.java?rev=1222009&r1=1222008&r2=1222009&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/cors/CrossOriginResourceSharingFilter.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/cors/CrossOriginResourceSharingFilter.java
Thu Dec 22 02:38:56 2011
@@ -96,7 +96,18 @@ public class CrossOriginResourceSharingF
 
     public Response handleRequest(Message m, ClassResourceInfo resourceClass) {
         OperationResourceInfo opResInfo = m.getExchange().get(OperationResourceInfo.class);
+        /*
+         * If there is an actual method annotated with @OPTIONS, this is the annotation (if
any) from it.
+         * The lookup falls back to it.
+         */
         CrossOriginResourceSharing annotation = getAnnotation(opResInfo);
+        /*
+         * If we don't have an annotation on the target method or an @OPTION method, perhaps
+         * we've got one on the class?
+         */
+        if (annotation == null) {
+            annotation = resourceClass.getServiceClass().getAnnotation(CrossOriginResourceSharing.class);
+        }
 
         if ("OPTIONS".equals(m.get(Message.HTTP_REQUEST_METHOD))) {
           
@@ -196,7 +207,8 @@ public class CrossOriginResourceSharingF
             return null;
         }
         CrossOriginResourceSharing ann = method.getAnnotation(CrossOriginResourceSharing.class);
-        ann = ann == null ? optionAnn : ann; 
+        ann = ann == null ? optionAnn : ann;
+        
         if (ann == null) {
             return createPreflightResponse(m, false);
         }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/AnnotatedCorsServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/AnnotatedCorsServer.java?rev=1222009&r1=1222008&r2=1222009&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/AnnotatedCorsServer.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/AnnotatedCorsServer.java
Thu Dec 22 02:38:56 2011
@@ -23,6 +23,7 @@ import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.OPTIONS;
+import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
@@ -55,6 +56,14 @@ public class AnnotatedCorsServer {
     public String simpleGet(@PathParam("echo") String echo) {
         return echo;
     }
+    
+    @POST
+    @Produces("application/json")
+    @Consumes("application/json")
+    @Path("/unannotatedPost")
+    public Response postSomething() {
+        return Response.ok().build();
+    }
 
     @DELETE
     @Path("/delete")

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java?rev=1222009&r1=1222008&r2=1222009&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java
Thu Dec 22 02:38:56 2011
@@ -151,6 +151,31 @@ public class CrossOriginSimpleTest exten
     }
     
     @Test
+    public void preflightPostClassAnnotation() throws ClientProtocolException, IOException
{
+        HttpClient httpclient = new DefaultHttpClient();
+        HttpOptions httpoptions = new HttpOptions("http://localhost:" + PORT + "/antest/unannotatedPost");
+        httpoptions.addHeader("Origin", "http://in.org");
+        // nonsimple header
+        httpoptions.addHeader("Content-Type", "application/json");
+        httpoptions.addHeader(CorsHeaderConstants.HEADER_AC_REQUEST_METHOD, "POST");
+        httpoptions.addHeader(CorsHeaderConstants.HEADER_AC_REQUEST_HEADERS, "X-custom-1");
+        HttpResponse response = httpclient.execute(httpoptions);
+        assertEquals(200, response.getStatusLine().getStatusCode());
+    }
+    
+    @Test
+    public void simplePostClassAnnotation() throws ClientProtocolException, IOException {
+        HttpClient httpclient = new DefaultHttpClient();
+        HttpOptions httpoptions = new HttpOptions("http://localhost:" + PORT + "/antest/unannotatedPost");
+        httpoptions.addHeader("Origin", "http://in.org");
+        // nonsimple header
+        httpoptions.addHeader("Content-Type", "text/plain");
+        httpoptions.addHeader(CorsHeaderConstants.HEADER_AC_REQUEST_METHOD, "POST");
+        HttpResponse response = httpclient.execute(httpoptions);
+        assertEquals(200, response.getStatusLine().getStatusCode());
+    }
+    
+    @Test
     public void allowStarPassNone() throws Exception {
         // allow *, no origin
         assertAllOrigin(true, null, null, false);



Mime
View raw message