[seam-commits] Seam SVN: r13318 - in modules/resteasy/trunk: api/src/main/java/org/jboss/seam/resteasy/configuration and 7 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Jun 29 09:03:19 EDT 2010


Author: jharting
Date: 2010-06-29 09:03:17 -0400 (Tue, 29 Jun 2010)
New Revision: 13318

Modified:
   modules/resteasy/trunk/api/
   modules/resteasy/trunk/api/src/main/java/org/jboss/seam/resteasy/configuration/SeamResteasyConfiguration.java
   modules/resteasy/trunk/impl/
   modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/ConfigurationListener.java
   modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/validation/ValidationExceptionMapper.java
   modules/resteasy/trunk/impl/src/main/resources/META-INF/web-fragment.xml
   modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ConfigurationTest.java
   modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/CustomSeamResteasyConfiguration.java
   modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/TestProvider.java
   modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/TestResource.java
   modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/validation/ValidationTest.java
   modules/resteasy/trunk/impl/src/test/resources/org/jboss/seam/resteasy/test/configuration/web.xml
Log:
svn:ignore


Property changes on: modules/resteasy/trunk/api
___________________________________________________________________
Name: svn:ignore
   + .classpath
.project
target
.settings


Modified: modules/resteasy/trunk/api/src/main/java/org/jboss/seam/resteasy/configuration/SeamResteasyConfiguration.java
===================================================================
--- modules/resteasy/trunk/api/src/main/java/org/jboss/seam/resteasy/configuration/SeamResteasyConfiguration.java	2010-06-29 07:48:31 UTC (rev 13317)
+++ modules/resteasy/trunk/api/src/main/java/org/jboss/seam/resteasy/configuration/SeamResteasyConfiguration.java	2010-06-29 13:03:17 UTC (rev 13318)
@@ -23,6 +23,7 @@
 public class SeamResteasyConfiguration
 {
    private Set<Class<?>> resources = new HashSet<Class<?>>();
+   private Set<Class<?>> excludedResources = new HashSet<Class<?>>();
    private Set<Class<?>> providers = new HashSet<Class<?>>();
 
    private Map<String, String> mediaTypeMappings = new HashMap<String, String>();
@@ -44,7 +45,20 @@
    {
       this.resources = resources;
    }
+   
+   /**
+    * Returns a set of resource classes that will be excluded from deployment. 
+    */
+   public Set<Class<?>> getExcludedResources()
+   {
+      return excludedResources;
+   }
 
+   public void setExcludedResources(Set<Class<?>> excludedResources)
+   {
+      this.excludedResources = excludedResources;
+   }
+
    /**
     * Returns a set of provider classes to be registered. 
     */


Property changes on: modules/resteasy/trunk/impl
___________________________________________________________________
Name: svn:ignore
   + .classpath
.project
target
temp-testng-customsuite.xml
test-output
.settings


Modified: modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/ConfigurationListener.java
===================================================================
--- modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/ConfigurationListener.java	2010-06-29 07:48:31 UTC (rev 13317)
+++ modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/ConfigurationListener.java	2010-06-29 13:03:17 UTC (rev 13318)
@@ -5,6 +5,7 @@
 import java.util.Map.Entry;
 
 import javax.inject.Inject;
+import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import javax.ws.rs.core.MediaType;
@@ -12,6 +13,7 @@
 
 import org.jboss.resteasy.core.Dispatcher;
 import org.jboss.resteasy.spi.Registry;
+import org.jboss.resteasy.spi.ResteasyDeployment;
 import org.jboss.resteasy.spi.ResteasyProviderFactory;
 import org.jboss.seam.resteasy.validation.ValidationExceptionMapper;
 import org.slf4j.Logger;
@@ -24,24 +26,43 @@
    private Dispatcher dispatcher;
    private ResteasyProviderFactory factory;
    private Registry registry;
-   
+
    private static final Logger log = LoggerFactory.getLogger(ConfigurationListener.class);
 
    public void contextInitialized(ServletContextEvent sce)
    {
+      if (sce.getServletContext().getAttribute(Dispatcher.class.getName()) == null)
+      {
+         // RESTEasy has not been initialized
+         bootstrapResteasy(sce.getServletContext());
+      }
+
       dispatcher = (Dispatcher) sce.getServletContext().getAttribute(Dispatcher.class.getName());
       factory = dispatcher.getProviderFactory();
       registry = dispatcher.getRegistry();
 
       log.info("Processing seam-resteasy configuration.");
-      
+
       registerProviders();
       registerResources();
+      unregisterResources(); // remove excluded resources
       dispatcher.setLanguageMappings(configuration.getLanguageMappings());
       registerMediaTypeMappings();
       registerExceptionMappings();
    }
 
+   protected void bootstrapResteasy(ServletContext servletContext)
+   {
+      log.info("Starting RESTEasy.");
+      SeamResteasyListenerBootstrap bootstrap = new SeamResteasyListenerBootstrap(servletContext);
+      ResteasyDeployment deployment = bootstrap.createDeployment();
+      deployment.start();
+
+      servletContext.setAttribute(ResteasyProviderFactory.class.getName(), deployment.getProviderFactory());
+      servletContext.setAttribute(Dispatcher.class.getName(), deployment.getDispatcher());
+      servletContext.setAttribute(Registry.class.getName(), deployment.getRegistry());
+   }
+
    private void registerResources()
    {
       for (Class<?> clazz : configuration.getResources())
@@ -50,6 +71,15 @@
          registry.addPerRequestResource(clazz);
       }
    }
