cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1389971 - in /cxf/trunk: 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/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/...
Date Tue, 25 Sep 2012 16:28:46 GMT
Author: sergeyb
Date: Tue Sep 25 16:28:46 2012
New Revision: 1389971

URL: http://svn.apache.org/viewvc?rev=1389971&view=rev
Log:
[CXF-4455] Support for new ResourceInfo context

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceInfoImpl.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceInfoImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceInfoImpl.java?rev=1389971&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceInfoImpl.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceInfoImpl.java
Tue Sep 25 16:28:46 2012
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.impl;
+
+import java.lang.reflect.Method;
+
+import javax.ws.rs.container.ResourceInfo;
+
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.message.Message;
+
+public class ResourceInfoImpl implements ResourceInfo {
+
+    private OperationResourceInfo ori;
+    public ResourceInfoImpl(Message m) {
+        this.ori = m.getExchange().get(OperationResourceInfo.class);
+    }
+    @Override
+    public Method getResourceMethod() {
+        return ori == null ? null : ori.getMethodToInvoke();
+    }
+    @Override
+    public Class<?> getResourceClass() {
+        return ori == null ? null : ori.getClassResourceInfo().getResourceClass();
+    }
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceInfoImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceInfoImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1389971&r1=1389970&r2=1389971&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Tue Sep 25 16:28:46 2012
@@ -755,7 +755,8 @@ public final class ProviderFactory {
             requestHandlers, responseHandlers, exceptionMappers,
             postMatchContainerRequestFilters.values(), preMatchContainerRequestFilters,
             postMatchContainerResponseFilters.values(),
-            responseExceptionMappers, clientRequestFilters, clientResponseFilters);
+            responseExceptionMappers, clientRequestFilters, clientResponseFilters,
+            readerInterceptors, writerInterceptors);
     }
 //CHECKSTYLE:ON
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java?rev=1389971&r1=1389970&r2=1389971&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
Tue Sep 25 16:28:46 2012
@@ -45,6 +45,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.container.ResourceInfo;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
@@ -84,6 +85,7 @@ public final class AnnotationUtils {
         classes.add(ContextResolver.class);
         classes.add(Providers.class);
         classes.add(Request.class);
+        classes.add(ResourceInfo.class);
         classes.add(Application.class);
         // Servlet API
         try {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1389971&r1=1389970&r2=1389971&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Tue
Sep 25 16:28:46 2012
@@ -67,6 +67,7 @@ import javax.ws.rs.container.ContainerRe
 import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.container.ContainerResponseContext;
 import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.container.ResourceInfo;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.HttpHeaders;
@@ -110,6 +111,7 @@ import org.apache.cxf.jaxrs.impl.Provide
 import org.apache.cxf.jaxrs.impl.ReaderInterceptorContextImpl;
 import org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR;
 import org.apache.cxf.jaxrs.impl.RequestImpl;
+import org.apache.cxf.jaxrs.impl.ResourceInfoImpl;
 import org.apache.cxf.jaxrs.impl.SecurityContextImpl;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
 import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
@@ -876,17 +878,19 @@ public final class JAXRSUtils {
         } else if (HttpHeaders.class.isAssignableFrom(clazz)
             || ProtocolHeaders.class.isAssignableFrom(clazz)) {
             o = createHttpHeaders(contextMessage, clazz);
-        } else if (Request.class.isAssignableFrom(clazz)) {
-            o = new RequestImpl(contextMessage);
         } else if (SecurityContext.class.isAssignableFrom(clazz)) {
             SecurityContext customContext = contextMessage.get(SecurityContext.class);
             o = customContext == null ? new SecurityContextImpl(contextMessage) : customContext;
+        } else if (MessageContext.class.isAssignableFrom(clazz)) {
+            o = new MessageContextImpl(m);
+        } else if (ResourceInfo.class.isAssignableFrom(clazz)) {
+            o = new ResourceInfoImpl(contextMessage);
+        } else if (Request.class.isAssignableFrom(clazz)) {
+            o = new RequestImpl(contextMessage);
         } else if (Providers.class.isAssignableFrom(clazz)) {
             o = new ProvidersImpl(contextMessage);
         } else if (ContextResolver.class.isAssignableFrom(clazz)) {
             o = createContextResolver(genericType, contextMessage);
-        } else if (MessageContext.class.isAssignableFrom(clazz)) {
-            o = new MessageContextImpl(m);
         } else if (Application.class.isAssignableFrom(clazz)) {
             ProviderInfo<?> providerInfo = 
                 (ProviderInfo<?>)contextMessage.getExchange().getEndpoint().get(Application.class.getName());

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=1389971&r1=1389970&r2=1389971&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Tue Sep 25
16:28:46 2012
@@ -43,6 +43,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.container.ResourceInfo;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Cookie;
@@ -120,6 +121,7 @@ public class Customer extends AbstractCu
     private UriInfo uriInfo;
     @Context private CustomerContext customerContext;
     @Context private HttpHeaders headers;
+    @Context private ResourceInfo resourceInfo;
     @Context private Request request;
     @Context private SecurityContext sContext;
     @Context private Providers bodyWorkers;
@@ -279,6 +281,10 @@ public class Customer extends AbstractCu
         return headers;
     }
     
+    public ResourceInfo getResourceInfo() {
+        return resourceInfo;
+    }
+    
     public Request getRequest() {
         return request;
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1389971&r1=1389970&r2=1389971&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Tue Sep 25 16:28:46 2012
@@ -35,6 +35,7 @@ import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.container.ResourceInfo;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.HttpHeaders;
@@ -72,6 +73,7 @@ import org.apache.cxf.jaxrs.impl.Metadat
 import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
 import org.apache.cxf.jaxrs.impl.ProvidersImpl;
 import org.apache.cxf.jaxrs.impl.RequestImpl;
+import org.apache.cxf.jaxrs.impl.ResourceInfoImpl;
 import org.apache.cxf.jaxrs.impl.SecurityContextImpl;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpServletRequest;
@@ -1520,7 +1522,7 @@ public class JAXRSUtilsTest extends Asse
     }
     
     @Test
-    public void testPerRequestHttpContextFields() throws Exception {
+    public void testPerRequestContextFields() throws Exception {
         
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
         cri.setResourceProvider(new PerRequestResourceProvider(Customer.class));
@@ -1544,7 +1546,7 @@ public class JAXRSUtilsTest extends Asse
     
     @SuppressWarnings("unchecked")
     @Test
-    public void testSingletonHttpContextFields() throws Exception {
+    public void testSingletonContextFields() throws Exception {
         
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
         Customer c = new Customer();
@@ -1569,6 +1571,8 @@ public class JAXRSUtilsTest extends Asse
                    ((ThreadLocalProxy<HttpHeaders>)c.getHeaders()).get().getClass());
         assertSame(RequestImpl.class, 
                    ((ThreadLocalProxy<Request>)c.getRequest()).get().getClass());
+        assertSame(ResourceInfoImpl.class, 
+                   ((ThreadLocalProxy<ResourceInfo>)c.getResourceInfo()).get().getClass());
         assertSame(SecurityContextImpl.class, 
                    ((ThreadLocalProxy<SecurityContext>)c.getSecurityContext()).get().getClass());
         assertSame(ProvidersImpl.class, 

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java?rev=1389971&r1=1389970&r2=1389971&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
Tue Sep 25 16:28:46 2012
@@ -35,6 +35,8 @@ import javax.ws.rs.container.ContainerRe
 import javax.ws.rs.container.ContainerResponseContext;
 import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.container.PreMatching;
+import javax.ws.rs.container.ResourceInfo;
+import javax.ws.rs.core.Context;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.ReaderInterceptor;
 import javax.ws.rs.ext.ReaderInterceptorContext;
@@ -140,12 +142,16 @@ public class BookServer20 extends Abstra
     }
     
     public static class CustomReaderInterceptor implements ReaderInterceptor {
-
+        @Context
+        private ResourceInfo ri;
         @Override
         public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException,
             WebApplicationException {
-            context.getHeaders().add("ServerReaderInterceptor", "serverRead");
+            if (ri.getResourceClass() == BookStore.class) {
+                context.getHeaders().add("ServerReaderInterceptor", "serverRead");
+            }
             return context.proceed();
+            
         }
         
     }



Mime
View raw message