[seam-commits] Seam SVN: r10967 - in branches/community/Seam_2_1: examples/restbay/src/org/jboss/seam/example/restbay/resteasy and 12 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon May 25 10:19:53 EDT 2009
Author: christian.bauer at jboss.com
Date: 2009-05-25 10:19:52 -0400 (Mon, 25 May 2009)
New Revision: 10967
Added:
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/applicationcomponent/
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/applicationcomponent/ApplicationComponentTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/eventcomponent/
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/eventcomponent/EventComponentTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceapplicationcomponent/
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceapplicationcomponent/InterfaceApplicationComponentTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceapplicationcomponent/InterfaceApplicationComponentTestResourceBean.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceeventcomponent/
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceeventcomponent/InterfaceEventComponentTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceeventcomponent/InterfaceEventComponentTestResourceBean.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfacestatelesscomponent/
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfacestatelesscomponent/InterfaceStatelessComponentTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfacestatelesscomponent/InterfaceStatelessComponentTestResourceBean.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/plain/
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/plain/PlainTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/ApplicationComponentTestProvider.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/InterfaceApplicationComponenTestProviderBean.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/InterfaceApplicationComponentTestProvider.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/PlainResteasyStringConverterProvider.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/PlainTestProvider.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelesscomponent/
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelesscomponent/StatelessComponentTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejb/
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejb/StatelessEjbTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejb/StatelessEjbTestResourceBean.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejbcomponent/
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejbcomponent/StatelessEjbComponentTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejbcomponent/StatelessEjbComponentTestResourceBean.java
Removed:
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/CalendarConverter.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/EventComponentTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/PlainTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/StatelessEjbTestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/StatelessEjbTestResourceBean.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestProvider.java
branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyDispatcher.java
Modified:
branches/community/Seam_2_1/examples/restbay/resources/WEB-INF/components.xml
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestComponent.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestResource.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/BasicServiceTest.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/SecurityTest.java
branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml
branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/AbstractResource.java
branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/Application.java
branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/EntityHomeWrapper.java
branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResourceHome.java
branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResourceQuery.java
branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java
branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyContextInjectionInterceptor.java
branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyResourceAdapter.java
branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/SeamResteasyProviderFactory.java
branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/SeamResteasyResourceFactory.java
Log:
JBSEAM-4167, improved RESTEasy bootstrap code, many new tests
Modified: branches/community/Seam_2_1/examples/restbay/resources/WEB-INF/components.xml
===================================================================
--- branches/community/Seam_2_1/examples/restbay/resources/WEB-INF/components.xml 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/resources/WEB-INF/components.xml 2009-05-25 14:19:52 UTC (rev 10967)
@@ -37,7 +37,7 @@
<resteasy:application resource-path-prefix="/restv1">
<resteasy:resource-class-names>
- <value>org.jboss.seam.example.restbay.resteasy.StatelessEjbTestResourceBean</value>
+ <value>org.jboss.seam.example.restbay.resteasy.statelessejb.StatelessEjbTestResourceBean</value>
</resteasy:resource-class-names>
</resteasy:application>
Deleted: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/CalendarConverter.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/CalendarConverter.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/CalendarConverter.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,41 +0,0 @@
-package org.jboss.seam.example.restbay.resteasy;
-
-import org.jboss.resteasy.spi.StringConverter;
-
-import javax.ws.rs.ext.Provider;
-import java.util.GregorianCalendar;
-import java.text.SimpleDateFormat;
-import java.text.ParseException;
-
-/**
- * Converts QueryParam etc. strings to GregorianCalendar if they are in ISO date format
- * @author Christian Bauer
- */
- at Provider
-public class CalendarConverter implements StringConverter<GregorianCalendar>
-{
- public static final String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
-
- public GregorianCalendar fromString(String s)
- {
- SimpleDateFormat sdf = new SimpleDateFormat(ISO_FORMAT);
- GregorianCalendar cal = new GregorianCalendar();
- try
- {
- cal.setTime(sdf.parse(s));
- }
- catch (ParseException e)
- {
- throw new RuntimeException(e);
- }
- return cal;
-
- }
-
- // TODO: RESTEasy doesn't seem to use that at all
- public String toString(GregorianCalendar gregorianCalendar)
- {
- SimpleDateFormat sdf = new SimpleDateFormat(ISO_FORMAT);
- return sdf.format(gregorianCalendar.getTime());
- }
-}
Deleted: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/EventComponentTestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/EventComponentTestResource.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/EventComponentTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,138 +0,0 @@
-package org.jboss.seam.example.restbay.resteasy;
-
-import org.jboss.resteasy.annotations.Form;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.In;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.CookieParam;
-import javax.ws.rs.Encoded;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MultivaluedMap;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-/**
- * @author Christian Bauer
- */
- at Name("eventComponentTestResource")
- at Path("/eventComponentTest")
-public class EventComponentTestResource extends TestResource
-{
-
- @In
- TestComponent testComponent;
-
- @GET
- @Path("/echouri")
- @Override
- public String echoUri()
- {
- return super.echoUri();
- }
-
- @GET
- @Path("/echoquery")
- @Override
- public String echoQueryParam(@QueryParam("bar") String bar)
- {
- return super.echoQueryParam(bar);
- }
-
- @GET
- @Path("/echoheader")
- @Override
- public String echoHeaderParam(@HeaderParam("bar") String bar)
- {
- return super.echoHeaderParam(bar);
- }
-
- @GET
- @Path("/echocookie")
- @Override
- public String echoCookieParam(@CookieParam("bar") String bar)
- {
- return super.echoCookieParam(bar);
- }
-
- @GET
- @Path("/echotwoparams/{1}/{2}")
- @Override
- public String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two)
- {
- return super.echoTwoParams(one, two);
- }
-
- @GET
- @Path("/echoencoded/{val}")
- @Override
- public String echoEncoded(@PathParam("val") @Encoded String val)
- {
- return super.echoEncoded(val);
- }
-
- @POST
- @Path("/echoformparams")
- @Consumes("application/x-www-form-urlencoded")
- @Override
- public String echoFormParams(MultivaluedMap<String, String> formMap)
- {
- return super.echoFormParams(formMap);
- }
-
- @POST
- @Path("/echoformparams2")
- @Override
- public String echoFormParams2(@FormParam("foo") String[] foo)
- {
- return super.echoFormParams2(foo);
- }
-
- @POST
- @Path("/echoformparams3")
- @Override
- public String echoFormParams3(@Form TestForm form)
- {
- return super.echoFormParams3(form);
- }
-
- @Path("/foo/bar/{baz}")
- @Override
- public SubResource getBar(@PathParam("baz") String baz)
- {
- return super.getBar(baz);
- }
-
- @GET
- @Path("/convertDate/{isoDate}")
- @Override
- public long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate)
- {
- return super.convertPathParam(isoDate);
- }
-
- @GET
- @Path("/trigger/unsupported")
- @Override
- public String throwException()
- {
- return super.throwException();
- }
-
- @GET
- @Path("/commaSeparated")
- @Produces("text/csv")
- @Override
- public List<String[]> getCommaSeparated()
- {
- return testComponent.getCommaSeparated();
- }
-
-}
Deleted: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/PlainTestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/PlainTestResource.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/PlainTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,121 +0,0 @@
-package org.jboss.seam.example.restbay.resteasy;
-
-import org.jboss.resteasy.annotations.Form;
-
-import javax.ws.rs.*;
-import javax.ws.rs.core.MultivaluedMap;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-/**
- * @author Christian Bauer
- */
- at Path("/plainTest")
-public class PlainTestResource extends TestResource
-{
-
- @GET
- @Path("/echouri")
- @Override
- public String echoUri()
- {
- return super.echoUri();
- }
-
- @GET
- @Path("/echoquery")
- @Override
- public String echoQueryParam(@QueryParam("bar") String bar)
- {
- return super.echoQueryParam(bar);
- }
-
- @GET
- @Path("/echoheader")
- @Override
- public String echoHeaderParam(@HeaderParam("bar") String bar)
- {
- return super.echoHeaderParam(bar);
- }
-
- @GET
- @Path("/echocookie")
- @Override
- public String echoCookieParam(@CookieParam("bar") String bar)
- {
- return super.echoCookieParam(bar);
- }
-
- @GET
- @Path("/echotwoparams/{1}/{2}")
- @Override
- public String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two)
- {
- return super.echoTwoParams(one, two);
- }
-
- @GET
- @Path("/echoencoded/{val}")
- @Override
- public String echoEncoded(@PathParam("val") @Encoded String val)
- {
- return super.echoEncoded(val);
- }
-
- @POST
- @Path("/echoformparams")
- @Consumes("application/x-www-form-urlencoded")
- @Override
- public String echoFormParams(MultivaluedMap<String, String> formMap)
- {
- return super.echoFormParams(formMap);
- }
-
- @POST
- @Path("/echoformparams2")
- @Override
- public String echoFormParams2(@FormParam("foo") String[] foo)
- {
- return super.echoFormParams2(foo);
- }
-
- @POST
- @Path("/echoformparams3")
- @Override
- public String echoFormParams3(@Form TestForm form)
- {
- return super.echoFormParams3(form);
- }
-
- @Path("/foo/bar/{baz}")
- @Override
- public SubResource getBar(@PathParam("baz") String baz)
- {
- return super.getBar(baz);
- }
-
- @GET
- @Path("/convertDate/{isoDate}")
- @Override
- public long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate)
- {
- return super.convertPathParam(isoDate);
- }
-
- @GET
- @Path("/trigger/unsupported")
- @Override
- public String throwException()
- {
- return super.throwException();
- }
-
- @GET
- @Path("/commaSeparated")
- @Produces("text/csv")
- @Override
- public List<String[]> getCommaSeparated()
- {
- return super.getCommaSeparated();
- }
-}
Deleted: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/StatelessEjbTestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/StatelessEjbTestResource.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/StatelessEjbTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,93 +0,0 @@
-package org.jboss.seam.example.restbay.resteasy;
-
-import org.jboss.resteasy.annotations.Form;
-
-import javax.ejb.Local;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.UriInfo;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.Path;
-import javax.ws.rs.GET;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.CookieParam;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Encoded;
-import javax.ws.rs.POST;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.Produces;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-/**
- * @author Christian Bauer
- */
- at Local
- at Path("/statelessEjbTest")
-public interface StatelessEjbTestResource
-{
-
- // TODO: RESTEasy can not inject setter/fields on plain EJBs, see https://jira.jboss.org/jira/browse/RESTEASY-151
- // That's why we have to do it through parameter injection below
- @Context
- public void setUriInfo(UriInfo uriInfo);
-
- @Context
- public void setHeaders(HttpHeaders headers);
-
-
- @GET
- @Path("/echouri")
- String echoUri(@Context UriInfo uriInfo); // TODO
-
- @GET
- @Path("/echoquery")
- String echoQueryParam(@QueryParam("bar") String bar);
-
- @GET
- @Path("/echoheader")
- String echoHeaderParam(@HeaderParam("bar") String bar);
-
- @GET
- @Path("/echocookie")
- String echoCookieParam(@CookieParam("bar") String bar);
-
- @GET
- @Path("/echotwoparams/{1}/{2}")
- String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two);
-
- @GET
- @Path("/echoencoded/{val}")
- String echoEncoded(@PathParam("val") @Encoded String val);
-
- @POST
- @Path("/echoformparams")
- @Consumes("application/x-www-form-urlencoded")
- String echoFormParams(MultivaluedMap<String, String> formMap);
-
- @POST
- @Path("/echoformparams2")
- String echoFormParams2(@FormParam("foo") String[] foo);
-
- @POST
- @Path("/echoformparams3")
- String echoFormParams3(@Form TestForm form);
-
- @Path("/foo/bar/{baz}")
- SubResource getBar(@PathParam("baz") String baz);
-
- @GET
- @Path("/convertDate/{isoDate}")
- long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate);
-
- @GET
- @Path("/trigger/unsupported")
- String throwException();
-
- @GET
- @Path("/commaSeparated")
- @Produces("text/csv")
- List<String[]> getCommaSeparated(@Context HttpHeaders headers); // TODO
-}
Deleted: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/StatelessEjbTestResourceBean.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/StatelessEjbTestResourceBean.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/StatelessEjbTestResourceBean.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,101 +0,0 @@
-package org.jboss.seam.example.restbay.resteasy;
-
-import javax.ejb.Stateless;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.UriInfo;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-/**
- * @author Christian Bauer
- */
- at Stateless
-public class StatelessEjbTestResourceBean extends TestResource implements StatelessEjbTestResource
-{
-
- @javax.annotation.Resource // EJB injection!
- javax.ejb.SessionContext ejbSessionContext;
-
-
- public String echoUri(@Context UriInfo uriInfo)
- {
- assert ejbSessionContext != null; // Ensure this is executed in the EJB container
- setUriInfo(uriInfo);
- return super.echoUri();
- }
-
- @Override
- public String echoQueryParam(String bar)
- {
- return super.echoQueryParam(bar);
- }
-
- @Override
- public String echoHeaderParam(String bar)
- {
- return super.echoHeaderParam(bar);
- }
-
- @Override
- public String echoCookieParam(String bar)
- {
- return super.echoCookieParam(bar);
- }
-
- @Override
- public String echoTwoParams(String one, String two)
- {
- return super.echoTwoParams(one, two);
- }
-
- @Override
- public String echoEncoded(String val)
- {
- return super.echoEncoded(val);
- }
-
- @Override
- public String echoFormParams(MultivaluedMap<String, String> formMap)
- {
- return super.echoFormParams(formMap);
- }
-
- @Override
- public String echoFormParams2(String[] foo)
- {
- return super.echoFormParams2(foo);
- }
-
- @Override
- public String echoFormParams3(TestForm form)
- {
- return super.echoFormParams3(form);
- }
-
- @Override
- public SubResource getBar(String baz)
- {
- return super.getBar(baz);
- }
-
- @Override
- public long convertPathParam(GregorianCalendar isoDate)
- {
- return super.convertPathParam(isoDate);
- }
-
- @Override
- public String throwException()
- {
- return super.throwException();
- }
-
- public List<String[]> getCommaSeparated(@Context HttpHeaders headers)
- {
- setHeaders(headers);
- return super.getCommaSeparated();
- }
-
-}
\ No newline at end of file
Modified: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestComponent.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestComponent.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestComponent.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -20,4 +20,8 @@
csv.add(new String[]{"asdf", "123"});
return csv;
}
+
+ public String getTestString() {
+ return "abc";
+ }
}
Deleted: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestProvider.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestProvider.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestProvider.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,50 +0,0 @@
-package org.jboss.seam.example.restbay.resteasy;
-
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Provider;
-import java.lang.reflect.Type;
-import java.lang.annotation.Annotation;
-import java.io.OutputStream;
-import java.io.IOException;
-import java.util.List;
-
-/**
- * @author Christian Bauer
- */
- at Provider
- at Produces("text/csv")
-public class TestProvider implements MessageBodyWriter
-{
-
- public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
- {
- return List.class.isAssignableFrom(aClass);
- }
-
- public long getSize(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
- {
- return -1;
- }
-
- public void writeTo(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType,
- MultivaluedMap httpHeaders, OutputStream outputStream) throws IOException, WebApplicationException
- {
- List<String[]> lines = (List<String[]>) o;
- StringBuilder cvs = new StringBuilder();
- for (String[] line : lines)
- {
- for (String field : line)
- {
- cvs.append(field).append(",");
- }
- cvs.deleteCharAt(cvs.length() - 1);
- cvs.append("\r\n");
- }
- outputStream.write(cvs.toString().getBytes());
-
- }
-}
Modified: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestResource.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -7,6 +7,10 @@
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collections;
+import java.util.Arrays;
/**
* Plain JAX RS root resource, no Seam components/lifecycle.
@@ -109,5 +113,12 @@
return new TestComponent().getCommaSeparated();
}
+ public String[] getCommaSeparatedStrings() {
+ return new String[] {"foo", "bar", "baz"};
+ }
+ public Integer[] getCommaSeparatedIntegers() {
+ return new Integer[] {1, 2, 3};
+ }
+
}
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/applicationcomponent/ApplicationComponentTestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/applicationcomponent/ApplicationComponentTestResource.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/applicationcomponent/ApplicationComponentTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,194 @@
+package org.jboss.seam.example.restbay.resteasy.applicationcomponent;
+
+import org.jboss.resteasy.annotations.Form;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.example.restbay.resteasy.TestResource;
+import org.jboss.seam.example.restbay.resteasy.TestComponent;
+import org.jboss.seam.example.restbay.resteasy.TestForm;
+import org.jboss.seam.example.restbay.resteasy.SubResource;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.contexts.Contexts;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MultivaluedMap;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Name("applicationComponentTestResource")
+ at Path("/applicationComponentTest")
+ at Scope(ScopeType.APPLICATION)
+public class ApplicationComponentTestResource extends TestResource
+{
+ protected final String INSTANCE_CODE_KEY = "applicationComponentTestResource.instanceCode";
+
+ // We want to verify that this is really an application-scoped single instance
+ public ApplicationComponentTestResource()
+ {
+ // Yes, this check is really required, probably because Seam instantiates this twice or something for proxying?! :)
+ if (Contexts.getApplicationContext().get(INSTANCE_CODE_KEY) == null)
+ {
+ Contexts.getApplicationContext().set(INSTANCE_CODE_KEY, hashCode());
+ }
+ }
+
+ protected void assertSingleton()
+ {
+ assert Contexts.getApplicationContext().get(INSTANCE_CODE_KEY).equals(hashCode());
+ }
+
+ @In
+ TestComponent testComponent;
+
+ @GET
+ @Path("/echouri")
+ @Override
+ public String echoUri()
+ {
+ assertSingleton();
+ return super.echoUri();
+ }
+
+ @GET
+ @Path("/echoquery")
+ @Override
+ public String echoQueryParam(@QueryParam("bar") String bar)
+ {
+ assertSingleton();
+ return super.echoQueryParam(bar);
+ }
+
+ @GET
+ @Path("/echoheader")
+ @Override
+ public String echoHeaderParam(@HeaderParam("bar") String bar)
+ {
+ assertSingleton();
+ return super.echoHeaderParam(bar);
+ }
+
+ @GET
+ @Path("/echocookie")
+ @Override
+ public String echoCookieParam(@CookieParam("bar") String bar)
+ {
+ assertSingleton();
+ return super.echoCookieParam(bar);
+ }
+
+ @GET
+ @Path("/echotwoparams/{1}/{2}")
+ @Override
+ public String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two)
+ {
+ assertSingleton();
+ return super.echoTwoParams(one, two);
+ }
+
+ @GET
+ @Path("/echoencoded/{val}")
+ @Override
+ public String echoEncoded(@PathParam("val") @Encoded String val)
+ {
+ assertSingleton();
+ return super.echoEncoded(val);
+ }
+
+ @POST
+ @Path("/echoformparams")
+ @Consumes("application/x-www-form-urlencoded")
+ @Override
+ public String echoFormParams(MultivaluedMap<String, String> formMap)
+ {
+ assertSingleton();
+ return super.echoFormParams(formMap);
+ }
+
+ @POST
+ @Path("/echoformparams2")
+ @Override
+ public String echoFormParams2(@FormParam("foo") String[] foo)
+ {
+ assertSingleton();
+ return super.echoFormParams2(foo);
+ }
+
+ @POST
+ @Path("/echoformparams3")
+ @Override
+ public String echoFormParams3(@Form TestForm form)
+ {
+ assertSingleton();
+ return super.echoFormParams3(form);
+ }
+
+ @Path("/foo/bar/{baz}")
+ @Override
+ public SubResource getBar(@PathParam("baz") String baz)
+ {
+ assertSingleton();
+ return super.getBar(baz);
+ }
+
+ @GET
+ @Path("/convertDate/{isoDate}")
+ @Override
+ public long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate)
+ {
+ assertSingleton();
+ return super.convertPathParam(isoDate);
+ }
+
+ @GET
+ @Path("/trigger/unsupported")
+ @Override
+ public String throwException()
+ {
+ assertSingleton();
+ return super.throwException();
+ }
+
+ @GET
+ @Path("/commaSeparated")
+ @Produces("text/csv")
+ @Override
+ public List<String[]> getCommaSeparated()
+ {
+ assertSingleton();
+ return testComponent.getCommaSeparated();
+ }
+
+ @GET
+ @Path("/commaSeparatedStrings")
+ @Produces("text/plain")
+ @Override
+ public String[] getCommaSeparatedStrings()
+ {
+ assertSingleton();
+ return super.getCommaSeparatedStrings();
+ }
+
+ @GET
+ @Path("/commaSeparatedIntegers")
+ @Produces("text/plain")
+ @Override
+ public Integer[] getCommaSeparatedIntegers()
+ {
+ assertSingleton();
+ return super.getCommaSeparatedIntegers();
+ }
+}
\ No newline at end of file
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/eventcomponent/EventComponentTestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/eventcomponent/EventComponentTestResource.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/eventcomponent/EventComponentTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,159 @@
+package org.jboss.seam.example.restbay.resteasy.eventcomponent;
+
+import org.jboss.resteasy.annotations.Form;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.example.restbay.resteasy.TestResource;
+import org.jboss.seam.example.restbay.resteasy.TestComponent;
+import org.jboss.seam.example.restbay.resteasy.TestForm;
+import org.jboss.seam.example.restbay.resteasy.SubResource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MultivaluedMap;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Name("eventComponentTestResource")
+ at Path("/eventComponentTest")
+public class EventComponentTestResource extends TestResource
+{
+
+ @In
+ TestComponent testComponent;
+
+ @GET
+ @Path("/echouri")
+ @Override
+ public String echoUri()
+ {
+ return super.echoUri();
+ }
+
+ @GET
+ @Path("/echoquery")
+ @Override
+ public String echoQueryParam(@QueryParam("bar") String bar)
+ {
+ return super.echoQueryParam(bar);
+ }
+
+ @GET
+ @Path("/echoheader")
+ @Override
+ public String echoHeaderParam(@HeaderParam("bar") String bar)
+ {
+ return super.echoHeaderParam(bar);
+ }
+
+ @GET
+ @Path("/echocookie")
+ @Override
+ public String echoCookieParam(@CookieParam("bar") String bar)
+ {
+ return super.echoCookieParam(bar);
+ }
+
+ @GET
+ @Path("/echotwoparams/{1}/{2}")
+ @Override
+ public String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two)
+ {
+ return super.echoTwoParams(one, two);
+ }
+
+ @GET
+ @Path("/echoencoded/{val}")
+ @Override
+ public String echoEncoded(@PathParam("val") @Encoded String val)
+ {
+ return super.echoEncoded(val);
+ }
+
+ @POST
+ @Path("/echoformparams")
+ @Consumes("application/x-www-form-urlencoded")
+ @Override
+ public String echoFormParams(MultivaluedMap<String, String> formMap)
+ {
+ return super.echoFormParams(formMap);
+ }
+
+ @POST
+ @Path("/echoformparams2")
+ @Override
+ public String echoFormParams2(@FormParam("foo") String[] foo)
+ {
+ return super.echoFormParams2(foo);
+ }
+
+ @POST
+ @Path("/echoformparams3")
+ @Override
+ public String echoFormParams3(@Form TestForm form)
+ {
+ return super.echoFormParams3(form);
+ }
+
+ @Path("/foo/bar/{baz}")
+ @Override
+ public SubResource getBar(@PathParam("baz") String baz)
+ {
+ return super.getBar(baz);
+ }
+
+ @GET
+ @Path("/convertDate/{isoDate}")
+ @Override
+ public long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate)
+ {
+ return super.convertPathParam(isoDate);
+ }
+
+ @GET
+ @Path("/trigger/unsupported")
+ @Override
+ public String throwException()
+ {
+ return super.throwException();
+ }
+
+ @GET
+ @Path("/commaSeparated")
+ @Produces("text/csv")
+ @Override
+ public List<String[]> getCommaSeparated()
+ {
+ return testComponent.getCommaSeparated();
+ }
+
+ @GET
+ @Path("/commaSeparatedStrings")
+ @Produces("text/plain")
+ @Override
+ public String[] getCommaSeparatedStrings()
+ {
+ return super.getCommaSeparatedStrings();
+ }
+
+ @GET
+ @Path("/commaSeparatedIntegers")
+ @Produces("text/plain")
+ @Override
+ public Integer[] getCommaSeparatedIntegers()
+ {
+ return super.getCommaSeparatedIntegers();
+ }
+}
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceapplicationcomponent/InterfaceApplicationComponentTestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceapplicationcomponent/InterfaceApplicationComponentTestResource.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceapplicationcomponent/InterfaceApplicationComponentTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,101 @@
+package org.jboss.seam.example.restbay.resteasy.interfaceapplicationcomponent;
+
+import org.jboss.resteasy.annotations.Form;
+import org.jboss.seam.example.restbay.resteasy.TestForm;
+import org.jboss.seam.example.restbay.resteasy.SubResource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Path("/interfaceApplicationComponentTest")
+public interface InterfaceApplicationComponentTestResource
+{
+
+ @Context
+ public void setUriInfo(UriInfo uriInfo);
+
+ @Context
+ public void setHeaders(HttpHeaders headers);
+
+ @GET
+ @Path("/echouri")
+ String echoUri();
+
+ @GET
+ @Path("/echoquery")
+ String echoQueryParam(@QueryParam("bar") String bar);
+
+ @GET
+ @Path("/echoheader")
+ String echoHeaderParam(@HeaderParam("bar") String bar);
+
+ @GET
+ @Path("/echocookie")
+ String echoCookieParam(@CookieParam("bar") String bar);
+
+ @GET
+ @Path("/echotwoparams/{1}/{2}")
+ String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two);
+
+ @GET
+ @Path("/echoencoded/{val}")
+ String echoEncoded(@PathParam("val") @Encoded String val);
+
+ @POST
+ @Path("/echoformparams")
+ @Consumes("application/x-www-form-urlencoded")
+ String echoFormParams(MultivaluedMap<String, String> formMap);
+
+ @POST
+ @Path("/echoformparams2")
+ String echoFormParams2(@FormParam("foo") String[] foo);
+
+ @POST
+ @Path("/echoformparams3")
+ String echoFormParams3(@Form TestForm form);
+
+ @Path("/foo/bar/{baz}")
+ SubResource getBar(@PathParam("baz") String baz);
+
+ @GET
+ @Path("/convertDate/{isoDate}")
+ long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate);
+
+ @GET
+ @Path("/trigger/unsupported")
+ String throwException();
+
+ @GET
+ @Path("/commaSeparated")
+ @Produces("text/csv")
+ List<String[]> getCommaSeparated();
+
+ @GET
+ @Path("/commaSeparatedStrings")
+ @Produces("text/plain")
+ String[] getCommaSeparatedStrings();
+
+ @GET
+ @Path("/commaSeparatedIntegers")
+ @Produces("text/plain")
+ Integer[] getCommaSeparatedIntegers();
+
+}
\ No newline at end of file
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceapplicationcomponent/InterfaceApplicationComponentTestResourceBean.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceapplicationcomponent/InterfaceApplicationComponentTestResourceBean.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceapplicationcomponent/InterfaceApplicationComponentTestResourceBean.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,32 @@
+package org.jboss.seam.example.restbay.resteasy.interfaceapplicationcomponent;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.example.restbay.resteasy.TestComponent;
+import org.jboss.seam.example.restbay.resteasy.TestResource;
+
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Name("interfaceApplicationComponentTestResource")
+ at Scope(ScopeType.EVENT)
+public class InterfaceApplicationComponentTestResourceBean extends TestResource implements InterfaceApplicationComponentTestResource
+{
+
+ @In
+ TestComponent testComponent;
+
+ @Override
+ public List<String[]> getCommaSeparated()
+ {
+ assert headers.getAcceptableMediaTypes().size() == 2;
+ assert headers.getAcceptableMediaTypes().get(0).toString().equals("text/plain");
+ assert headers.getAcceptableMediaTypes().get(1).toString().equals("text/csv");
+ return testComponent.getCommaSeparated();
+ }
+
+}
\ No newline at end of file
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceeventcomponent/InterfaceEventComponentTestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceeventcomponent/InterfaceEventComponentTestResource.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceeventcomponent/InterfaceEventComponentTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,101 @@
+package org.jboss.seam.example.restbay.resteasy.interfaceeventcomponent;
+
+import org.jboss.resteasy.annotations.Form;
+import org.jboss.seam.example.restbay.resteasy.TestForm;
+import org.jboss.seam.example.restbay.resteasy.SubResource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Path("/interfaceEventComponentTest")
+public interface InterfaceEventComponentTestResource
+{
+
+ @Context
+ public void setUriInfo(UriInfo uriInfo);
+
+ @Context
+ public void setHeaders(HttpHeaders headers);
+
+ @GET
+ @Path("/echouri")
+ String echoUri();
+
+ @GET
+ @Path("/echoquery")
+ String echoQueryParam(@QueryParam("bar") String bar);
+
+ @GET
+ @Path("/echoheader")
+ String echoHeaderParam(@HeaderParam("bar") String bar);
+
+ @GET
+ @Path("/echocookie")
+ String echoCookieParam(@CookieParam("bar") String bar);
+
+ @GET
+ @Path("/echotwoparams/{1}/{2}")
+ String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two);
+
+ @GET
+ @Path("/echoencoded/{val}")
+ String echoEncoded(@PathParam("val") @Encoded String val);
+
+ @POST
+ @Path("/echoformparams")
+ @Consumes("application/x-www-form-urlencoded")
+ String echoFormParams(MultivaluedMap<String, String> formMap);
+
+ @POST
+ @Path("/echoformparams2")
+ String echoFormParams2(@FormParam("foo") String[] foo);
+
+ @POST
+ @Path("/echoformparams3")
+ String echoFormParams3(@Form TestForm form);
+
+ @Path("/foo/bar/{baz}")
+ SubResource getBar(@PathParam("baz") String baz);
+
+ @GET
+ @Path("/convertDate/{isoDate}")
+ long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate);
+
+ @GET
+ @Path("/trigger/unsupported")
+ String throwException();
+
+ @GET
+ @Path("/commaSeparated")
+ @Produces("text/csv")
+ List<String[]> getCommaSeparated();
+
+ @GET
+ @Path("/commaSeparatedStrings")
+ @Produces("text/plain")
+ String[] getCommaSeparatedStrings();
+
+ @GET
+ @Path("/commaSeparatedIntegers")
+ @Produces("text/plain")
+ Integer[] getCommaSeparatedIntegers();
+
+}
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceeventcomponent/InterfaceEventComponentTestResourceBean.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceeventcomponent/InterfaceEventComponentTestResourceBean.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfaceeventcomponent/InterfaceEventComponentTestResourceBean.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,32 @@
+package org.jboss.seam.example.restbay.resteasy.interfaceeventcomponent;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.example.restbay.resteasy.TestResource;
+import org.jboss.seam.example.restbay.resteasy.TestComponent;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Name("interfaceEventComponentTestResource")
+ at Scope(ScopeType.EVENT)
+public class InterfaceEventComponentTestResourceBean extends TestResource implements InterfaceEventComponentTestResource
+{
+
+ @In
+ TestComponent testComponent;
+
+ @Override
+ public List<String[]> getCommaSeparated()
+ {
+ assert headers.getAcceptableMediaTypes().size() == 2;
+ assert headers.getAcceptableMediaTypes().get(0).toString().equals("text/plain");
+ assert headers.getAcceptableMediaTypes().get(1).toString().equals("text/csv");
+ return testComponent.getCommaSeparated();
+ }
+
+}
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfacestatelesscomponent/InterfaceStatelessComponentTestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfacestatelesscomponent/InterfaceStatelessComponentTestResource.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfacestatelesscomponent/InterfaceStatelessComponentTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,101 @@
+package org.jboss.seam.example.restbay.resteasy.interfacestatelesscomponent;
+
+import org.jboss.resteasy.annotations.Form;
+import org.jboss.seam.example.restbay.resteasy.TestForm;
+import org.jboss.seam.example.restbay.resteasy.SubResource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Path("/interfaceStatelessComponentTest")
+public interface InterfaceStatelessComponentTestResource
+{
+
+ @Context
+ public void setUriInfo(UriInfo uriInfo);
+
+ @Context
+ public void setHeaders(HttpHeaders headers);
+
+ @GET
+ @Path("/echouri")
+ String echoUri();
+
+ @GET
+ @Path("/echoquery")
+ String echoQueryParam(@QueryParam("bar") String bar);
+
+ @GET
+ @Path("/echoheader")
+ String echoHeaderParam(@HeaderParam("bar") String bar);
+
+ @GET
+ @Path("/echocookie")
+ String echoCookieParam(@CookieParam("bar") String bar);
+
+ @GET
+ @Path("/echotwoparams/{1}/{2}")
+ String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two);
+
+ @GET
+ @Path("/echoencoded/{val}")
+ String echoEncoded(@PathParam("val") @Encoded String val);
+
+ @POST
+ @Path("/echoformparams")
+ @Consumes("application/x-www-form-urlencoded")
+ String echoFormParams(MultivaluedMap<String, String> formMap);
+
+ @POST
+ @Path("/echoformparams2")
+ String echoFormParams2(@FormParam("foo") String[] foo);
+
+ @POST
+ @Path("/echoformparams3")
+ String echoFormParams3(@Form TestForm form);
+
+ @Path("/foo/bar/{baz}")
+ SubResource getBar(@PathParam("baz") String baz);
+
+ @GET
+ @Path("/convertDate/{isoDate}")
+ long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate);
+
+ @GET
+ @Path("/trigger/unsupported")
+ String throwException();
+
+ @GET
+ @Path("/commaSeparated")
+ @Produces("text/csv")
+ List<String[]> getCommaSeparated();
+
+ @GET
+ @Path("/commaSeparatedStrings")
+ @Produces("text/plain")
+ String[] getCommaSeparatedStrings();
+
+ @GET
+ @Path("/commaSeparatedIntegers")
+ @Produces("text/plain")
+ Integer[] getCommaSeparatedIntegers();
+
+}
\ No newline at end of file
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfacestatelesscomponent/InterfaceStatelessComponentTestResourceBean.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfacestatelesscomponent/InterfaceStatelessComponentTestResourceBean.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/interfacestatelesscomponent/InterfaceStatelessComponentTestResourceBean.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,153 @@
+package org.jboss.seam.example.restbay.resteasy.interfacestatelesscomponent;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.example.restbay.resteasy.SubResource;
+import org.jboss.seam.example.restbay.resteasy.TestComponent;
+import org.jboss.seam.example.restbay.resteasy.TestForm;
+import org.jboss.seam.example.restbay.resteasy.TestResource;
+
+import javax.ws.rs.core.MultivaluedMap;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Name("interfaceStatelessComponentTestResource")
+ at Scope(ScopeType.EVENT)
+public class InterfaceStatelessComponentTestResourceBean extends TestResource implements InterfaceStatelessComponentTestResource
+{
+
+ protected final String INSTANCE_CODE_KEY = "interfaceStatelessComponentTestResource.instanceCode";
+
+ // We want to verify that this is really stateless (Seam doesn't pool POJO instances, so that should work)
+ public InterfaceStatelessComponentTestResourceBean()
+ {
+ Integer instanceCode;
+ if ((instanceCode = (Integer)Contexts.getApplicationContext().get(INSTANCE_CODE_KEY)) != null)
+ {
+ assert !instanceCode.equals(hashCode());
+ }
+ Contexts.getApplicationContext().set(INSTANCE_CODE_KEY, hashCode());
+ }
+
+ protected void assertStateless()
+ {
+ assert !Contexts.getApplicationContext().get(INSTANCE_CODE_KEY).equals(hashCode());
+ }
+
+ @In
+ TestComponent testComponent;
+
+ @Override
+ public String echoUri()
+ {
+ assertStateless();
+ return super.echoUri();
+ }
+
+ @Override
+ public String echoQueryParam(String bar)
+ {
+ assertStateless();
+ return super.echoQueryParam(bar);
+ }
+
+ @Override
+ public String echoHeaderParam(String bar)
+ {
+ assertStateless();
+ return super.echoHeaderParam(bar);
+ }
+
+ @Override
+ public String echoCookieParam(String bar)
+ {
+ assertStateless();
+ return super.echoCookieParam(bar);
+ }
+
+ @Override
+ public String echoTwoParams(String one, String two)
+ {
+ assertStateless();
+ return super.echoTwoParams(one, two);
+ }
+
+ @Override
+ public String echoEncoded(String val)
+ {
+ assertStateless();
+ return super.echoEncoded(val);
+ }
+
+ @Override
+ public String echoFormParams(MultivaluedMap<String, String> formMap)
+ {
+ assertStateless();
+ return super.echoFormParams(formMap);
+ }
+
+ @Override
+ public String echoFormParams2(String[] foo)
+ {
+ assertStateless();
+ return super.echoFormParams2(foo);
+ }
+
+ @Override
+ public String echoFormParams3(TestForm form)
+ {
+ assertStateless();
+ return super.echoFormParams3(form);
+ }
+
+ @Override
+ public SubResource getBar(String baz)
+ {
+ assertStateless();
+ return super.getBar(baz);
+ }
+
+ @Override
+ public long convertPathParam(GregorianCalendar isoDate)
+ {
+ assertStateless();
+ return super.convertPathParam(isoDate);
+ }
+
+ @Override
+ public String throwException()
+ {
+ assertStateless();
+ return super.throwException();
+ }
+
+ @Override
+ public List<String[]> getCommaSeparated()
+ {
+ assertStateless();
+ assert headers.getAcceptableMediaTypes().size() == 2;
+ assert headers.getAcceptableMediaTypes().get(0).toString().equals("text/plain");
+ assert headers.getAcceptableMediaTypes().get(1).toString().equals("text/csv");
+ return testComponent.getCommaSeparated();
+ }
+
+ @Override
+ public String[] getCommaSeparatedStrings()
+ {
+ assertStateless();
+ return super.getCommaSeparatedStrings();
+ }
+
+ @Override
+ public Integer[] getCommaSeparatedIntegers()
+ {
+ assertStateless();
+ return super.getCommaSeparatedIntegers();
+ }
+}
\ No newline at end of file
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/plain/PlainTestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/plain/PlainTestResource.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/plain/PlainTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,142 @@
+package org.jboss.seam.example.restbay.resteasy.plain;
+
+import org.jboss.resteasy.annotations.Form;
+import org.jboss.seam.example.restbay.resteasy.TestResource;
+import org.jboss.seam.example.restbay.resteasy.TestForm;
+import org.jboss.seam.example.restbay.resteasy.SubResource;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.MultivaluedMap;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Path("/plainTest")
+public class PlainTestResource extends TestResource
+{
+
+ @GET
+ @Path("/echouri")
+ @Override
+ public String echoUri()
+ {
+ return super.echoUri();
+ }
+
+ @GET
+ @Path("/echoquery")
+ @Override
+ public String echoQueryParam(@QueryParam("bar") String bar)
+ {
+ return super.echoQueryParam(bar);
+ }
+
+ @GET
+ @Path("/echoheader")
+ @Override
+ public String echoHeaderParam(@HeaderParam("bar") String bar)
+ {
+ return super.echoHeaderParam(bar);
+ }
+
+ @GET
+ @Path("/echocookie")
+ @Override
+ public String echoCookieParam(@CookieParam("bar") String bar)
+ {
+ return super.echoCookieParam(bar);
+ }
+
+ @GET
+ @Path("/echotwoparams/{1}/{2}")
+ @Override
+ public String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two)
+ {
+ return super.echoTwoParams(one, two);
+ }
+
+ @GET
+ @Path("/echoencoded/{val}")
+ @Override
+ public String echoEncoded(@PathParam("val") @Encoded String val)
+ {
+ return super.echoEncoded(val);
+ }
+
+ @POST
+ @Path("/echoformparams")
+ @Consumes("application/x-www-form-urlencoded")
+ @Override
+ public String echoFormParams(MultivaluedMap<String, String> formMap)
+ {
+ return super.echoFormParams(formMap);
+ }
+
+ @POST
+ @Path("/echoformparams2")
+ @Override
+ public String echoFormParams2(@FormParam("foo") String[] foo)
+ {
+ return super.echoFormParams2(foo);
+ }
+
+ @POST
+ @Path("/echoformparams3")
+ @Override
+ public String echoFormParams3(@Form TestForm form)
+ {
+ return super.echoFormParams3(form);
+ }
+
+ @Path("/foo/bar/{baz}")
+ @Override
+ public SubResource getBar(@PathParam("baz") String baz)
+ {
+ return super.getBar(baz);
+ }
+
+ @GET
+ @Path("/convertDate/{isoDate}")
+ @Override
+ public long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate)
+ {
+ return super.convertPathParam(isoDate);
+ }
+
+ @GET
+ @Path("/trigger/unsupported")
+ @Override
+ public String throwException()
+ {
+ return super.throwException();
+ }
+
+ @GET
+ @Path("/commaSeparated")
+ @Produces("text/csv")
+ @Override
+ public List<String[]> getCommaSeparated()
+ {
+ return super.getCommaSeparated();
+ }
+
+ @GET
+ @Path("/commaSeparatedStrings")
+ @Produces("text/plain")
+ @Override
+ public String[] getCommaSeparatedStrings()
+ {
+ return super.getCommaSeparatedStrings();
+ }
+
+ @GET
+ @Path("/commaSeparatedIntegers")
+ @Produces("text/plain")
+ @Override
+ public Integer[] getCommaSeparatedIntegers()
+ {
+ return super.getCommaSeparatedIntegers();
+ }
+}
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/ApplicationComponentTestProvider.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/ApplicationComponentTestProvider.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/ApplicationComponentTestProvider.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,63 @@
+package org.jboss.seam.example.restbay.resteasy.provider;
+
+import org.jboss.seam.example.restbay.resteasy.TestComponent;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.ScopeType;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+/**
+ * @author Christian Bauer
+ */
+ at Name("applicationComponentTestProvider")
+ at Scope(ScopeType.APPLICATION)
+ at Provider
+ at Produces("text/plain")
+public class ApplicationComponentTestProvider implements MessageBodyWriter
+{
+
+ @In
+ TestComponent testComponent;
+
+ public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
+ {
+ return aClass.isArray() && (aClass.getComponentType().equals(String.class)) ;
+ }
+
+ public long getSize(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
+ {
+ return -1;
+ }
+
+ public void writeTo(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap httpHeaders, OutputStream outputStream) throws IOException, WebApplicationException
+ {
+ String[] strings = (String[])o;
+
+ StringBuilder line = new StringBuilder();
+
+ line.append(testComponent.getTestString()).append(",");
+
+ for (String string : strings)
+ {
+ line.append(string).append(",");
+ }
+ if (line.length()>0) {
+ line.deleteCharAt(line.length() - 1);
+ }
+
+ outputStream.write(line.toString().getBytes());
+
+ }
+}
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/InterfaceApplicationComponenTestProviderBean.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/InterfaceApplicationComponenTestProviderBean.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/InterfaceApplicationComponenTestProviderBean.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,58 @@
+package org.jboss.seam.example.restbay.resteasy.provider;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.example.restbay.resteasy.TestComponent;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.In;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.MediaType;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+/**
+ * @author Christian Bauer
+ */
+ at Name("interfaceApplicationComponentTestProvider")
+ at Scope(ScopeType.APPLICATION)
+public class InterfaceApplicationComponenTestProviderBean implements InterfaceApplicationComponentTestProvider
+{
+
+ @In
+ TestComponent testComponent;
+
+ public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
+ {
+ return aClass.isArray() && (aClass.getComponentType().equals(Integer.class)) ;
+ }
+
+ public long getSize(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
+ {
+ return -1;
+ }
+
+ public void writeTo(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap httpHeaders, OutputStream outputStream) throws IOException, WebApplicationException
+ {
+ Integer[] integers = (Integer[])o;
+
+ StringBuilder line = new StringBuilder();
+
+ line.append(testComponent.getTestString()).append(",");
+
+ for (Integer integer : integers)
+ {
+ line.append(integer).append(",");
+ }
+ if (line.length()>0) {
+ line.deleteCharAt(line.length() - 1);
+ }
+
+ outputStream.write(line.toString().getBytes());
+
+ }
+}
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/InterfaceApplicationComponentTestProvider.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/InterfaceApplicationComponentTestProvider.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/InterfaceApplicationComponentTestProvider.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,15 @@
+package org.jboss.seam.example.restbay.resteasy.provider;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * @author Christian Bauer
+ */
+ at Provider
+ at Produces("text/plain")
+public interface InterfaceApplicationComponentTestProvider extends MessageBodyWriter
+{
+
+}
\ No newline at end of file
Copied: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/PlainResteasyStringConverterProvider.java (from rev 10932, branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/CalendarConverter.java)
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/PlainResteasyStringConverterProvider.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/PlainResteasyStringConverterProvider.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,42 @@
+package org.jboss.seam.example.restbay.resteasy.provider;
+
+import org.jboss.resteasy.spi.StringConverter;
+
+import javax.ws.rs.ext.Provider;
+import java.util.GregorianCalendar;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
+
+/**
+ * Converts QueryParam etc. strings to GregorianCalendar if they are in ISO date format
+ *
+ * @author Christian Bauer
+ */
+ at Provider
+public class PlainResteasyStringConverterProvider implements StringConverter<GregorianCalendar>
+{
+ public static final String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
+
+ public GregorianCalendar fromString(String s)
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat(ISO_FORMAT);
+ GregorianCalendar cal = new GregorianCalendar();
+ try
+ {
+ cal.setTime(sdf.parse(s));
+ }
+ catch (ParseException e)
+ {
+ throw new RuntimeException(e);
+ }
+ return cal;
+
+ }
+
+ // TODO: RESTEasy doesn't seem to use that at all
+ public String toString(GregorianCalendar gregorianCalendar)
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat(ISO_FORMAT);
+ return sdf.format(gregorianCalendar.getTime());
+ }
+}
Copied: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/PlainTestProvider.java (from rev 10932, branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/TestProvider.java)
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/PlainTestProvider.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/provider/PlainTestProvider.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,50 @@
+package org.jboss.seam.example.restbay.resteasy.provider;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Provider
+ at Produces("text/csv")
+public class PlainTestProvider implements MessageBodyWriter
+{
+
+ public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
+ {
+ return List.class.isAssignableFrom(aClass);
+ }
+
+ public long getSize(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType)
+ {
+ return -1;
+ }
+
+ public void writeTo(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap httpHeaders, OutputStream outputStream) throws IOException, WebApplicationException
+ {
+ List<String[]> lines = (List<String[]>) o;
+ StringBuilder cvs = new StringBuilder();
+ for (String[] line : lines)
+ {
+ for (String field : line)
+ {
+ cvs.append(field).append(",");
+ }
+ cvs.deleteCharAt(cvs.length() - 1);
+ cvs.append("\r\n");
+ }
+ outputStream.write(cvs.toString().getBytes());
+
+ }
+}
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelesscomponent/StatelessComponentTestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelesscomponent/StatelessComponentTestResource.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelesscomponent/StatelessComponentTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,199 @@
+package org.jboss.seam.example.restbay.resteasy.statelesscomponent;
+
+import org.jboss.resteasy.annotations.Form;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.example.restbay.resteasy.TestResource;
+import org.jboss.seam.example.restbay.resteasy.TestComponent;
+import org.jboss.seam.example.restbay.resteasy.TestForm;
+import org.jboss.seam.example.restbay.resteasy.SubResource;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.contexts.Contexts;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MultivaluedMap;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Name("statelessComponentTestResource")
+ at Path("/statelessComponentTest")
+ at Scope(ScopeType.STATELESS)
+public class StatelessComponentTestResource extends TestResource
+{
+
+ protected final String INSTANCE_CODE_KEY = "statelessComponentTestResource.instanceCode";
+
+ // We want to verify that this is really stateless (Seam doesn't pool POJO instances, so that should work)
+ public StatelessComponentTestResource()
+ {
+ Integer instanceCode;
+ if ((instanceCode = (Integer)Contexts.getApplicationContext().get(INSTANCE_CODE_KEY)) != null)
+ {
+ assert !instanceCode.equals(hashCode());
+ }
+ Contexts.getApplicationContext().set(INSTANCE_CODE_KEY, hashCode());
+ }
+
+ protected void assertStateless()
+ {
+ assert !Contexts.getApplicationContext().get(INSTANCE_CODE_KEY).equals(hashCode());
+ }
+
+ @In
+ TestComponent testComponent;
+
+ @GET
+ @Path("/echouri")
+ @Override
+ public String echoUri()
+ {
+ assertStateless();
+ return super.echoUri();
+ }
+
+ @GET
+ @Path("/echoquery")
+ @Override
+ public String echoQueryParam(@QueryParam("bar") String bar)
+ {
+ assertStateless();
+ return super.echoQueryParam(bar);
+ }
+
+ @GET
+ @Path("/echoheader")
+ @Override
+ public String echoHeaderParam(@HeaderParam("bar") String bar)
+ {
+ assertStateless();
+ return super.echoHeaderParam(bar);
+ }
+
+ @GET
+ @Path("/echocookie")
+ @Override
+ public String echoCookieParam(@CookieParam("bar") String bar)
+ {
+ assertStateless();
+ return super.echoCookieParam(bar);
+ }
+
+ @GET
+ @Path("/echotwoparams/{1}/{2}")
+ @Override
+ public String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two)
+ {
+ assertStateless();
+ return super.echoTwoParams(one, two);
+ }
+
+ @GET
+ @Path("/echoencoded/{val}")
+ @Override
+ public String echoEncoded(@PathParam("val") @Encoded String val)
+ {
+ assertStateless();
+ return super.echoEncoded(val);
+ }
+
+ @POST
+ @Path("/echoformparams")
+ @Consumes("application/x-www-form-urlencoded")
+ @Override
+ public String echoFormParams(MultivaluedMap<String, String> formMap)
+ {
+ assertStateless();
+ return super.echoFormParams(formMap);
+ }
+
+ @POST
+ @Path("/echoformparams2")
+ @Override
+ public String echoFormParams2(@FormParam("foo") String[] foo)
+ {
+ assertStateless();
+ return super.echoFormParams2(foo);
+ }
+
+ @POST
+ @Path("/echoformparams3")
+ @Override
+ public String echoFormParams3(@Form TestForm form)
+ {
+ assertStateless();
+ return super.echoFormParams3(form);
+ }
+
+ @Path("/foo/bar/{baz}")
+ @Override
+ public SubResource getBar(@PathParam("baz") String baz)
+ {
+ assertStateless();
+ return super.getBar(baz);
+ }
+
+ @GET
+ @Path("/convertDate/{isoDate}")
+ @Override
+ public long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate)
+ {
+ assertStateless();
+ return super.convertPathParam(isoDate);
+ }
+
+ @GET
+ @Path("/trigger/unsupported")
+ @Override
+ public String throwException()
+ {
+ assertStateless();
+ return super.throwException();
+ }
+
+ @GET
+ @Path("/commaSeparated")
+ @Produces("text/csv")
+ @Override
+ public List<String[]> getCommaSeparated()
+ {
+ assertStateless();
+ assert headers.getAcceptableMediaTypes().size() == 2;
+ assert headers.getAcceptableMediaTypes().get(0).toString().equals("text/plain");
+ assert headers.getAcceptableMediaTypes().get(1).toString().equals("text/csv");
+ return testComponent.getCommaSeparated();
+ }
+
+ @GET
+ @Path("/commaSeparatedStrings")
+ @Produces("text/plain")
+ @Override
+ public String[] getCommaSeparatedStrings()
+ {
+ assertStateless();
+ return super.getCommaSeparatedStrings();
+ }
+
+ @GET
+ @Path("/commaSeparatedIntegers")
+ @Produces("text/plain")
+ @Override
+ public Integer[] getCommaSeparatedIntegers()
+ {
+ assertStateless();
+ return super.getCommaSeparatedIntegers();
+ }
+}
\ No newline at end of file
Copied: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejb/StatelessEjbTestResource.java (from rev 10932, branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/StatelessEjbTestResource.java)
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejb/StatelessEjbTestResource.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejb/StatelessEjbTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,106 @@
+package org.jboss.seam.example.restbay.resteasy.statelessejb;
+
+import org.jboss.resteasy.annotations.Form;
+import org.jboss.seam.example.restbay.resteasy.TestForm;
+import org.jboss.seam.example.restbay.resteasy.SubResource;
+
+import javax.ejb.Local;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.Path;
+import javax.ws.rs.GET;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.POST;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.Produces;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Local
+ at Path("/statelessEjbTest")
+public interface StatelessEjbTestResource
+{
+
+ // TODO: RESTEasy can not inject setter/fields on plain EJBs, see https://jira.jboss.org/jira/browse/RESTEASY-151
+ // That's why we have to do it through parameter injection below
+ @Context
+ public void setUriInfo(UriInfo uriInfo);
+
+ @Context
+ public void setHeaders(HttpHeaders headers);
+
+
+ @GET
+ @Path("/echouri")
+ String echoUri(@Context UriInfo uriInfo); // TODO
+
+ @GET
+ @Path("/echoquery")
+ String echoQueryParam(@QueryParam("bar") String bar);
+
+ @GET
+ @Path("/echoheader")
+ String echoHeaderParam(@HeaderParam("bar") String bar);
+
+ @GET
+ @Path("/echocookie")
+ String echoCookieParam(@CookieParam("bar") String bar);
+
+ @GET
+ @Path("/echotwoparams/{1}/{2}")
+ String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two);
+
+ @GET
+ @Path("/echoencoded/{val}")
+ String echoEncoded(@PathParam("val") @Encoded String val);
+
+ @POST
+ @Path("/echoformparams")
+ @Consumes("application/x-www-form-urlencoded")
+ String echoFormParams(MultivaluedMap<String, String> formMap);
+
+ @POST
+ @Path("/echoformparams2")
+ String echoFormParams2(@FormParam("foo") String[] foo);
+
+ @POST
+ @Path("/echoformparams3")
+ String echoFormParams3(@Form TestForm form);
+
+ @Path("/foo/bar/{baz}")
+ SubResource getBar(@PathParam("baz") String baz);
+
+ @GET
+ @Path("/convertDate/{isoDate}")
+ long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate);
+
+ @GET
+ @Path("/trigger/unsupported")
+ String throwException();
+
+ @GET
+ @Path("/commaSeparated")
+ @Produces("text/csv")
+ List<String[]> getCommaSeparated(@Context HttpHeaders headers); // TODO
+
+ @GET
+ @Path("/commaSeparatedStrings")
+ @Produces("text/plain")
+ String[] getCommaSeparatedStrings();
+
+ @GET
+ @Path("/commaSeparatedIntegers")
+ @Produces("text/plain")
+ Integer[] getCommaSeparatedIntegers();
+
+}
Copied: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejb/StatelessEjbTestResourceBean.java (from rev 10932, branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/StatelessEjbTestResourceBean.java)
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejb/StatelessEjbTestResourceBean.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejb/StatelessEjbTestResourceBean.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,35 @@
+package org.jboss.seam.example.restbay.resteasy.statelessejb;
+
+import org.jboss.seam.example.restbay.resteasy.TestResource;
+
+import javax.ejb.Stateless;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Stateless
+public class StatelessEjbTestResourceBean extends TestResource implements StatelessEjbTestResource
+{
+
+ @javax.annotation.Resource // EJB injection!
+ javax.ejb.SessionContext ejbSessionContext;
+
+
+ public String echoUri(@Context UriInfo uriInfo)
+ {
+ assert ejbSessionContext != null; // Ensure this is executed in the EJB container
+ setUriInfo(uriInfo);
+ return super.echoUri();
+ }
+
+ public List<String[]> getCommaSeparated(@Context HttpHeaders headers)
+ {
+ setHeaders(headers);
+ return super.getCommaSeparated();
+ }
+
+}
\ No newline at end of file
Added: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejbcomponent/StatelessEjbComponentTestResource.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejbcomponent/StatelessEjbComponentTestResource.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejbcomponent/StatelessEjbComponentTestResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,105 @@
+package org.jboss.seam.example.restbay.resteasy.statelessejbcomponent;
+
+import org.jboss.resteasy.annotations.Form;
+import org.jboss.seam.example.restbay.resteasy.TestForm;
+import org.jboss.seam.example.restbay.resteasy.SubResource;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.GET;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Encoded;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
+import javax.ejb.Local;
+import java.util.List;
+import java.util.GregorianCalendar;
+
+/**
+ * @author Christian Bauer
+ */
+ at Local
+ at Path("/statelessEjbComponentTest")
+public interface StatelessEjbComponentTestResource
+{
+ // TODO: RESTEasy can not inject setter/fields on plain EJBs, see https://jira.jboss.org/jira/browse/RESTEASY-151
+ // That's why we have to do it through parameter injection below
+ @Context
+ public void setUriInfo(UriInfo uriInfo);
+
+ @Context
+ public void setHeaders(HttpHeaders headers);
+
+
+ @GET
+ @Path("/echouri")
+ String echoUri(@Context UriInfo uriInfo); // TODO
+
+ @GET
+ @Path("/echoquery")
+ String echoQueryParam(@QueryParam("bar") String bar);
+
+ @GET
+ @Path("/echoheader")
+ String echoHeaderParam(@HeaderParam("bar") String bar);
+
+ @GET
+ @Path("/echocookie")
+ String echoCookieParam(@CookieParam("bar") String bar);
+
+ @GET
+ @Path("/echotwoparams/{1}/{2}")
+ String echoTwoParams(@PathParam("1") String one, @PathParam("2") String two);
+
+ @GET
+ @Path("/echoencoded/{val}")
+ String echoEncoded(@PathParam("val") @Encoded String val);
+
+ @POST
+ @Path("/echoformparams")
+ @Consumes("application/x-www-form-urlencoded")
+ String echoFormParams(MultivaluedMap<String, String> formMap);
+
+ @POST
+ @Path("/echoformparams2")
+ String echoFormParams2(@FormParam("foo") String[] foo);
+
+ @POST
+ @Path("/echoformparams3")
+ String echoFormParams3(@Form TestForm form);
+
+ @Path("/foo/bar/{baz}")
+ SubResource getBar(@PathParam("baz") String baz);
+
+ @GET
+ @Path("/convertDate/{isoDate}")
+ long convertPathParam(@PathParam("isoDate") GregorianCalendar isoDate);
+
+ @GET
+ @Path("/trigger/unsupported")
+ String throwException();
+
+ @GET
+ @Path("/commaSeparated")
+ @Produces("text/csv")
+ List<String[]> getCommaSeparated(@Context HttpHeaders headers); // TODO
+
+ @GET
+ @Path("/commaSeparatedStrings")
+ @Produces("text/plain")
+ String[] getCommaSeparatedStrings();
+
+ @GET
+ @Path("/commaSeparatedIntegers")
+ @Produces("text/plain")
+ Integer[] getCommaSeparatedIntegers();
+
+}
Copied: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejbcomponent/StatelessEjbComponentTestResourceBean.java (from rev 10628, branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/StatelessEjbTestResourceBean.java)
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejbcomponent/StatelessEjbComponentTestResourceBean.java (rev 0)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejbcomponent/StatelessEjbComponentTestResourceBean.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -0,0 +1,45 @@
+package org.jboss.seam.example.restbay.resteasy.statelessejbcomponent;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.example.restbay.resteasy.TestComponent;
+import org.jboss.seam.example.restbay.resteasy.TestResource;
+
+import javax.ejb.Stateless;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+import java.util.List;
+
+/**
+ * @author Christian Bauer
+ */
+ at Name("statelessEjbComponentTestResource")
+ at Scope(ScopeType.STATELESS)
+ at Stateless
+public class StatelessEjbComponentTestResourceBean extends TestResource implements StatelessEjbComponentTestResource
+{
+
+ @javax.annotation.Resource // EJB injection!
+ javax.ejb.SessionContext ejbSessionContext;
+
+ @In
+ TestComponent testComponent;
+
+ public String echoUri(@Context UriInfo uriInfo)
+ {
+ assert ejbSessionContext != null; // Ensure this is executed in the EJB container
+ setUriInfo(uriInfo);
+ return super.echoUri();
+ }
+
+ public List<String[]> getCommaSeparated(@Context HttpHeaders headers)
+ {
+ setHeaders(headers);
+ super.getCommaSeparated(); // Ignore return, just to run the assertions
+ return testComponent.getCommaSeparated();
+ }
+
+}
\ No newline at end of file
Property changes on: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/resteasy/statelessejbcomponent/StatelessEjbComponentTestResourceBean.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/BasicServiceTest.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/BasicServiceTest.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/BasicServiceTest.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -12,6 +12,58 @@
import java.util.Map;
import java.util.HashMap;
+/**
+ * <p>
+ * This is the test matrix for resources:
+ * </p>
+ *
+ * <pre>
+ * | EVENT | CONVERSATION | SESSION | APPLICATION | STATELESS
+ * ---------------------------------------------------------------------------------------------
+ * Plain JAX-RS Resource | OK | - | - | - | -
+ * ---------------------------------------------------------------------------------------------
+ * POJO Seam Component Resource | OK | ? | ? | OK | OK
+ * ---------------------------------------------------------------------------------------------
+ * POJO interface-annotated Component | OK | ? | ? | OK | OK
+ * ---------------------------------------------------------------------------------------------
+ * EJB Plain SLSB Resource | - | - | - | - | OK
+ * ---------------------------------------------------------------------------------------------
+ * EJB SLSB Seam Component Resource | - | - | - | - | OK
+ * ---------------------------------------------------------------------------------------------
+ * EJB SFSB Seam Component Resource | ? | ? | ? | ? | -
+ * ---------------------------------------------------------------------------------------------
+ * </pre>
+ *
+ * <p>
+ * Note that all EJB resources are always @Path annotated on their interface, not the implementation class.
+ * </p>
+ *
+ * <p>
+ * This is the test matrix for providers:
+ * </p>
+ *
+ * <pre>
+ * | EVENT | CONVERSATION | SESSION | APPLICATION | STATELESS
+ * ---------------------------------------------------------------------------------------------
+ * Plain JAX-RS Provider | - | - | - | - | OK
+ * ---------------------------------------------------------------------------------------------
+ * RESTEasy StringConverter Provider | - | - | - | - | OK
+ * ---------------------------------------------------------------------------------------------
+ * RESTEasy StringConverter Component | ? | - | - | ? | ?
+ * ---------------------------------------------------------------------------------------------
+ * POJO Seam Component Provider | ? | - | - | OK | ?
+ * ---------------------------------------------------------------------------------------------
+ * POJO interface-annotated Component | ? | - | - | OK | ?
+ * ---------------------------------------------------------------------------------------------
+ * EJB Plain SLSB Provider | - | - | - | - | ?
+ * ---------------------------------------------------------------------------------------------
+ * EJB SLSB Seam Component Provider | - | - | - | - | ?
+ * ---------------------------------------------------------------------------------------------
+ * EJB SFSB Seam Component Resource | ? | - | - | ? | -
+ * ---------------------------------------------------------------------------------------------
+ * </pre>
+ *
+ */
public class BasicServiceTest extends ResourceSeamTest
{
@@ -29,8 +81,17 @@
{
return new String[][] {
{ "/restv1/plainTest" },
+
{ "/restv1/eventComponentTest" },
- { "/restv1/statelessEjbTest" }
+ { "/restv1/applicationComponentTest" },
+ { "/restv1/statelessComponentTest" },
+
+ { "/restv1/interfaceEventComponentTest" },
+ { "/restv1/interfaceApplicationComponentTest" },
+ { "/restv1/interfaceStatelessComponentTest" },
+
+ { "/restv1/statelessEjbTest" },
+ { "/restv1/statelessEjbComponentTest" }
};
}
@@ -270,5 +331,41 @@
}.run();
+ new ResourceRequest(Method.GET, resourcePath + "/commaSeparatedStrings")
+ {
+
+ @Override
+ protected void prepareRequest(MockHttpServletRequest request)
+ {
+ request.addHeader("Accept", "text/plain");
+ }
+
+ @Override
+ protected void onResponse(MockHttpServletResponse response)
+ {
+ assert response.getStatus() == 200;
+ assert response.getContentAsString().equals("abc,foo,bar,baz");
+ }
+
+ }.run();
+
+ new ResourceRequest(Method.GET, resourcePath + "/commaSeparatedIntegers")
+ {
+
+ @Override
+ protected void prepareRequest(MockHttpServletRequest request)
+ {
+ request.addHeader("Accept", "text/plain");
+ }
+
+ @Override
+ protected void onResponse(MockHttpServletResponse response)
+ {
+ assert response.getStatus() == 200;
+ assert response.getContentAsString().equals("abc,1,2,3");
+ }
+
+ }.run();
+
}
}
Modified: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/SecurityTest.java
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/SecurityTest.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/SecurityTest.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -8,7 +8,8 @@
import org.testng.annotations.Test;
/**
- * This class tests RESTEasy integration with together with Seam Security
+ * This class tests RESTEasy integration together with Seam Security.
+ *
* @author Jozef Hartinger
*
*/
Modified: branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml
===================================================================
--- branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/examples/restbay/src/org/jboss/seam/example/restbay/test/testng.xml 2009-05-25 14:19:52 UTC (rev 10967)
@@ -13,19 +13,19 @@
<class name="org.jboss.seam.example.restbay.test.AuctionServiceTest"/>
</classes>
</test>
-
+
<test name="RestBay: ResourceHome">
<classes>
<class name="org.jboss.seam.example.restbay.test.ResourceHomeTest"/>
</classes>
</test>
-
+
<test name="RestBay: ResourceQuery">
<classes>
<class name="org.jboss.seam.example.restbay.test.ResourceQueryTest"/>
</classes>
</test>
-
+
<!-- <test name="RestBay: Security">
<classes>
<class name="org.jboss.seam.example.restbay.test.SecurityTest"/>
Modified: branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/AbstractResource.java
===================================================================
--- branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/AbstractResource.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/AbstractResource.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -32,9 +32,8 @@
* Resource class used by ResourceHome and ResourceQuery components. Contains
* information about path, media types and entity class the component operates
* on.
- *
+ *
* @author Jozef Hartinger
- *
* @param <T> entity class
*/
public abstract class AbstractResource<T>
@@ -49,7 +48,7 @@
public AbstractResource()
{
- mediaTypes = new MediaType[] { MediaType.APPLICATION_XML_TYPE };
+ mediaTypes = new MediaType[]{MediaType.APPLICATION_XML_TYPE};
}
public String[] getMediaTypes()
@@ -79,7 +78,7 @@
/**
* Retrieve entity class. If not set, type parameters of a superclass are
* examined.
- *
+ *
* @return entity class
*/
public Class<T> getEntityClass()
@@ -105,9 +104,9 @@
/**
* Retrieve a suffix of this resource's URI. See {@link #setPath(String path)}
- *
- * @see javax.ws.rs.Path
+ *
* @return path
+ * @see javax.ws.rs.Path
*/
public String getPath()
{
@@ -118,7 +117,7 @@
* Set the path this resource will operate on. This method is intended to be
* used only by Seam to create a resource configured in component descriptor.
* To specify the path in other cases, use @Path annotation. See
- *
+ *
* @param path
*/
public void setPath(String path)
@@ -130,7 +129,7 @@
* Select a media type that will be used for marshalling entity. Media type
* is selected from the intersection of media types supported by this
* resource and media types accepted by client.
- *
+ *
* @return selected media type, returns null if no suitable media type is
* found
*/
@@ -149,7 +148,7 @@
/**
* Check if media type passed as parameter is supported by this resource.
- *
+ *
* @param mediaType
* @return true if and only if the media type is accepted by this resource
*/
Modified: branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/Application.java
===================================================================
--- branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/Application.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/Application.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,3 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.seam.resteasy;
import org.jboss.seam.ScopeType;
@@ -11,8 +32,8 @@
import java.util.*;
/**
- * Resteasy and JAX-RS configuration, override in components.xml to
- * customize Resteasy settings.
+ * RESTEasy and JAX-RS configuration, override in components.xml to
+ * customize RESTful request processing and RESTEasy settings.
*
* @author Christian Bauer
*/
@@ -25,37 +46,37 @@
final private Map<Class<?>, Set<Component>> providerClasses = new HashMap<Class<?>, Set<Component>>();
final private Map<Class<?>, Set<Component>> resourceClasses = new HashMap<Class<?>, Set<Component>>();
-
- private List<String> providerClassNames = new ArrayList<String>();
- private List<String> resourceClassNames = new ArrayList<String>();
- private Map<String, String> mediaTypeMappings = new HashMap<String, String>();
- private Map<String, String> languageMappings = new HashMap<String, String>();
+ private List<String> providerClassNames = new ArrayList<String>();
+ private List<String> resourceClassNames = new ArrayList<String>();
- private boolean scanProviders = true;
- private boolean scanResources = true;
- private boolean useBuiltinProviders = true;
- private boolean destroySessionAfterRequest = true;
+ private Map<String, String> mediaTypeMappings = new HashMap<String, String>();
+ private Map<String, String> languageMappings = new HashMap<String, String>();
- private String resourcePathPrefix = "/rest";
- private boolean stripSeamResourcePath = true;
+ private boolean scanProviders = true;
+ private boolean scanResources = true;
+ private boolean useBuiltinProviders = true;
+ private boolean destroySessionAfterRequest = true;
- public Application()
- {
- super();
- }
+ private String resourcePathPrefix = "/rest";
+ private boolean stripSeamResourcePath = true;
- public Set<Class<?>> getProviderClasses()
- {
- return providerClasses.keySet();
- }
+ public Application()
+ {
+ super();
+ }
- @Override
- public Set<Class<?>> getClasses()
- {
- return resourceClasses.keySet();
- }
+ public Set<Class<?>> getProviderClasses()
+ {
+ return providerClasses.keySet();
+ }
+ @Override
+ public Set<Class<?>> getClasses()
+ {
+ return resourceClasses.keySet();
+ }
+
public void addProviderClass(Class<?> clazz)
{
providerClasses.put(clazz, null);
@@ -72,10 +93,10 @@
components.add(component);
}
- public void removeProviderClass(Class<?> clazz)
- {
- providerClasses.remove(clazz);
- }
+ public void removeProviderClass(Class<?> clazz)
+ {
+ providerClasses.remove(clazz);
+ }
public void addResourceClass(Class<?> clazz)
{
@@ -93,10 +114,10 @@
components.addAll(newComponents);
}
- public void removeResourceClass(Class<?> clazz)
- {
- resourceClasses.remove(clazz);
- }
+ public void removeResourceClass(Class<?> clazz)
+ {
+ resourceClasses.remove(clazz);
+ }
public Set<Component> getProviderClassComponent(Class clazz)
{
@@ -108,109 +129,109 @@
return resourceClasses.get(clazz) != null ? resourceClasses.get(clazz) : null;
}
- public Map<String, MediaType> getMediaTypeMappings()
- {
- Map<String, MediaType> extMap = new HashMap<String, MediaType>();
- for (String ext : mediaTypeMappings.keySet())
- {
- String value = mediaTypeMappings.get(ext);
- extMap.put(ext, MediaType.valueOf(value));
- }
- return extMap;
- }
+ public Map<String, MediaType> getMediaTypeMappings()
+ {
+ Map<String, MediaType> extMap = new HashMap<String, MediaType>();
+ for (String ext : mediaTypeMappings.keySet())
+ {
+ String value = mediaTypeMappings.get(ext);
+ extMap.put(ext, MediaType.valueOf(value));
+ }
+ return extMap;
+ }
- public void setMediaTypeMappings(Map<String, String> mediaTypeMappings)
- {
- this.mediaTypeMappings = mediaTypeMappings;
- }
+ public void setMediaTypeMappings(Map<String, String> mediaTypeMappings)
+ {
+ this.mediaTypeMappings = mediaTypeMappings;
+ }
- public Map<String, String> getLanguageMappings()
- {
- return languageMappings;
- }
+ public Map<String, String> getLanguageMappings()
+ {
+ return languageMappings;
+ }
- public void setLanguageMappings(Map<String, String> languageMappings)
- {
- this.languageMappings = languageMappings;
- }
+ public void setLanguageMappings(Map<String, String> languageMappings)
+ {
+ this.languageMappings = languageMappings;
+ }
- public List<String> getProviderClassNames()
- {
- return providerClassNames;
- }
+ public List<String> getProviderClassNames()
+ {
+ return providerClassNames;
+ }
- public void setProviderClassNames(List<String> providerClassNames)
- {
- this.providerClassNames = providerClassNames;
- }
+ public void setProviderClassNames(List<String> providerClassNames)
+ {
+ this.providerClassNames = providerClassNames;
+ }
- public List<String> getResourceClassNames()
- {
- return resourceClassNames;
- }
+ public List<String> getResourceClassNames()
+ {
+ return resourceClassNames;
+ }
- public void setResourceClassNames(List<String> resourceClassNames)
- {
- this.resourceClassNames = resourceClassNames;
- }
+ public void setResourceClassNames(List<String> resourceClassNames)
+ {
+ this.resourceClassNames = resourceClassNames;
+ }
- public boolean isScanProviders()
- {
- return scanProviders;
- }
+ public boolean isScanProviders()
+ {
+ return scanProviders;
+ }
- public void setScanProviders(boolean scanProviders)
- {
- this.scanProviders = scanProviders;
- }
+ public void setScanProviders(boolean scanProviders)
+ {
+ this.scanProviders = scanProviders;
+ }
- public boolean isScanResources()
- {
- return scanResources;
- }
+ public boolean isScanResources()
+ {
+ return scanResources;
+ }
- public void setScanResources(boolean scanResources)
- {
- this.scanResources = scanResources;
- }
+ public void setScanResources(boolean scanResources)
+ {
+ this.scanResources = scanResources;
+ }
- public boolean isUseBuiltinProviders()
- {
- return useBuiltinProviders;
- }
+ public boolean isUseBuiltinProviders()
+ {
+ return useBuiltinProviders;
+ }
- public void setUseBuiltinProviders(boolean useBuiltinProviders)
- {
- this.useBuiltinProviders = useBuiltinProviders;
- }
+ public void setUseBuiltinProviders(boolean useBuiltinProviders)
+ {
+ this.useBuiltinProviders = useBuiltinProviders;
+ }
- public boolean isDestroySessionAfterRequest()
- {
- return destroySessionAfterRequest;
- }
+ public boolean isDestroySessionAfterRequest()
+ {
+ return destroySessionAfterRequest;
+ }
- public void setDestroySessionAfterRequest(boolean destroySessionAfterRequest)
- {
- this.destroySessionAfterRequest = destroySessionAfterRequest;
- }
+ public void setDestroySessionAfterRequest(boolean destroySessionAfterRequest)
+ {
+ this.destroySessionAfterRequest = destroySessionAfterRequest;
+ }
- public String getResourcePathPrefix()
- {
- return resourcePathPrefix;
- }
+ public String getResourcePathPrefix()
+ {
+ return resourcePathPrefix;
+ }
- public void setResourcePathPrefix(String resourcePathPrefix)
- {
- this.resourcePathPrefix = resourcePathPrefix;
- }
+ public void setResourcePathPrefix(String resourcePathPrefix)
+ {
+ this.resourcePathPrefix = resourcePathPrefix;
+ }
- public boolean isStripSeamResourcePath()
- {
- return stripSeamResourcePath;
- }
+ public boolean isStripSeamResourcePath()
+ {
+ return stripSeamResourcePath;
+ }
- public void setStripSeamResourcePath(boolean stripSeamResourcePath)
- {
- this.stripSeamResourcePath = stripSeamResourcePath;
- }
+ public void setStripSeamResourcePath(boolean stripSeamResourcePath)
+ {
+ this.stripSeamResourcePath = stripSeamResourcePath;
+ }
}
Modified: branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/EntityHomeWrapper.java
===================================================================
--- branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/EntityHomeWrapper.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/EntityHomeWrapper.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -18,7 +18,7 @@
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ */
package org.jboss.seam.resteasy;
import org.jboss.seam.framework.EntityHome;
@@ -28,12 +28,10 @@
/**
* This class provides an unified interface for accessing EntityHome and
* HibernateEntityHome instances.
- *
+ *
* @author Jozef Hartinger
- *
* @see org.jboss.seam.framework.EntityHome
* @see org.jboss.seam.framework.HibernateEntityHome
- *
*/
public class EntityHomeWrapper<T>
{
Modified: branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResourceHome.java
===================================================================
--- branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResourceHome.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResourceHome.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -18,7 +18,7 @@
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ */
package org.jboss.seam.resteasy;
import java.io.InputStream;
@@ -52,15 +52,14 @@
/**
* This component exposes EntityHome and HibernateEntityHome components as a
* REST resource.
- *
+ *
* @author Jozef Hartinger
- *
* @param <T> Entity class
* @param <T2> Entity id class
*/
// Empty @Path because it's ignored by second-stage bootstrap if not subclassed or in components.xml
// but we need it as a marker so we'll find components.xml declarations during first stage of bootstrap.
- at Path("")
+ at Path("")
public class ResourceHome<T, T2> extends AbstractResource<T>
{
private EntityHomeWrapper<T> entityHome = null;
@@ -93,10 +92,10 @@
* Called by RESTEasy when HTTP GET request is received. String form of
* entity identifier is passed as a parameter. Returns a response containing
* database entity.
- *
- * @see #getEntity
+ *
* @param rawId String form of entity identifier
* @return response
+ * @see #getEntity
*/
@Path("/{id}")
@GET
@@ -118,7 +117,7 @@
/**
* Retrieve an entity identified by id parameter.
- *
+ *
* @param id entity identifier
* @return entity database entity
*/
@@ -133,10 +132,10 @@
* Called by RESTEasy when HTTP POST request is received. Persists received
* entity and returns 201 HTTP status code with location header set to new
* URI if operation succeeds.
- *
- * @see #createEntity
+ *
* @param messageBody HTTP request body
* @return response
+ * @see #createEntity
*/
@POST
public Response createResource(InputStream messageBody)
@@ -162,7 +161,7 @@
/**
* Store entity passed as a parameter in the database.
- *
+ *
* @param entity Object to be persisted
* @return id identifier assigned to the entity
*/
@@ -176,11 +175,11 @@
/**
* Called by RESTEasy when HTTP PUT request is received. Merges the state of
* the database entity with the received representation.
- *
- * @see #updateEntity
- * @param rawId String form of entity identifier
+ *
+ * @param rawId String form of entity identifier
* @param messageBody HTTP request body
* @return response
+ * @see #updateEntity
*/
@Path("/{id}")
@PUT
@@ -215,7 +214,7 @@
* Merge the state of the database entity with the entity passed as a
* parameter. Override to customize the update strategy - for instance to
* update specific fields only instead of a full merge.
- *
+ *
* @param entity
*/
public void updateEntity(T entity, T2 id)
@@ -226,10 +225,10 @@
/**
* Called by RESTEasy when HTTP DELETE request is received. Deletes a
* database entity.
- *
- * @see #deleteEntity
+ *
* @param rawId String form of entity identifier
* @return response
+ * @see #deleteEntity
*/
@Path("/{id}")
@DELETE
@@ -247,7 +246,7 @@
/**
* Delete database entity.
- *
+ *
* @param id entity identifier
*/
public void deleteEntity(T2 id)
@@ -258,7 +257,7 @@
/**
* Convert HTTP request body into entity class instance.
- *
+ *
* @param is HTTP request body
* @return entity
*/
@@ -284,7 +283,7 @@
/**
* Converts String form of entity identifier to it's natural type.
- *
+ *
* @param id String form of entity identifier
* @return entity identifier
*/
@@ -298,7 +297,7 @@
* EntityHome component getter. Override this method to set the EntityHome
* this resource will operate on. You can use either EntityHome or
* HibernateEntityHome instance.
- *
+ *
* @return entity home
*/
public Home<?, T> getEntityHome()
@@ -308,7 +307,7 @@
/**
* EntityHome component setter
- *
+ *
* @param entityHome
*/
public void setEntityHome(Home<?, T> entityHome)
@@ -331,7 +330,7 @@
* If set to read-only mode, this resource will only response to GET
* requests. HTTP 415 status code (method not allowed) will returned in all
* other cases.
- *
+ *
* @param readonly
*/
public void setReadonly(boolean readonly)
@@ -342,7 +341,7 @@
/**
* Retrieve entity identifier's class. If not set, type parameters of a
* superclass are examined.
- *
+ *
* @return class of entity identifier
*/
public Class getEntityIdClass()
Modified: branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResourceQuery.java
===================================================================
--- branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResourceQuery.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResourceQuery.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -18,7 +18,7 @@
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ */
package org.jboss.seam.resteasy;
import java.lang.reflect.ParameterizedType;
@@ -37,15 +37,15 @@
import org.jboss.seam.annotations.Create;
import org.jboss.seam.framework.EntityQuery;
import org.jboss.seam.framework.Query;
+
import static javax.ws.rs.core.Response.Status.UNSUPPORTED_MEDIA_TYPE;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
/**
* This component exposes EntityQuery component as a REST resource responding to
* HTTP GET request.
- *
+ *
* @author Jozef Hartinger
- *
* @param <T> entity type
*/
// Empty @Path because it's ignored by second-stage bootstrap if not subclassed or in components.xml
@@ -73,11 +73,11 @@
* Called by RESTEasy to respond for an HTTP GET request. Retrieves a list of
* entities matching criteria set by query parameters from database and
* returns it wrapped in Response instance.
- *
- * @see #getEntityList
+ *
* @param start first entity in the list
- * @param show maximum size of the list
+ * @param show maximum size of the list
* @return representation of a list of database entries
+ * @see #getEntityList
*/
@GET
@Wrapped
@@ -111,7 +111,7 @@
public Type[] getActualTypeArguments()
{
- return new Type[] { getEntityClass() };
+ return new Type[]{getEntityClass()};
}
};
return Response.ok(new GenericEntity(result, responseType)
@@ -121,9 +121,9 @@
/**
* Retrieve a list of database entities.
- *
+ *
* @param start first entity in the list
- * @param show maximum size of the list, 0 for unlimited
+ * @param show maximum size of the list, 0 for unlimited
* @return list of database entries
*/
public List<T> getEntityList(int start, int show)
@@ -138,7 +138,7 @@
/**
* EntityQuery getter
- *
+ *
* @return EntityQuery instance
*/
public Query<?, T> getEntityQuery()
Modified: branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java
===================================================================
--- branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyBootstrap.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,33 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.seam.resteasy;
+import org.jboss.resteasy.core.Dispatcher;
+import org.jboss.resteasy.core.SynchronousDispatcher;
+import org.jboss.resteasy.core.ThreadLocalResteasyProviderFactory;
+import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
+import org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory;
+import org.jboss.resteasy.spi.ResourceFactory;
+import org.jboss.resteasy.spi.StringConverter;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
+import org.jboss.seam.Seam;
+import org.jboss.seam.annotations.AutoCreate;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Factory;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.JndiName;
+import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
-import org.jboss.seam.annotations.AutoCreate;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Logger;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Create;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Init;
import org.jboss.seam.deployment.AnnotationDeploymentHandler;
import org.jboss.seam.deployment.DeploymentStrategy;
-import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.log.Log;
+import org.jboss.seam.util.EJB;
import org.jboss.seam.util.Reflections;
-import org.jboss.seam.util.EJB;
-import org.jboss.resteasy.core.ThreadLocalResteasyProviderFactory;
+import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.HashSet;
-import java.util.Map;
-import java.util.HashMap;
import java.util.Set;
/**
- * Scans annoated JAX-RS resources and providers, optionally registers them as Seam components.
- * It does so by populating the <tt>Application</tt> instance, which is then processed further
- * by the <tt>ResteasyDispatcher</tt> during startup.
+ * Detects (through scanning and configuration) JAX-RS resources and providers, then
+ * registers them with RESTEasy.
+ * <p>
+ * This class is a factory for <tt>org.jboss.seam.resteasy.dispatcher</tt> and it has been
+ * designed for extension. Alternatively, you can ignore what this class is doing and provide a
+ * different <tt>org.jboss.seam.resteasy.dispatcher</tt> yourself without extending this class.
+ * </p>
+ * <p>
+ * The main methods of this class are <tt>registerProviders()</tt> and <tt>registerResources()</tt>.
+ * These methods call out to the individual fine-grained registration procedures, which you can override
+ * if a different registration strategy for a particular type/component is desired.
+ * </p>
*
* @author Christian Bauer
*/
@@ -39,167 +78,454 @@
public class ResteasyBootstrap
{
- @Logger
- Log log;
+ @Logger
+ Log log;
- @In
- protected Application application;
+ @In
+ protected Application application;
- private SeamResteasyProviderFactory providerFactory;
- public SeamResteasyProviderFactory getProviderFactory()
- {
- return providerFactory;
- }
+ // The job of this class is to initialize and configure the RESTEasy Dispatcher instance
+ protected Dispatcher dispatcher;
- @Create
- public void init()
- {
- log.info("starting RESTEasy with custom SeamResteasyProviderFactory");
- providerFactory = new SeamResteasyProviderFactory();
+ @Factory("org.jboss.seam.resteasy.dispatcher")
+ public Dispatcher getDispatcher()
+ {
+ return dispatcher;
+ }
- // Always use the "deployment sensitive" factory - that means it is handled through ThreadLocal, not static
- SeamResteasyProviderFactory.setInstance(new ThreadLocalResteasyProviderFactory(getProviderFactory()));
+ @Create
+ public void init()
+ {
+ log.info("bootstrapping JAX-RS application");
- log.info("deploying JAX-RS application");
+ // Custom ResteasyProviderFactory that understands Seam component lookup at runtime
+ SeamResteasyProviderFactory providerFactory = createProviderFactory();
+ dispatcher = createDispatcher(providerFactory);
+ initDispatcher();
- Collection<Class<?>> annotatedProviderClasses = null;
- Collection<Class<?>> annotatedResourceClasses = null;
- if (application.isScanProviders() || application.isScanResources())
- {
- log.debug("scanning all classes for JAX-RS annotations");
+ // Always use the "deployment sensitive" factory - that means it is handled through ThreadLocal, not static
+ // TODO: How does that actually work? It's never used because the dispatcher is created with the original one
+ SeamResteasyProviderFactory.setInstance(new ThreadLocalResteasyProviderFactory(providerFactory));
- DeploymentStrategy deployment = (DeploymentStrategy) Component.getInstance("deploymentStrategy");
- AnnotationDeploymentHandler handler =
- (AnnotationDeploymentHandler) deployment.getDeploymentHandlers().get(AnnotationDeploymentHandler.NAME);
+ // Seam can scan the classes for us, we just have to list them in META-INF/seam-deployment.properties
+ DeploymentStrategy deployment = (DeploymentStrategy) Component.getInstance("deploymentStrategy");
+ AnnotationDeploymentHandler handler =
+ (AnnotationDeploymentHandler) deployment.getDeploymentHandlers().get(AnnotationDeploymentHandler.NAME);
- annotatedProviderClasses = handler.getClassMap().get(javax.ws.rs.ext.Provider.class.getName());
- annotatedResourceClasses = handler.getClassMap().get(javax.ws.rs.Path.class.getName());
- }
+ Collection<Class<?>> providers = findProviders(handler);
+ Collection<Class<?>> resources = findResources(handler);
+ Collection<Component> seamComponents = findSeamComponents();
- log.debug("finding all Seam component classes");
- Map<Class, Set<Component>> seamComponents = new HashMap<Class, Set<Component>>();
- String[] applicationContextNames = Contexts.getApplicationContext().getNames();
- for (String applicationContextName : applicationContextNames)
- {
- if (applicationContextName.endsWith(".component"))
- {
- Component seamComponent =
- (Component) Component.getInstance(applicationContextName, ScopeType.APPLICATION);
- // TODO: This should consider EJB components/annotations on interfaces somehow?
- Class beanClass = seamComponent.getBeanClass();
- if (!seamComponents.containsKey(beanClass))
- {
- seamComponents.put(beanClass, new HashSet<Component>());
- }
- seamComponents.get(beanClass).add(seamComponent);
- }
- }
+ registerProviders(seamComponents, providers);
+ registerResources(seamComponents, resources);
+ }
- registerProviders(seamComponents, annotatedProviderClasses);
- registerResources(seamComponents, annotatedResourceClasses);
- }
+ protected SeamResteasyProviderFactory createProviderFactory()
+ {
+ return new SeamResteasyProviderFactory();
+ }
- // Load all provider classes, either scanned or through explicit configuration
- protected void registerProviders(Map<Class, Set<Component>> seamComponents, Collection annotatedProviderClasses)
- {
- Collection<Class> providerClasses = new HashSet<Class>();
- try
- {
- if (application.isScanProviders() && annotatedProviderClasses != null)
- providerClasses.addAll(annotatedProviderClasses);
+ protected Dispatcher createDispatcher(SeamResteasyProviderFactory providerFactory)
+ {
+ return new SynchronousDispatcher(providerFactory);
+ }
- for (String s : new HashSet<String>(application.getProviderClassNames()))
- providerClasses.add(Reflections.classForName(s));
+ protected void initDispatcher()
+ {
+ getDispatcher().setLanguageMappings(application.getLanguageMappings());
+ getDispatcher().setMediaTypeMappings(application.getMediaTypeMappings());
+ }
- }
- catch (ClassNotFoundException ex)
- {
- log.error("error loading JAX-RS provider class: " + ex.getMessage());
- }
- for (Class providerClass : providerClasses)
- {
- // Ignore built-in providers, we register them manually later
- if (providerClass.getName().startsWith("org.jboss.resteasy.plugins.providers")) continue;
+ protected Collection<Class<?>> findProviders(AnnotationDeploymentHandler handler)
+ {
+ return findTypes(
+ handler,
+ application.isScanProviders(),
+ javax.ws.rs.ext.Provider.class.getName(),
+ application.getProviderClassNames()
+ );
+ }
- // Check if this is also a Seam component bean class
- if (seamComponents.containsKey(providerClass))
- {
- for (Component seamComponent : seamComponents.get(providerClass))
+ protected Collection<Class<?>> findResources(AnnotationDeploymentHandler handler)
+ {
+ return findTypes(
+ handler,
+ application.isScanResources(),
+ javax.ws.rs.Path.class.getName(),
+ application.getResourceClassNames()
+ );
+ }
+
+ protected Collection<Class<?>> findTypes(AnnotationDeploymentHandler handler, boolean scanClasspathForAnnotations,
+ String annotationFQName, Collection<String> includeTypeNames)
+ {
+
+ Collection<Class<?>> types = new HashSet();
+
+ if (scanClasspathForAnnotations)
+ {
+ Collection<Class<?>> annotatedTypes = handler.getClassMap().get(annotationFQName);
+ if (annotatedTypes != null) types.addAll(annotatedTypes);
+ }
+
+ try
+ {
+ for (String s : new HashSet<String>(includeTypeNames))
+ {
+ types.add(Reflections.classForName(s));
+ }
+ }
+ catch (ClassNotFoundException ex)
+ {
+ log.error("error loading JAX-RS type: " + ex.getMessage(), ex);
+ }
+
+ return types;
+ }
+
+
+ protected Collection<Component> findSeamComponents()
+ {
+ // Iterate through all variables in the application context that end with ".component"
+ log.debug("discovering all Seam components");
+ Collection<Component> seamComponents = new HashSet();
+ String[] applicationContextNames = Contexts.getApplicationContext().getNames();
+ for (String applicationContextName : applicationContextNames)
+ {
+ if (applicationContextName.endsWith(".component"))
+ {
+ Component seamComponent =
+ (Component) Component.getInstance(applicationContextName, ScopeType.APPLICATION);
+ seamComponents.add(seamComponent);
+ }
+ }
+ return seamComponents;
+ }
+
+
+ protected void registerProviders(Collection<Component> seamComponents, Collection<Class<?>> providerClasses)
+ {
+
+ // RESTEasy built-in providers first
+ if (application.isUseBuiltinProviders())
+ {
+ log.info("registering built-in RESTEasy providers");
+ RegisterBuiltin.register(getDispatcher().getProviderFactory());
+ }
+
+ Set<Class> handledProviders = new HashSet(); // Stuff we don't want to examine twice
+
+ for (Component seamComponent : seamComponents)
+ {
+ // The component can have one (not many) @Provider annotated business interface
+ Class providerInterface = getAnnotatedInterface(javax.ws.rs.ext.Provider.class, seamComponent);
+
+ // How we register it depends on the component type
+ switch (seamComponent.getType())
+ {
+
+ // TODO: We don't support EJB Seam components as providers
+
+ case JAVA_BEAN:
+
+ // We are only interested in components that have a @Provider annotation on iface or bean
+ if (providerInterface == null
+ && !seamComponent.getBeanClass().isAnnotationPresent(javax.ws.rs.ext.Provider.class))
{
- // Needs to be APPLICATION or STATELESS
- if (!seamComponent.getScope().equals(ScopeType.APPLICATION) &&
- !seamComponent.getScope().equals(ScopeType.STATELESS))
- {
- log.warn("can't add provider Seam component, not APPLICATION or STATELESS scope: " + seamComponent.getName());
- log.warn("this provider class will be registered without Seam injection or lifecycle!");
- seamComponent = null;
- }
- if (seamComponent != null)
- {
- log.debug("adding provider Seam component: " + seamComponent.getName());
- application.addProviderClass(providerClass, seamComponent);
- }
- else
- {
- log.debug("adding provider class: " + providerClass.getName());
- application.addProviderClass(providerClass);
- }
+ break;
}
- }
- else
- {
- log.debug("adding provider class: " + providerClass.getName());
- application.addProviderClass(providerClass);
- }
+
+ // They also have to be in the right scope, otherwise we can't handle their lifecylce (yet)
+ switch (seamComponent.getScope())
+ {
+ case APPLICATION:
+
+ // StringConverter is a special case
+ if (StringConverter.class.isAssignableFrom(seamComponent.getBeanClass()))
+ {
+ getDispatcher().getProviderFactory().addStringConverter(
+ (StringConverter) Component.getInstance(seamComponent.getName())
+ );
+ }
+ else
+ {
+ registerSeamComponentProvider(seamComponent);
+ }
+ break;
+
+ default:
+ throw new RuntimeException(
+ "Provider Seam component '" + seamComponent.getName() + "' must be scoped " +
+ "APPLICATION"
+ );
+ }
+ break;
}
- if (application.getProviderClasses().size() == 0 &&
- !application.isUseBuiltinProviders())
- {
- log.info("no RESTEasy provider classes added");
- }
- }
- // Load all resource classes, either scanned or through explicit configuration
- protected void registerResources(Map<Class, Set<Component>> seamComponents, Collection annotatedResourceClasses)
- {
- Collection<Class> resourceClasses = new HashSet<Class>();
- try
- {
- if (application.isScanResources() && annotatedResourceClasses != null)
- resourceClasses.addAll(annotatedResourceClasses);
+ // We simply add everything we have seen so far... it's not really necessary but it doesn't hurt (does it?)
+ handledProviders.add(seamComponent.getBeanClass());
+ handledProviders.addAll(seamComponent.getBusinessInterfaces());
+ }
- for (String s : new HashSet<String>(application.getResourceClassNames()))
- resourceClasses.add(Reflections.classForName(s));
+ for (Class<?> providerClass : providerClasses)
+ {
- }
- catch (ClassNotFoundException ex)
- {
- log.error("error loading JAX-RS resource class: " + ex.getMessage());
- }
- for (Class<Object> resourceClass : resourceClasses)
- {
- // Check if this is also a Seam component bean class
- if (seamComponents.containsKey(resourceClass))
+ // An @Provider annotated type may:
+
+ // - have been already handled as a Seam component in the previous routine
+ if (handledProviders.contains(providerClass)) continue;
+
+ // - be a RESTEasy built-in provider
+ if (providerClass.getName().startsWith("org.jboss.resteasy.plugins.providers")) continue;
+
+ // - be an interface, which we don't care about if we don't have an implementation
+ if (providerClass.isInterface()) continue;
+
+ // - be just plain RESTEasy, no Seam component lookup or lifecycle
+ if (StringConverter.class.isAssignableFrom(providerClass))
+ {
+ log.debug("registering provider as RESTEasy StringConverter: {0}", providerClass);
+ getDispatcher().getProviderFactory().addStringConverter((Class<? extends StringConverter>) providerClass);
+ }
+ else
+ {
+ log.debug("registering provider as plain JAX-RS type: {0}", providerClass);
+ getDispatcher().getProviderFactory().registerProvider(providerClass);
+ }
+ }
+ }
+
+ protected void registerResources(Collection<Component> seamComponents, Collection<Class<?>> resourceClasses)
+ {
+
+ Set<Class> handledResources = new HashSet(); // Stuff we don't want to examine twice
+
+ for (Component seamComponent : seamComponents)
+ {
+
+ // A bean class of type (not subtypes) ResourceHome or ResourceQuery annotated with @Path, then
+ // it's a Seam component resource we need to register with getPath() on the instance, it has been
+ // configured in components.xml
+ if (seamComponent.getBeanClass().equals(ResourceHome.class) ||
+ seamComponent.getBeanClass().equals(ResourceQuery.class))
+ {
+ registerHomeQueryResources(seamComponent);
+ handledResources.add(ResourceHome.class);
+ handledResources.add(ResourceQuery.class);
+ continue;
+ }
+
+ // The component can have one (not many) @Path annotated business interface
+ Class resourceInterface = getAnnotatedInterface(javax.ws.rs.Path.class, seamComponent);
+
+ // How we register it depends on the component type
+ switch (seamComponent.getType())
+ {
+ case STATELESS_SESSION_BEAN:
+ // EJB seam component resources must be @Path annotated on one of their business interfaces
+ if (resourceInterface != null)
+ {
+ // TODO: Do we have to consider the scope? It should be stateless, right?
+ registerInterfaceSeamComponentResource(seamComponent, resourceInterface);
+ }
+ break;
+ case STATEFUL_SESSION_BEAN:
+ // EJB seam component resources must be @Path annotated on one of their business interfaces
+ if (resourceInterface != null)
+ {
+ log.error("Not implemented: Stateful EJB Seam component resource: " + seamComponent);
+ // TODO: registerStatefulEJBSeamComponentResource(seamComponent);
+ }
+ break;
+ case JAVA_BEAN:
+
+ // We are only interested in components that have a @Path annotation on iface or bean
+ if (resourceInterface == null
+ && !seamComponent.getBeanClass().isAnnotationPresent(javax.ws.rs.Path.class))
+ {
+ break;
+ }
+
+ // They also have to be in the right scope, otherwise we can't handle their lifecylce (yet)
+ switch (seamComponent.getScope())
+ {
+ case EVENT:
+ case APPLICATION:
+ case STATELESS:
+ case SESSION:
+ if (resourceInterface != null)
+ {
+ registerInterfaceSeamComponentResource(seamComponent, resourceInterface);
+ }
+ else if (seamComponent.getBeanClass().isAnnotationPresent(javax.ws.rs.Path.class))
+ {
+ registerSeamComponentResource(seamComponent);
+ }
+ break;
+ default:
+ throw new RuntimeException(
+ "Resource Seam component '" + seamComponent.getName() + "' must be scoped either " +
+ "EVENT, APPLICATION, STATELESS, or SESSION"
+ );
+ }
+ break;
+ }
+
+ // We simply add everything we have seen so far... it's not really necessary but it doesn't hurt (does it?)
+ handledResources.add(seamComponent.getBeanClass());
+ handledResources.addAll(seamComponent.getBusinessInterfaces());
+
+ }
+
+ for (Class<?> resourceClass : resourceClasses)
+ {
+ // An @Path annotated type may:
+
+ // - have been already handled as a Seam component in the previous routine
+ if (handledResources.contains(resourceClass)) continue;
+
+ // - be an interface, which we don't care about if we don't have an implementation
+ if (resourceClass.isInterface()) continue;
+
+ // - be a @Stateless EJB implementation class that was listed in components.xml
+ if (resourceClass.isAnnotationPresent(EJB.STATELESS))
+ {
+ registerStatelessEJBResource(resourceClass);
+ }
+ // - be a @Stateful EJB implementation class that was listed in components.xml
+ else if (resourceClass.isAnnotationPresent(EJB.STATEFUL))
+ {
+ throw new RuntimeException(
+ "Only stateless EJBs can be JAX-RS resources, remove from configuration: " + resourceClass.getName()
+ );
+ }
+ else
+ {
+ // - just be a regular JAX-RS lifecycle instance that can created/destroyed by RESTEasy
+ registerPlainResource(resourceClass);
+ }
+ }
+
+ }
+
+ protected void registerHomeQueryResources(Component seamComponent)
+ {
+ // We can always instantiate this safely here because it can't have dependencies!
+ AbstractResource instance = (AbstractResource) seamComponent.newInstance();
+ String path = instance.getPath();
+ if (instance.getPath() != null)
+ {
+ log.debug(
+ "registering resource, configured ResourceHome/Query on path {1}, as Seam component: {0}",
+ seamComponent.getName(),
+ path
+ );
+
+ ResourceFactory factory = new SeamResteasyResourceFactory(
+ seamComponent.getBeanClass(),
+ seamComponent,
+ getDispatcher().getProviderFactory()
+ );
+
+ getDispatcher().getRegistry().addResourceFactory(factory, path);
+ }
+ else
+ {
+ log.error("Unable to register {0} resource on null path, check components.xml", seamComponent.getName());
+ }
+ }
+
+ protected void registerSeamComponentResource(Component seamComponent)
+ {
+ log.debug("registering resource as Seam component: {0}", seamComponent.getName());
+
+ ResourceFactory factory = new SeamResteasyResourceFactory(
+ seamComponent.getBeanClass(),
+ seamComponent,
+ getDispatcher().getProviderFactory()
+ );
+
+ getDispatcher().getRegistry().addResourceFactory(factory);
+ }
+
+ protected void registerInterfaceSeamComponentResource(Component seamComponent, Class resourceInterface)
+ {
+ log.debug(
+ "registering resource, annotated interface {1}, as Seam component: {0}",
+ seamComponent.getName(),
+ resourceInterface.getName()
+ );
+
+ ResourceFactory factory = new SeamResteasyResourceFactory(
+ resourceInterface,
+ seamComponent,
+ getDispatcher().getProviderFactory()
+ );
+
+ getDispatcher().getRegistry().addResourceFactory(factory);
+ }
+
+ protected void registerStatelessEJBResource(Class ejbImplementationClass)
+ {
+ String jndiName = getJndiName(ejbImplementationClass);
+
+ log.debug(
+ "registering resource, stateless EJB implementation {1}, as RESTEasy JNDI resource name: {0}",
+ jndiName,
+ ejbImplementationClass.getName()
+ );
+ getDispatcher().getRegistry().addJndiResource(jndiName);
+ }
+
+ protected void registerPlainResource(Class plainResourceClass)
+ {
+ log.debug("registering resource, event-scoped JAX-RS lifecycle: {0}", plainResourceClass.getName());
+ getDispatcher().getRegistry().addResourceFactory(new POJOResourceFactory(plainResourceClass));
+ }
+
+ protected void registerSeamComponentProvider(Component seamComponent)
+ {
+ log.debug("registering provider as Seam component: {0}", seamComponent.getName());
+ getDispatcher().getProviderFactory().registerProviderInstance(
+ Component.getInstance(seamComponent.getName())
+ );
+ }
+
+ protected Class getAnnotatedInterface(Class<? extends Annotation> annotation, Component seamComponent)
+ {
+ Class resourceInterface = null;
+ for (Class anInterface : seamComponent.getBusinessInterfaces())
+ {
+ if (anInterface.isAnnotationPresent(annotation))
+ {
+ if (resourceInterface != null)
{
- Set<Component> components = seamComponents.get(resourceClass);
- log.debug("adding resource Seam components {0} for class {1}", components, resourceClass);
- application.addResourceClass(resourceClass, components);
+ throw new IllegalStateException("Only one business interface can be annotated " + annotation + ": " + seamComponent);
}
- // Check if it is a @Path annotated EJB interface
- else if (resourceClass.isAnnotationPresent(EJB.LOCAL) ||
- resourceClass.isAnnotationPresent(EJB.REMOTE))
- {
- log.debug("ignoring @Path annotated EJB interface, add the bean " +
- "implementation to <resteasy:resource-class-names/>: " + resourceClass.getName());
- }
- else
- {
- log.debug("adding resource class: " + resourceClass.getName());
- application.addResourceClass(resourceClass);
- }
- }
- if (application.getClasses().size() == 0)
- log.info("no JAX-RS resource classes registered");
- }
+ resourceInterface = anInterface;
+ }
+ }
+ return resourceInterface;
+ }
+ protected String getJndiName(Class<?> beanClass)
+ {
+ if (beanClass.isAnnotationPresent(JndiName.class))
+ {
+ return beanClass.getAnnotation(JndiName.class).value();
+ }
+ else
+ {
+ String jndiPattern = Init.instance().getJndiPattern();
+ if (jndiPattern == null)
+ {
+ throw new IllegalArgumentException(
+ "You must specify org.jboss.seam.core.init.jndiPattern or use @JndiName: " + beanClass.getName()
+ );
+ }
+ return jndiPattern.replace("#{ejbName}", Seam.getEjbName(beanClass));
+ }
+ }
+
+
}
Modified: branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyContextInjectionInterceptor.java
===================================================================
--- branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyContextInjectionInterceptor.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyContextInjectionInterceptor.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,13 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.seam.resteasy;
+import org.jboss.resteasy.spi.HttpRequest;
+import org.jboss.resteasy.spi.HttpResponse;
+import org.jboss.resteasy.spi.PropertyInjector;
+import org.jboss.seam.Component;
import org.jboss.seam.annotations.intercept.Interceptor;
-import org.jboss.seam.core.BijectionInterceptor;
import org.jboss.seam.intercept.AbstractInterceptor;
import org.jboss.seam.intercept.InvocationContext;
-import org.jboss.seam.Component;
-import org.jboss.resteasy.spi.PropertyInjector;
-import org.jboss.resteasy.spi.HttpRequest;
-import org.jboss.resteasy.spi.HttpResponse;
/**
* Runs after Seam injection and provides JAX RS @Context handling, required for
@@ -15,32 +35,32 @@
*
* @author Christian Bauer
*/
- at Interceptor(stateless=true)
+ at Interceptor(stateless = true)
public class ResteasyContextInjectionInterceptor extends AbstractInterceptor
{
- public static final String RE_HTTP_REQUEST_VAR = "org.jboss.resteasy.spi.HttpRequest";
- public static final String RE_HTTP_RESPONSE_VAR = "org.jboss.resteasy.spi.HttpResponse";
+ public static final String RE_HTTP_REQUEST_VAR = "org.jboss.resteasy.spi.HttpRequest";
+ public static final String RE_HTTP_RESPONSE_VAR = "org.jboss.resteasy.spi.HttpResponse";
- private final PropertyInjector propertyInjector;
+ private final PropertyInjector propertyInjector;
- public ResteasyContextInjectionInterceptor(PropertyInjector propertyInjector)
- {
- this.propertyInjector = propertyInjector;
- }
+ public ResteasyContextInjectionInterceptor(PropertyInjector propertyInjector)
+ {
+ this.propertyInjector = propertyInjector;
+ }
- public Object aroundInvoke(InvocationContext ic) throws Exception
- {
- HttpRequest request = (HttpRequest) Component.getInstance(RE_HTTP_REQUEST_VAR);
- HttpResponse response = (HttpResponse)Component.getInstance(RE_HTTP_RESPONSE_VAR);
+ public Object aroundInvoke(InvocationContext ic) throws Exception
+ {
+ HttpRequest request = (HttpRequest) Component.getInstance(RE_HTTP_REQUEST_VAR);
+ HttpResponse response = (HttpResponse) Component.getInstance(RE_HTTP_RESPONSE_VAR);
- propertyInjector.inject(request, response, ic.getTarget());
+ propertyInjector.inject(request, response, ic.getTarget());
- return ic.proceed();
- }
+ return ic.proceed();
+ }
- public boolean isInterceptorEnabled()
- {
- return true;
- }
+ public boolean isInterceptorEnabled()
+ {
+ return true;
+ }
}
Deleted: branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyDispatcher.java
===================================================================
--- branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyDispatcher.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyDispatcher.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,238 +0,0 @@
-package org.jboss.seam.resteasy;
-
-import org.jboss.resteasy.core.SynchronousDispatcher;
-import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
-import org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory;
-import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher;
-import org.jboss.resteasy.spi.ResourceFactory;
-import org.jboss.resteasy.spi.StringConverter;
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.Seam;
-import org.jboss.seam.core.Init;
-import org.jboss.seam.util.EJB;
-import org.jboss.seam.annotations.AutoCreate;
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.In;
-import org.jboss.seam.annotations.Logger;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Startup;
-import org.jboss.seam.annotations.JndiName;
-import org.jboss.seam.log.Log;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import java.util.Set;
-
-/**
- * An extended version of the RESTEasy dispatcher, configured on Seam application
- * startup with a custom JAX RS <tt>Application</tt> instance. Registers custom resource
- * and provider lifecycle handlers with RESTEasy, depending on configured/detected resources
- * from <tt>ResteasyBootstrap</tt>.
- *
- * @author Christian Bauer
- */
- at Name("org.jboss.seam.resteasy.dispatcher")
- at Scope(ScopeType.APPLICATION)
- at Startup(depends = "org.jboss.seam.resteasy.bootstrap")
- at AutoCreate
-public class ResteasyDispatcher extends HttpServletDispatcher
-{
-
- @In
- protected Application application;
-
- @In
- protected ResteasyBootstrap bootstrap;
-
- @Logger
- private Log log;
-
- @Create
- public void init()
- {
- try
- {
- init(null);
- }
- catch (ServletException ex)
- {
- // Can never happen
- }
- }
-
- @Override
- public void init(ServletConfig servletConfig) throws ServletException
- {
- // We can skip the init, it only sets up the provider factory (did that already in bootstrap) and
- // the other stuff we do in onStartup(). We also do NOT put the ResteasyProviderFactory, the Dispatcher,
- // nor the Registry into the servlet context. Let's hope RESTEasy code is sane enough not to access the
- // servlet context at runtime...
- log.debug("registering RESTEasy and JAX RS resources and providers");
- setDispatcher(new SynchronousDispatcher(bootstrap.getProviderFactory()));
-
- getDispatcher().setLanguageMappings(application.getLanguageMappings());
- getDispatcher().setMediaTypeMappings(application.getMediaTypeMappings());
-
- // Provider registration
- if (application.isUseBuiltinProviders())
- {
- log.info("registering built-in RESTEasy providers");
- RegisterBuiltin.register(getDispatcher().getProviderFactory());
- }
-
- for (Class providerClass : application.getProviderClasses())
- {
- Set<Component> components = application.getProviderClassComponent(providerClass);
- if (components != null)
- {
- registerSeamComponentProviders(components, providerClass);
- }
- else
- {
- registerProvider(providerClass);
- }
- }
-
- // Resource registration
- for (final Class resourceClass : application.getClasses())
- {
- // First check if it's a class that is a Seam component
- Set<Component> components = application.getResourceClassComponent(resourceClass);
- if (components != null)
- {
- registerSeamComponentResources(components, resourceClass);
- }
- else
- {
- registerResource(resourceClass);
- }
- }
-
- }
-
-
- protected void registerSeamComponentProviders(Set<Component> components, Class providerClass) {
- for (Component seamComponent : components)
- {
- if (ScopeType.STATELESS.equals(seamComponent.getScope()))
- {
- throw new RuntimeException(
- "Registration of STATELESS Seam components as RESTEasy providers not implemented!"
- );
- }
- else if (ScopeType.APPLICATION.equals(seamComponent.getScope()))
- {
- Object providerInstance = Component.getInstance(seamComponent.getName());
- boolean isStringConverter = false;
- for (Class componentIface : seamComponent.getBusinessInterfaces())
- {
- if (StringConverter.class.isAssignableFrom(componentIface))
- {
- isStringConverter = true;
- break;
- }
- }
- if (isStringConverter)
- {
- log.error("can't register Seam component as RESTEasy StringConverter, see: https://jira.jboss.org/jira/browse/JBSEAM-4020");
- //log.debug("registering Seam component as custom RESTEasy string converter provider: " + seamComponent.getName());
- //getDispatcher().getProviderFactory().addStringConverter((StringConverter)providerInstance);
- }
- else
- {
- getDispatcher().getProviderFactory().registerProviderInstance(providerInstance);
- }
- }
- }
- }
-
- protected void registerSeamComponentResources(Set<Component> components, Class resourceClass) {
- for (final Component seamComponent : components)
- {
- // Seam component lookup when call is dispatched to resource
- ResourceFactory factory =
- new SeamResteasyResourceFactory(resourceClass, seamComponent, getDispatcher().getProviderFactory());
-
- // Register component on specific path if the component is a ResourceHome or ResourceQuery component configured in components.xml
- if (seamComponent.getBeanClass().equals(ResourceHome.class) || seamComponent.getBeanClass().equals(ResourceQuery.class))
- {
-
- // We can always instantiate this safely here because it can't have dependencies!
- AbstractResource instance = (AbstractResource) seamComponent.newInstance();
- String path = instance.getPath();
- if (instance.getPath() != null)
- {
- log.debug("registering resource {0} on path {1} with Seam component lifecycle", seamComponent.getName(), path);
- getDispatcher().getRegistry().addResourceFactory(factory, path);
- }
- else
- {
- log.warn("Unable to register {0} resource on null path, check components.xml", seamComponent.getName());
- }
- }
- else
- {
- log.debug("registering resource {0} with Seam component lifecycle", seamComponent.getName());
- getDispatcher().getRegistry().addResourceFactory(factory);
- }
- }
-
- }
-
- protected void registerProvider(Class providerClass) {
- // Just plain RESTEasy, no Seam component lookup or lifecycle
- if (StringConverter.class.isAssignableFrom(providerClass))
- {
- log.debug("registering as custom RESTEasy string converter provider class: " + providerClass);
- getDispatcher().getProviderFactory().addStringConverter(providerClass);
- }
- else
- {
- getDispatcher().getProviderFactory().registerProvider(providerClass);
- }
- }
-
- protected void registerResource(Class resourceClass) {
- // ResourceHome and ResourceQuery have an empty @Path("") and are supposed to be subclassed before use
- // (or through components.xml) - they should be ignored if they are not proper Seam components
- if (ResourceHome.class.equals(resourceClass) || ResourceQuery.class.equals(resourceClass))
- return;
-
- // Plain EJBs (not a Seam component) can be registered in RESTEasy by JNDI name
- if (resourceClass.isAnnotationPresent(EJB.STATELESS) || resourceClass.isAnnotationPresent(EJB.STATEFUL))
- {
- String jndiName = getJndiName(resourceClass);
- log.debug("registering plain EJB resource as RESTEasy JNDI resource name: " + jndiName);
- getDispatcher().getRegistry().addJndiResource(jndiName);
-
- }
- else
- {
- // JAX-RS default lifecycle
- log.debug("registering resource {0} with default JAX-RS lifecycle", resourceClass.getName());
- getDispatcher().getRegistry().addResourceFactory(new POJOResourceFactory(resourceClass));
- }
- }
-
- protected String getJndiName(Class<?> beanClass)
- {
- if (beanClass.isAnnotationPresent(JndiName.class))
- {
- return beanClass.getAnnotation(JndiName.class).value();
- }
- else
- {
- String jndiPattern = Init.instance().getJndiPattern();
- if (jndiPattern == null)
- {
- throw new IllegalArgumentException(
- "You must specify org.jboss.seam.core.init.jndiPattern or use @JndiName: " + beanClass.getName()
- );
- }
- return jndiPattern.replace("#{ejbName}", Seam.getEjbName(beanClass));
- }
- }
-
-}
Modified: branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyResourceAdapter.java
===================================================================
--- branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyResourceAdapter.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/ResteasyResourceAdapter.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,3 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.seam.resteasy;
import org.jboss.seam.Component;
@@ -13,6 +34,7 @@
import org.jboss.seam.web.Session;
import org.jboss.resteasy.core.SynchronousDispatcher;
import org.jboss.resteasy.core.ThreadLocalResteasyProviderFactory;
+import org.jboss.resteasy.core.Dispatcher;
import org.jboss.resteasy.plugins.server.servlet.HttpServletInputMessage;
import org.jboss.resteasy.plugins.server.servlet.HttpServletResponseWrapper;
import org.jboss.resteasy.plugins.server.servlet.ServletSecurityContext;
@@ -38,7 +60,7 @@
import java.util.List;
/**
- * Accepts incoming HTTP request throug the SeamResourceServlet and
+ * Accepts incoming HTTP requests through the <tt>SeamResourceServlet</tt> and
* dispatches the call to RESTEasy. Wraps the call in Seam contexts.
*
* @author Christian Bauer
@@ -49,134 +71,144 @@
public class ResteasyResourceAdapter extends AbstractResource
{
- @Logger
- Log log;
+ @Logger
+ Log log;
- protected ResteasyDispatcher dispatcher;
- protected Application application;
+ protected Dispatcher dispatcher;
+ protected Application application;
- @Create
- public void init()
- {
- // No injection, so lookup on first request
- dispatcher = (ResteasyDispatcher) Component.getInstance(ResteasyDispatcher.class);
- application = (Application) Component.getInstance(Application.class);
- }
+ @Create
+ public void init()
+ {
+ // No injection, so lookup on first request
+ dispatcher = (Dispatcher) Component.getInstance("org.jboss.seam.resteasy.dispatcher");
+ application = (Application) Component.getInstance(Application.class);
+ if (dispatcher == null) {
+ throw new IllegalStateException(
+ "ReasteasyDispatcher not available, make sure RESTEasy and all required JARs are on your classpath"
+ );
+ }
+ }
- @Override
- public String getResourcePath()
- {
- return application.getResourcePathPrefix();
- }
+ @Override
+ public String getResourcePath()
+ {
+ return application.getResourcePathPrefix();
+ }
- @Override
- public void getResource(final HttpServletRequest request, final HttpServletResponse response)
- throws ServletException, IOException
- {
+ @Override
+ public void getResource(final HttpServletRequest request, final HttpServletResponse response)
+ throws ServletException, IOException
+ {
- try
- {
- log.debug("processing REST request");
+ try
+ {
+ log.debug("processing REST request");
- // Wrap in RESTEasy thread-local factory handling
- ThreadLocalResteasyProviderFactory.push(dispatcher.getDispatcher().getProviderFactory());
+ // TODO: As far as I can tell from tracing RE code: All this thread-local stuff has no effect because
+ // the "default" provider factory is always used. But we do it anyway, just to mimic the servlet handler
+ // in RE...
- // Wrap in RESTEasy contexts (this also puts stuff in a thread-local)
- SeamResteasyProviderFactory.pushContext(HttpServletRequest.class, request);
- SeamResteasyProviderFactory.pushContext(HttpServletResponse.class, response);
- SeamResteasyProviderFactory.pushContext(SecurityContext.class, new ServletSecurityContext(request));
+ // Wrap in RESTEasy thread-local factory handling
+ ThreadLocalResteasyProviderFactory.push(dispatcher.getProviderFactory());
- // Wrap in Seam contexts
- new ContextualHttpServletRequest(request)
+ // Wrap in RESTEasy contexts (this also puts stuff in a thread-local)
+ SeamResteasyProviderFactory.pushContext(HttpServletRequest.class, request);
+ SeamResteasyProviderFactory.pushContext(HttpServletResponse.class, response);
+ SeamResteasyProviderFactory.pushContext(SecurityContext.class, new ServletSecurityContext(request));
+
+ // Wrap in Seam contexts
+ new ContextualHttpServletRequest(request)
+ {
+ @Override
+ public void process() throws ServletException, IOException
{
- @Override
- public void process() throws ServletException, IOException
- {
- HttpHeaders headers = ServletUtil.extractHttpHeaders(request);
- UriInfoImpl uriInfo = extractUriInfo(request);
+ HttpHeaders headers = ServletUtil.extractHttpHeaders(request);
+ UriInfoImpl uriInfo = extractUriInfo(request);
- HttpResponse theResponse = new HttpServletResponseWrapper(
- response,
- dispatcher.getDispatcher().getProviderFactory()
- );
+ HttpResponse theResponse = new HttpServletResponseWrapper(
+ response,
+ dispatcher.getProviderFactory()
+ );
- HttpRequest in = new HttpServletInputMessage(
- request,
- theResponse,
- headers,
- uriInfo,
- request.getMethod().toUpperCase(),
- (SynchronousDispatcher) dispatcher.getDispatcher()
- );
+ // TODO: This requires a SynchronousDispatcher
+ HttpRequest in = new HttpServletInputMessage(
+ request,
+ theResponse,
+ headers,
+ uriInfo,
+ request.getMethod().toUpperCase(),
+ (SynchronousDispatcher) dispatcher
+ );
- dispatcher.getDispatcher().invoke(in, theResponse);
+ dispatcher.invoke(in, theResponse);
- // Prevent anemic sessions clog up the server
- if (request.getSession().isNew()
- && application.isDestroySessionAfterRequest()
- && !Session.instance().isInvalid())
- {
- log.debug("Destroying HttpSession after REST request");
- Session.instance().invalidate();
- }
- }
- }.run();
+ // Prevent anemic sessions clog up the server
+ if (request.getSession().isNew()
+ && application.isDestroySessionAfterRequest()
+ && !Session.instance().isInvalid())
+ {
+ log.debug("Destroying HttpSession after REST request");
+ Session.instance().invalidate();
+ }
+ }
+ }.run();
- }
- finally
- {
- // Clean up the thread-locals
- SeamResteasyProviderFactory.clearContextData();
- ThreadLocalResteasyProviderFactory.pop();
- log.debug("completed processing of REST request");
- }
- }
+ }
+ finally
+ {
+ // Clean up the thread-locals
+ SeamResteasyProviderFactory.clearContextData();
+ ThreadLocalResteasyProviderFactory.pop();
+ log.debug("completed processing of REST request");
+ }
+ }
- // Replaces the static ServletUtil.extractUriInfo(), removes the Seam-related sub-path
- protected UriInfoImpl extractUriInfo(HttpServletRequest request)
- {
- String contextPath = request.getContextPath();
- URI absolutePath;
- try
- {
- URL absolute = new URL(request.getRequestURL().toString());
+ // Replaces the static ServletUtil.extractUriInfo(), removes the Seam-related sub-path
+ protected UriInfoImpl extractUriInfo(HttpServletRequest request)
+ {
+ String contextPath = request.getContextPath();
+ URI absolutePath;
+ try
+ {
+ URL absolute = new URL(request.getRequestURL().toString());
- UriBuilderImpl builder = new UriBuilderImpl();
- builder.scheme(absolute.getProtocol());
- builder.host(absolute.getHost());
- builder.port(absolute.getPort());
- builder.path(absolute.getPath());
- builder.replaceQuery(absolute.getQuery());
- absolutePath = builder.build();
- }
- catch (MalformedURLException e)
- {
- throw new RuntimeException(e);
- }
+ UriBuilderImpl builder = new UriBuilderImpl();
+ builder.scheme(absolute.getProtocol());
+ builder.host(absolute.getHost());
+ builder.port(absolute.getPort());
+ builder.path(absolute.getPath());
+ builder.replaceQuery(absolute.getQuery());
+ absolutePath = builder.build();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
- String path = PathHelper.getEncodedPathInfo(absolutePath.getRawPath(), contextPath);
+ String path = PathHelper.getEncodedPathInfo(absolutePath.getRawPath(), contextPath);
- if (application.isStripSeamResourcePath())
- {
- log.debug("removing SeamResourceServlet url-pattern and dispatcher prefix from request path");
- path = path.substring(path.indexOf(getResourcePath()) + getResourcePath().length());
- }
+ if (application.isStripSeamResourcePath())
+ {
+ log.debug("removing SeamResourceServlet url-pattern and dispatcher prefix from request path");
+ path = path.substring(path.indexOf(getResourcePath()) + getResourcePath().length());
+ }
- List<PathSegment> pathSegments = PathSegmentImpl.parseSegments(path);
- URI baseURI = absolutePath;
- if (!path.trim().equals(""))
- {
- String tmpContextPath = contextPath;
- if (!tmpContextPath.endsWith("/")) tmpContextPath += "/";
- baseURI = UriBuilder.fromUri(absolutePath).replacePath(tmpContextPath).build();
- }
+ List<PathSegment> pathSegments = PathSegmentImpl.parseSegments(path);
+ URI baseURI = absolutePath;
+ if (!path.trim().equals(""))
+ {
+ String tmpContextPath = contextPath;
+ if (!tmpContextPath.endsWith("/")) tmpContextPath += "/";
+ baseURI = UriBuilder.fromUri(absolutePath).replacePath(tmpContextPath).build();
+ }
- log.debug("UriInfo, absolute URI : " + absolutePath);
- log.debug("UriInfo, base URI : " + baseURI);
- log.debug("UriInfo, relative path/@Path: " + path);
- log.debug("UriInfo, query string : " + request.getQueryString());
+ log.debug("UriInfo, absolute URI : " + absolutePath);
+ log.debug("UriInfo, base URI : " + baseURI);
+ log.debug("UriInfo, relative path/@Path: " + path);
+ log.debug("UriInfo, query string : " + request.getQueryString());
- return new UriInfoImpl(absolutePath, baseURI, path, request.getQueryString(), pathSegments);
- }
+ return new UriInfoImpl(absolutePath, baseURI, path, request.getQueryString(), pathSegments);
+ }
}
Modified: branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/SeamResteasyProviderFactory.java
===================================================================
--- branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/SeamResteasyProviderFactory.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/SeamResteasyProviderFactory.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,3 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.seam.resteasy;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
@@ -5,21 +26,21 @@
/**
* TODO: We need to significantly extend and change that class so we can lookup provider instances
* through Seam at runtime. The original class has only been designed for registration of "singleton"
- * providers during startup.
+ * providers during startup. See comment about the TL handling in ResteasyResourceAdapter.java.
*
* @author Christian Bauer
*/
public class SeamResteasyProviderFactory extends ResteasyProviderFactory
{
- public static void setInstance(ResteasyProviderFactory factory)
- {
- ResteasyProviderFactory.setInstance(factory);
- }
+ public static void setInstance(ResteasyProviderFactory factory)
+ {
+ ResteasyProviderFactory.setInstance(factory);
+ }
- public static ResteasyProviderFactory getInstance()
- {
- return ResteasyProviderFactory.getInstance();
- }
+ public static ResteasyProviderFactory getInstance()
+ {
+ return ResteasyProviderFactory.getInstance();
+ }
}
Modified: branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/SeamResteasyResourceFactory.java
===================================================================
--- branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/SeamResteasyResourceFactory.java 2009-05-25 14:14:02 UTC (rev 10966)
+++ branches/community/Seam_2_1/src/resteasy/org/jboss/seam/resteasy/SeamResteasyResourceFactory.java 2009-05-25 14:19:52 UTC (rev 10967)
@@ -1,3 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.seam.resteasy;
import org.jboss.resteasy.spi.ResourceFactory;
@@ -13,61 +34,61 @@
import org.jboss.seam.log.Logging;
/**
- * Looks up Seam component in Seam contexts when a JAX RS resource is requested.
+ * Looks up Seam component in Seam contexts when a JAX-RS resource is requested.
*
* @author Christian Bauer
*/
public class SeamResteasyResourceFactory implements ResourceFactory
{
- Log log = Logging.getLog(SeamResteasyResourceFactory.class);
+ Log log = Logging.getLog(SeamResteasyResourceFactory.class);
- private final Class<?> resourceClass;
- private final Component seamComponent;
- private final ResteasyProviderFactory providerFactory;
+ private final Class<?> resourceType;
+ private final Component seamComponent;
+ private final ResteasyProviderFactory providerFactory;
- public SeamResteasyResourceFactory(Class<?> resourceClass, Component seamComponent, ResteasyProviderFactory providerFactory)
- {
- this.resourceClass = resourceClass;
- this.seamComponent = seamComponent;
- this.providerFactory = providerFactory;
- }
+ public SeamResteasyResourceFactory(Class<?> resourceType, Component seamComponent, ResteasyProviderFactory providerFactory)
+ {
+ this.resourceType = resourceType;
+ this.seamComponent = seamComponent;
+ this.providerFactory = providerFactory;
+ }
- public Class<?> getScannableClass()
- {
- return resourceClass;
- }
+ public Class<?> getScannableClass()
+ {
+ return resourceType;
+ }
- public void registered(InjectorFactory factory)
- {
- // Wrap the Resteasy PropertyInjectorImpl in a Seam interceptor (for @Context injection)
- seamComponent.addInterceptor(
- new ResteasyContextInjectionInterceptor(
- new PropertyInjectorImpl(getScannableClass(), providerFactory)
- )
- );
+ public void registered(InjectorFactory factory)
+ {
+ // Wrap the Resteasy PropertyInjectorImpl in a Seam interceptor (for @Context injection)
+ seamComponent.addInterceptor(
+ new ResteasyContextInjectionInterceptor(
+ new PropertyInjectorImpl(getScannableClass(), providerFactory)
+ )
+ );
- // NOTE: Adding an interceptor to Component at this stage means that the interceptor is
- // always executed last in the chain. The sorting of interceptors of a Component occurs
- // only when the Component metadata is instantiated. This is OK in this case, as the
- // JAX RS @Context injection can occur last after all other interceptors executed.
+ // NOTE: Adding an interceptor to Component at this stage means that the interceptor is
+ // always executed last in the chain. The sorting of interceptors of a Component occurs
+ // only when the Component metadata is instantiated. This is OK in this case, as the
+ // JAX RS @Context injection can occur last after all other interceptors executed.
- }
+ }
- public Object createResource(HttpRequest request, HttpResponse response, InjectorFactory factory)
- {
- // Push this onto event context so we have it available in ResteasyContextInjectionInterceptor
- Contexts.getEventContext().set(ResteasyContextInjectionInterceptor.RE_HTTP_REQUEST_VAR, request);
- Contexts.getEventContext().set(ResteasyContextInjectionInterceptor.RE_HTTP_RESPONSE_VAR, response);
- log.debug("creating RESTEasy resource instance by looking up Seam component: " + seamComponent.getName());
- return Component.getInstance(seamComponent.getName());
- }
+ public Object createResource(HttpRequest request, HttpResponse response, InjectorFactory factory)
+ {
+ // Push this onto event context so we have it available in ResteasyContextInjectionInterceptor
+ Contexts.getEventContext().set(ResteasyContextInjectionInterceptor.RE_HTTP_REQUEST_VAR, request);
+ Contexts.getEventContext().set(ResteasyContextInjectionInterceptor.RE_HTTP_RESPONSE_VAR, response);
+ log.debug("creating RESTEasy resource instance by looking up Seam component: " + seamComponent.getName());
+ return Component.getInstance(seamComponent.getName());
+ }
- public void requestFinished(HttpRequest request, HttpResponse response, Object resource)
- {
- }
+ public void requestFinished(HttpRequest request, HttpResponse response, Object resource)
+ {
+ }
- public void unregistered()
- {
- }
+ public void unregistered()
+ {
+ }
}
More information about the seam-commits
mailing list