+   
+   private void unregisterResources()
+   {
+      for (Class<?> clazz : configuration.getExcludedResources())
+      {
+         log.info("Excluding root resource {}.", clazz);
+         registry.removeRegistrations(clazz);
+      }
+   }
 
    private void registerProviders()
    {
@@ -84,14 +114,14 @@
             log.warn("{} is not an exception. Skipping mapping of the exception to {} status code.", item.getKey(), item.getValue());
          }
       }
-      
+
       // register ExceptionMapper for Bean Validation integration
       if (configuration.isRegisterValidationExceptionMapper())
       {
          factory.addExceptionMapper(ValidationExceptionMapper.class);
       }
    }
-   
+
    private void registerMediaTypeMappings()
    {
       Map<String, MediaType> mediaTypeMappings = new HashMap<String, MediaType>();

Modified: modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/validation/ValidationExceptionMapper.java
===================================================================
--- modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/validation/ValidationExceptionMapper.java	2010-06-29 07:48:31 UTC (rev 13317)
+++ modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/validation/ValidationExceptionMapper.java	2010-06-29 13:03:17 UTC (rev 13318)
@@ -16,7 +16,10 @@
       StringBuilder str = new StringBuilder();
       for (ConstraintViolation<Object> violation : exception.getViolations())
       {
+//         str.append(violation.getPropertyPath().toString());
+//         str.append(" ");
          str.append(violation.getMessage());
+         str.append("\n");
       }
       return response.entity(str.toString()).build();
    }

Modified: modules/resteasy/trunk/impl/src/main/resources/META-INF/web-fragment.xml
===================================================================
--- modules/resteasy/trunk/impl/src/main/resources/META-INF/web-fragment.xml	2010-06-29 07:48:31 UTC (rev 13317)
+++ modules/resteasy/trunk/impl/src/main/resources/META-INF/web-fragment.xml	2010-06-29 13:03:17 UTC (rev 13318)
@@ -10,4 +10,11 @@
 	<listener>
 		<listener-class>org.jboss.seam.resteasy.configuration.ConfigurationListener</listener-class>
 	</listener>
+	
+	<!-- Process the configuration listener after RESTEasy listener -->
+	<ordering>
+		<after>
+			<others/>
+		</after>
+	</ordering>
 </web-fragment>
\ No newline at end of file

Modified: modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ConfigurationTest.java
===================================================================
--- modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ConfigurationTest.java	2010-06-29 07:48:31 UTC (rev 13317)
+++ modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ConfigurationTest.java	2010-06-29 13:03:17 UTC (rev 13318)
@@ -1,89 +1,40 @@
 package org.jboss.seam.resteasy.test.configuration;
 
