Index: src/test/java/org/jboss/resteasy/test/resource/proxy/Car.java =================================================================== --- src/test/java/org/jboss/resteasy/test/resource/proxy/Car.java (revision 0) +++ src/test/java/org/jboss/resteasy/test/resource/proxy/Car.java (revision 0) @@ -0,0 +1,29 @@ +package org.jboss.resteasy.test.resource.proxy; + +import javax.ws.rs.GET; + +/** + * Objects of this class are used as subresources. + * @author Jozef Hartinger + * + */ +public class Car +{ + + private String id; + + public Car() + { + } + + public Car(String id) + { + this.id = id; + } + + @GET + public String getId() + { + return id; + } +} Index: src/test/java/org/jboss/resteasy/test/resource/proxy/Garage.java =================================================================== --- src/test/java/org/jboss/resteasy/test/resource/proxy/Garage.java (revision 0) +++ src/test/java/org/jboss/resteasy/test/resource/proxy/Garage.java (revision 0) @@ -0,0 +1,46 @@ +package org.jboss.resteasy.test.resource.proxy; + +import javassist.util.proxy.ProxyFactory; +import javassist.util.proxy.ProxyObject; + +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +@Path("/garage") +@Produces("text/plain") +public class Garage +{ + @Path("/car") + public Car getCar() + { + return lookupSeamComponent(); + } + + /** + * This method simulates obtaining a bean from Seam and returning it. - Components.getInstance(Car.class) + * Seam is not used in this test. Car instance is wrapped with a javassist proxy. + * @return Proxied Car instance + */ + private Car lookupSeamComponent() + { + Car car = new Car("MT-123AB"); + CarProxy interceptor = new CarProxy(car); + + ProxyFactory factory = new ProxyFactory(); + factory.setSuperclass(Car.class); + + ProxyObject component = null; + try + { + component = (ProxyObject) factory.createClass().newInstance(); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + component.setHandler(interceptor); + + return (Car) component; + } +} Index: src/test/java/org/jboss/resteasy/test/resource/proxy/CarProxy.java =================================================================== --- src/test/java/org/jboss/resteasy/test/resource/proxy/CarProxy.java (revision 0) +++ src/test/java/org/jboss/resteasy/test/resource/proxy/CarProxy.java (revision 0) @@ -0,0 +1,26 @@ +package org.jboss.resteasy.test.resource.proxy; + +import java.lang.reflect.Method; + +import javassist.util.proxy.MethodHandler; + +/** + * Trivial proxy that forwards method calls to underlying Car instance. + * In Seam, similar proxies are used for nontrivial purposes. + * @author Jozef Hartinger + * + */ +public class CarProxy implements MethodHandler +{ + private Car car; + + public CarProxy(Car car) + { + this.car = car; + } + + public Object invoke(Object object, Method method, Method proceed, Object[] args) throws Throwable + { + return method.invoke(car, args); + } +} Index: src/test/java/org/jboss/resteasy/test/resource/proxy/ProxiedSubresourceTest.java =================================================================== --- src/test/java/org/jboss/resteasy/test/resource/proxy/ProxiedSubresourceTest.java (revision 0) +++ src/test/java/org/jboss/resteasy/test/resource/proxy/ProxiedSubresourceTest.java (revision 0) @@ -0,0 +1,37 @@ +package org.jboss.resteasy.test.resource.proxy; + + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.GetMethod; +import org.jboss.resteasy.test.BaseResourceTest; +import org.junit.Before; +import org.junit.Test; +import static org.jboss.resteasy.test.TestPortProvider.generateURL; +import static junit.framework.Assert.assertEquals; + +public class ProxiedSubresourceTest extends BaseResourceTest +{ + + private static final String URI = generateURL("/garage/car"); + + @Before + public void setUp() + { + addPerRequestResource(Garage.class); + } + + /** + * This method tests RESTEASY-356 + */ + @Test + public void testProxiedSubresource() throws Exception + { + HttpClient client = new HttpClient(); + + GetMethod method = new GetMethod(URI); + method.setRequestHeader("Accept", "text/plain"); + int status = client.executeMethod(method); + assertEquals(200, status); + assertEquals(method.getResponseBodyAsString(), "MT-123AB"); + } +}