cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1423959 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/main/java/org/apach...
Date Wed, 19 Dec 2012 17:09:59 GMT
Author: sergeyb
Date: Wed Dec 19 17:09:59 2012
New Revision: 1423959

URL: http://svn.apache.org/viewvc?rev=1423959&view=rev
Log:
[CXF-2335] Support for the subresource injection

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.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/model/ClassResourceInfoTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1423959&r1=1423958&r2=1423959&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Wed Dec
19 17:09:59 2012
@@ -153,15 +153,19 @@ public class JAXRSInvoker extends Abstra
             }
             
             pushOntoStack(ori, ClassHelper.getRealClass(resourceObject), inMessage);
-                    
-            if (cri.isRoot()) {
+            
+            final boolean contextsAvailable = cri.contextsAvailable();
+            final boolean paramsAvailable = cri.paramsAvailable();
+            if (contextsAvailable || paramsAvailable) {
                 Object realResourceObject = ClassHelper.getRealObject(resourceObject);
-                JAXRSUtils.injectParameters(ori, realResourceObject, inMessage);
-    
-                InjectionUtils.injectContexts(realResourceObject,
-                                              ori.getClassResourceInfo(),
-                                              inMessage);
-                
+                if (paramsAvailable) {
+                    JAXRSUtils.injectParameters(ori, realResourceObject, inMessage);
+                }
+                if (contextsAvailable) {
+                    InjectionUtils.injectContexts(realResourceObject, cri, inMessage);
+                }
+            }
+            if (cri.isRoot()) {
                 ProviderInfo<?> appProvider = 
                     (ProviderInfo<?>)exchange.getEndpoint().get(Application.class.getName());
                 if (appProvider != null) {
@@ -169,7 +173,6 @@ public class JAXRSInvoker extends Abstra
                                                   appProvider,
                                                   inMessage);
                 }
-                
             }
         }
         