-
 import static org.testng.Assert.assertEquals;
 
-import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.GetMethod;
-import org.jboss.arquillian.api.Deployment;
 import org.jboss.arquillian.api.Run;
 import org.jboss.arquillian.api.RunModeType;
-import org.jboss.arquillian.testng.Arquillian;
-import org.jboss.seam.resteasy.configuration.ConfigurationListener;
-import org.jboss.seam.resteasy.configuration.GenericExceptionMapper;
-import org.jboss.seam.resteasy.configuration.SeamResteasyConfiguration;
-import org.jboss.seam.resteasy.validation.ValidationException;
-import org.jboss.seam.resteasy.validation.ValidationExceptionMapper;
-import org.jboss.shrinkwrap.api.ArchivePaths;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.seam.resteasy.test.SeamResteasyClientTest;
 import org.testng.annotations.Test;
 
 @Run(RunModeType.AS_CLIENT)
-public class ConfigurationTest 
-extends Arquillian
+public class ConfigurationTest extends SeamResteasyClientTest
 {
-   private HttpClient client = new HttpClient();
-   
-   @Deployment
-   public static WebArchive createDeployment()
-   {
-      JavaArchive jar = ShrinkWrap.create("seam-resteasy.jar", JavaArchive.class);
-      jar.addManifestResource("META-INF/web-fragment.xml", "web-fragment.xml");
-      jar.addManifestResource("META-INF/beans.xml", ArchivePaths.create("beans.xml"));
-      jar.addClass(SeamResteasyConfiguration.class);
-      jar.addClass(ConfigurationListener.class);
-      jar.addClass(GenericExceptionMapper.class);
-      jar.addClass(ValidationExceptionMapper.class);
-      jar.addClass(ValidationException.class);
-      WebArchive war = ShrinkWrap.create("test.war", WebArchive.class);
-      war.addClass(CustomSeamResteasyConfiguration.class);
-      war.addClass(EntityNotFoundException.class);
-      war.addClass(TestProvider.class);
-      war.addClass(TestResource.class);
-      war.addLibrary(jar);
-      war.addResource("META-INF/beans.xml", ArchivePaths.create("WEB-INF/beans.xml"));
-      war.setWebXML("org/jboss/seam/resteasy/test/configuration/web.xml");
-      return war;
-   }
-   
-   
    @Test
    public void testResource() throws Exception
    {
       test("http://localhost:8080/test/foo", 200, "foo");
    }
-   
+
    @Test
    public void testProvider() throws Exception
    {
-      GetMethod get = new GetMethod("http://localhost:8080/test/foo/bar");
+      GetMethod get = new GetMethod("http://localhost:8080/test/foo/student");
       get.setRequestHeader("Accept", "foo/bar");
       assertEquals(client.executeMethod(get), 200);
-      assertEquals(get.getResponseBodyAsString(), "foobar");
+      assertEquals(get.getResponseBodyAsString(), "Jozef Hartinger");
    }
-   
+
    @Test
    public void testExceptionMapping() throws Exception
    {
-      test("http://localhost:8080/test/foo/notFound", 404, null);
+      test("http://localhost:8080/test/foo/notFound", 410, null);
    }
-   
+
    @Test
    public void testMediaTypeMapping() throws Exception
    {
       test("http://localhost:8080/test/foo.xml", 200, "<foo/>");
    }
-   
-   private void test(String url, int expectedStatus, String expectedBody) throws Exception
-   {
-      GetMethod get = new GetMethod(url);
-      get.setRequestHeader("Accept", "text/plain");
-      assertEquals(client.executeMethod(get), expectedStatus);
-      if (expectedBody != null)
-      {
-         assertEquals(get.getResponseBodyAsString(), expectedBody);
-      }
-   }
 }