@@ -228,7 +231,7 @@ public class JAXRSInvoker extends Abstra
                 result = checkResultObject(result, subResourcePath);
 
                 subCri = cri.getSubResource(methodToInvoke.getReturnType(),
-                    ClassHelper.getRealClass(result));
+                    ClassHelper.getRealClass(result), result);
                 if (subCri == null) {
                     org.apache.cxf.common.i18n.Message errorM =
                         new org.apache.cxf.common.i18n.Message("NO_SUBRESOURCE_FOUND",

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java?rev=1423959&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
Wed Dec 19 17:09:59 2012
@@ -0,0 +1,76 @@
+/**
+ * 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.net.URI;
+
+import javax.ws.rs.InternalServerErrorException;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+
+public class ResourceContextImpl implements ResourceContext {
+
+    private ClassResourceInfo cri;
+    private Class<?> subClass;
+    
+    public ResourceContextImpl(OperationResourceInfo ori) {
+        this.cri = ori.getClassResourceInfo();
+        this.subClass = ori.getMethodToInvoke().getReturnType();
+    }
+    
+    @Override
+    public <T> T getResource(Class<T> cls) {
+        T resource = null;
+        try {
+            resource = cls.newInstance();
+        } catch (Throwable ex) {
+            throw new InternalServerErrorException(ex);
+        }
+        return doInitResource(cls, resource);
+    }
+    
+    public <T> T initResource(T resource) {
+        return doInitResource(resource.getClass(), resource);
+    }
+
+    private <T> T doInitResource(Class<?> cls, T resource) {
+        cri.getSubResource(subClass, cls, resource, true);
+        return resource;
+    }
+
+    @Override
+    public Object matchResource(URI arg0) throws NullPointerException, IllegalArgumentException
{
+        return null;
+    }
+
+    @Override
+    public <T> T matchResource(URI arg0, Class<T> arg1) throws NullPointerException,
+        IllegalArgumentException, ClassCastException {
+        return null;
+    }
+
+    @Override
+    public UriInfo matchUriInfo(URI arg0) throws NullPointerException, IllegalArgumentException
{
+        return null;
+    }
+
+}

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java?rev=1423959&r1=1423958&r2=1423959&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
Wed Dec 19 17:09:59 2012
@@ -56,12 +56,18 @@ public abstract class AbstractResourceIn
         this.bus = bus;
     }
 
-    protected AbstractResourceInfo(Class<?> resourceClass, Class<?> serviceClass,
boolean isRoot, Bus bus) {
+    protected AbstractResourceInfo(Class<?> resourceClass, Class<?> serviceClass,

+                                   boolean isRoot, Bus bus) {
+        this(resourceClass, serviceClass, isRoot, true, bus);
+    }
+    
+    protected AbstractResourceInfo(Class<?> resourceClass, Class<?> serviceClass,

+                                   boolean isRoot, boolean checkContexts, Bus bus) {
         this.bus = bus;
         this.serviceClass = serviceClass;
         this.resourceClass = resourceClass;
         root = isRoot;
-        if (root && resourceClass != null) {
+        if (checkContexts && resourceClass != null) {
             findContexts(serviceClass);   
         }
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java?rev=1423959&r1=1423958&r2=1423959&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/BeanResourceInfo.java
Wed Dec 19 17:09:59 2012
@@ -32,20 +32,29 @@ import org.apache.cxf.jaxrs.utils.Annota
 public abstract class BeanResourceInfo extends AbstractResourceInfo {
     protected List<Field> paramFields;
     protected List<Method> paramMethods;
-    
+    private boolean paramsAvailable;
     
     protected BeanResourceInfo(Bus bus) {
         super(bus);
     }
 
     protected BeanResourceInfo(Class<?> resourceClass, Class<?> serviceClass,
boolean isRoot, Bus bus) {
-        super(resourceClass, serviceClass, isRoot, bus);
-        if (isRoot && resourceClass != null) {
+        this(resourceClass, serviceClass, isRoot, true, bus);
+    }
+    
+    protected BeanResourceInfo(Class<?> resourceClass, Class<?> serviceClass,

+                               boolean isRoot, boolean checkContexts, Bus bus) {
+        super(resourceClass, serviceClass, isRoot, checkContexts, bus);
+        if (checkContexts && resourceClass != null) {
             setParamField(serviceClass);
             setParamMethods(serviceClass);
         }
     }
     
+    public boolean paramsAvailable() {
+        return paramsAvailable;
+    }
+    
     private void setParamField(Class<?> cls) {
         if (Object.class == cls || cls == null) {
             return;
@@ -56,6 +65,7 @@ public abstract class BeanResourceInfo e
                     if (paramFields == null) {
                         paramFields = new ArrayList<Field>();
                     }
+                    paramsAvailable = true;
                     paramFields.add(f);
                 }
             }
@@ -87,6 +97,7 @@ public abstract class BeanResourceInfo e
         if (paramMethods == null) {
             paramMethods = new ArrayList<Method>();
         }
+        paramsAvailable = true;
         paramMethods.add(m);
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=1423959&r1=1423958&r2=1423959&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
Wed Dec 19 17:09:59 2012
@@ -53,7 +53,7 @@ public class ClassResourceInfo extends B
     private String producesTypes;
     private List<String> nameBindings = Collections.emptyList();
     private ClassResourceInfo parent;
-    
+    private Set<String> injectedSubInstances = new HashSet<String>();
     public ClassResourceInfo(ClassResourceInfo cri) {
         super(cri.getBus());       
         if (cri.isCreatedFromModel() && !InjectionUtils.isConcreteClass(cri.getServiceClass()))
{
@@ -77,9 +77,9 @@ public class ClassResourceInfo extends B
     
     public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass,

                              boolean theRoot, boolean enableStatic, Bus bus) {
-        super(theResourceClass, theServiceClass, theRoot, bus);
+        super(theResourceClass, theServiceClass, theRoot, theRoot || enableStatic, bus);
         this.enableStatic = enableStatic;
-        if (root && resourceClass != null) {
+        if (resourceClass != null) {
             nameBindings = AnnotationUtils.getNameBindings(serviceClass.getAnnotations());
         }
     }
@@ -122,25 +122,49 @@ public class ClassResourceInfo extends B
         return subResources.get(key);
     }
     
+    @Override
+    public boolean contextsAvailable() {
+        // avoid re-injecting the contexts if the root acts as subresource
+        return super.contextsAvailable() && (isRoot() || parent != null);
+    }
+    
     public ClassResourceInfo getSubResource(Class<?> typedClass, Class<?> instanceClass)
{
-        
         instanceClass = enableStatic ? typedClass : instanceClass;
+        return getSubResource(typedClass, instanceClass, null, enableStatic);
+    }
+    
+    public ClassResourceInfo getSubResource(Class<?> typedClass, Class<?> instanceClass,
Object instance) {
+        instanceClass = enableStatic ? typedClass : instanceClass;
+        return getSubResource(typedClass, instanceClass, instance, enableStatic);
+    }
+    
+    public ClassResourceInfo getSubResource(Class<?> typedClass, 
+                                            Class<?> instanceClass,
+                                            Object instance,
+                                            boolean resolveContexts) {
         
         SubresourceKey key = new SubresourceKey(typedClass, instanceClass);
         ClassResourceInfo cri = subResources.get(key);
-        if (cri == null && !enableStatic) {
-            cri = ResourceUtils.createClassResourceInfo(typedClass, instanceClass, false,
enableStatic,
+        if (cri == null) {
+            cri = ResourceUtils.createClassResourceInfo(typedClass, instanceClass, false,
resolveContexts,
                                                         getBus());
             if (cri != null) {
-                ClassResourceInfo tmpCri = subResources.putIfAbsent(key, cri);
-                if (tmpCri != null) {
-                    cri = tmpCri;
-                    if (cri != this) {
-                        cri.setParent(this);
-                    }
+                cri.setParent(this);
+                subResources.putIfAbsent(key, cri);
+            }
+        }
+        // this branch will run only if ResourceContext is used 
+        // or static resolution is enabled for subresources initialized
+        // from within singleton root resources (not default)
+        if (resolveContexts && cri != null && cri.isSingleton() &&
instance != null && cri.contextsAvailable()) {
+            synchronized (this) {
+                if (!injectedSubInstances.contains(instance.toString())) {
+                    InjectionUtils.injectContextProxies(cri, instance);
+                    injectedSubInstances.add(instance.toString());
                 }
             }
         }
+        
         return cri;
     }
     
@@ -158,10 +182,10 @@ public class ClassResourceInfo extends B
     }
     
     public List<String> getNameBindings() {
-        if (root || parent == null) {
+        if (parent == null) {
             return nameBindings;
         } else {
-            return parent.nameBindings;
+            return parent.getNameBindings();
         }
     }
     
@@ -216,7 +240,7 @@ public class ClassResourceInfo extends B
     }
     
     public List<MediaType> getProduceMime() {
-        if (root || parent == null) {
+        if (parent == null) {
             if (producesTypes != null) {
                 return JAXRSUtils.parseMediaTypes(producesTypes);
             }
@@ -228,7 +252,7 @@ public class ClassResourceInfo extends B
     }
     
     public List<MediaType> getConsumeMime() {
-        if (root || parent == null) {
+        if (parent == null) {
             if (consumesTypes != null) {
                 return JAXRSUtils.parseMediaTypes(consumesTypes);
             }
@@ -245,7 +269,11 @@ public class ClassResourceInfo extends B
     
     @Override
     public boolean isSingleton() {
-        return resourceProvider != null && resourceProvider.isSingleton();
+        if (parent == null) {
+            return resourceProvider != null && resourceProvider.isSingleton();
+        } else {
+            return parent.isSingleton();
+        }
     }
 
     void setParent(ClassResourceInfo parent) {

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=1423959&r1=1423958&r2=1423959&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
Wed Dec 19 17:09:59 2012
@@ -47,6 +47,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.ResourceContext;
 import javax.ws.rs.container.ResourceInfo;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Context;
@@ -88,6 +89,7 @@ public final class AnnotationUtils {
         classes.add(Providers.class);
         classes.add(Request.class);
         classes.add(ResourceInfo.class);
+        classes.add(ResourceContext.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=1423959&r1=1423958&r2=1423959&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 Wed
Dec 19 17:09:59 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.ResourceContext;
 import javax.ws.rs.container.ResourceInfo;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Cookie;
@@ -113,6 +114,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.ResourceContextImpl;
 import org.apache.cxf.jaxrs.impl.ResourceInfoImpl;
 import org.apache.cxf.jaxrs.impl.SecurityContextImpl;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
@@ -935,6 +937,8 @@ public final class JAXRSUtils {
             o = new MessageContextImpl(m);
         } else if (ResourceInfo.class.isAssignableFrom(clazz)) {
             o = new ResourceInfoImpl(contextMessage);
+        } else if (ResourceContext.class.isAssignableFrom(clazz)) {
+            o = new ResourceContextImpl(contextMessage.getExchange().get(OperationResourceInfo.class));
         } else if (Request.class.isAssignableFrom(clazz)) {
             o = new RequestImpl(contextMessage);
         } else if (Providers.class.isAssignableFrom(clazz)) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java?rev=1423959&r1=1423958&r2=1423959&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ClassResourceInfoTest.java
Wed Dec 19 17:09:59 2012
@@ -117,12 +117,8 @@ public class ClassResourceInfoTest exten
     
     @Test
     public void testGetHttpContexts() {
-        ClassResourceInfo c = new ClassResourceInfo(TestClass.class, false);
+        ClassResourceInfo c = new ClassResourceInfo(TestClass.class, true);
         List<Field> fields = c.getContextFields();
-        assertEquals("Only root classes should check these fields", 0, fields.size());
-        
-        c = new ClassResourceInfo(TestClass.class, true);
-        fields = c.getContextFields();
         Set<Class<?>> clses = new HashSet<Class<?>>(); 
         for (Field f : fields) {
             clses.add(f.getType());

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java?rev=1423959&r1=1423958&r2=1423959&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java Wed Dec
19 17:09:59 2012
@@ -19,10 +19,17 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.XmlType;
 
 
@@ -35,6 +42,10 @@ public class Book2 {
     @XmlElement(name = "id", namespace = "http://www.example.org/books")
     private long id;
     
+    @Context
+    @XmlTransient
+    private UriInfo uriInfo; 
+    
     public Book2() {
     }
     
@@ -58,5 +69,14 @@ public class Book2 {
         return id;
     }
     
+    @GET
+    @Path("rc")
+    @Produces("application/xml")
+    public Book2 initFromContext() {
+        MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
+        id = Long.valueOf(params.getFirst("bookid"));
+        name = params.getFirst("bookname");
+        return this;
+    }
 
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1423959&r1=1423958&r2=1423959&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Wed
Dec 19 17:09:59 2012
@@ -54,6 +54,7 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.container.ResourceContext;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.EntityTag;
@@ -84,6 +85,7 @@ import org.apache.cxf.jaxrs.ext.search.S
 import org.apache.cxf.jaxrs.ext.search.SearchContext;
 import org.apache.cxf.jaxrs.ext.xml.XMLInstruction;
 import org.apache.cxf.jaxrs.ext.xml.XSISchemaLocation;
+import org.apache.cxf.jaxrs.impl.ResourceContextImpl;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.systest.jaxrs.BookServer20.CustomHeaderAdded;
 
@@ -108,10 +110,14 @@ public class BookStore {
     private SecurityContext securityContext;
     @Context 
     private UriInfo ui;
+    @Context 
+    private ResourceContext resourceContext;
     
     @BeanParam
     private BookBean theBookBean;
     
+    private Book2 book2Sub = new Book2();
+    
     public BookStore() {
         init();
     }
@@ -886,6 +892,17 @@ public class BookStore {
         }
     }
     
+    @Path("/booksubresource/context")
+    public Book2 getBookSubResourceRC() {
+        return resourceContext.getResource(Book2.class);
+    }
+    
+    @Path("/booksubresource/instance/context")
+    public Book2 getBookSubResourceInstanceRC(@Context ResourceContext rc) {
+        // This cast is temporarily
+        return ((ResourceContextImpl)rc).initResource(book2Sub);
+    }
+    
     @Path("/booksubresourceobject/{bookId}/")
     public Object getBookSubResourceObject(@PathParam("bookId") String id) throws BookNotFoundFault
{
         return getBookSubResource(id);

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1423959&r1=1423958&r2=1423959&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Wed Dec 19 17:09:59 2012
@@ -112,7 +112,6 @@ public class JAXRSClientServerBookTest e
     
     private void doTestUseParamBeanWebClient(String address) {
         WebClient wc = WebClient.create(address);
-        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000);
         wc.query("id", "120");
         wc.query("id1", "3");
         Book book = wc.get(Book.class);
@@ -1424,6 +1423,29 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testGetBookWithResourceContext() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/booksubresource/context/rc";
+        doTestGetBookWithResourceContext(address);
+    }
+    
+    @Test
+    public void testGetBookWithResourceContextInstance() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/booksubresource/instance/context/rc";
+        doTestGetBookWithResourceContext(address);
+    }
+    
+    private void doTestGetBookWithResourceContext(String address) throws Exception {
+        WebClient wc = WebClient.create(address);
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000);
+        wc.accept("application/xml");
+        wc.query("bookid", "12345");
+        wc.query("bookname", "bookcontext");
+        Book2 book = wc.get(Book2.class);
+        assertEquals(12345L, book.getId());
+        assertEquals("bookcontext", book.getName());
+    }
+    
+    @Test
     public void testGetChapterEncodingDefault() throws Exception {
         
         getAndCompareAsStrings("http://localhost:" 



Mime
View raw message