Modified: modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/CustomSeamResteasyConfiguration.java
===================================================================
--- modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/CustomSeamResteasyConfiguration.java	2010-06-29 07:48:31 UTC (rev 13317)
+++ modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/CustomSeamResteasyConfiguration.java	2010-06-29 13:03:17 UTC (rev 13318)
@@ -11,8 +11,9 @@
    public CustomSeamResteasyConfiguration()
    {
       getResources().add(TestResource.class);
+      getExcludedResources().add(ExcludedResource.class);
       getProviders().add(TestProvider.class);
-      getExceptionMappings().put(EntityNotFoundException.class, 404);
+      getExceptionMappings().put(EntityNotFoundException.class, 410);
       getMediaTypeMappings().put("xml", "application/xml");
    }
 }

Modified: modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/TestProvider.java
===================================================================
--- modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/TestProvider.java	2010-06-29 07:48:31 UTC (rev 13317)
+++ modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/TestProvider.java	2010-06-29 13:03:17 UTC (rev 13318)
@@ -6,16 +6,20 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 
+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 org.jboss.seam.resteasy.test.Student;
+
 @Provider
-public class TestProvider implements MessageBodyWriter<String>
+ at Produces("foo/bar")
+public class TestProvider implements MessageBodyWriter<Student>
 {
-   public long getSize(String t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)
+   public long getSize(Student t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)
    {
       return -1;
    }
@@ -25,10 +29,10 @@
       return mediaType.equals(MediaType.valueOf("foo/bar"));
    }
 
-   public void writeTo(String t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException
+   public void writeTo(Student t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException
    {
       OutputStreamWriter writer = new OutputStreamWriter(entityStream); 
-      writer.write("foo"+t);
+      writer.write(t.getName() + " Hartinger");
       writer.flush();
    }
 }

Modified: modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/TestResource.java
===================================================================
--- modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/TestResource.java	2010-06-29 07:48:31 UTC (rev 13317)
+++ modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/TestResource.java	2010-06-29 13:03:17 UTC (rev 13318)
@@ -4,6 +4,8 @@
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 
+import org.jboss.seam.resteasy.test.Student;
+
 @Path("foo")
 @Produces("text/plain")
 public class TestResource
@@ -22,11 +24,11 @@
    }
    
    @GET
-   @Path("bar")
+   @Path("student")
    @Produces("foo/bar")
-   public String bar()
+   public Student bar()
    {
-      return "bar";
+      return new Student("Jozef");
    }
    
    @GET

Modified: modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/validation/ValidationTest.java
===================================================================
--- modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/validation/ValidationTest.java	2010-06-29 07:48:31 UTC (rev 13317)
+++ modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/validation/ValidationTest.java	2010-06-29 13:03:17 UTC (rev 13318)
@@ -81,7 +81,7 @@
       catch (ValidationException e)
       {
          Response response = mapper.toResponse(e);
-         assertEquals(response.getEntity().toString(), "must be false");
+         assertEquals(response.getEntity().toString().trim(), "must be false");
       }
    }
    

Modified: modules/resteasy/trunk/impl/src/test/resources/org/jboss/seam/resteasy/test/configuration/web.xml
===================================================================
--- modules/resteasy/trunk/impl/src/test/resources/org/jboss/seam/resteasy/test/configuration/web.xml	2010-06-29 07:48:31 UTC (rev 13317)
+++ modules/resteasy/trunk/impl/src/test/resources/org/jboss/seam/resteasy/test/configuration/web.xml	2010-06-29 13:03:17 UTC (rev 13318)
@@ -5,23 +5,9 @@
       http://java.sun.com/xml/ns/javaee
       http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 
+	<!-- Disable auto-scanning -->
      <context-param>
-        <param-name>resteasy.scan</param-name>
-        <param-value>false</param-value>
+        <param-name>resteasy.scan.resources</param-name>
+        <param-value></param-value>
     </context-param>
-
-    <listener>
-        <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
-    </listener>
-
-	<servlet>
-		<servlet-name>Resteasy</servlet-name>
-		<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
-	</servlet>
-
-	<servlet-mapping>
-		<servlet-name>Resteasy</servlet-name>
-		<url-pattern>/*</url-pattern>
-	</servlet-mapping>
-
 </web-app>
\ No newline at end of file



More information about the seam-commits mailing list