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

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Jun 29 09:38:43 EDT 2010


Author: jharting
Date: 2010-06-29 09:38:42 -0400 (Tue, 29 Jun 2010)
New Revision: 13320

Added:
   modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/SeamResteasyBootstrap.java
   modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/SeamResteasyClientTest.java
   modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/Student.java
   modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ExcludedResource.java
   modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ExclusionTest.java
   modules/resteasy/trunk/impl/src/test/resources/org/jboss/seam/resteasy/test/configuration/excluded-web.xml
Modified:
   modules/resteasy/trunk/api/src/main/java/org/jboss/seam/resteasy/configuration/SeamResteasyConfiguration.java
   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/GenericExceptionMapper.java
   modules/resteasy/trunk/pom.xml
Log:
Get configuration working again.

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 13:07:52 UTC (rev 13319)
+++ modules/resteasy/trunk/api/src/main/java/org/jboss/seam/resteasy/configuration/SeamResteasyConfiguration.java	2010-06-29 13:38:42 UTC (rev 13320)
@@ -10,10 +10,10 @@
 /**
  * Holds configuration options for seam-resteasy extension. It can be used to configure the extension via XML descriptor
  * using seam-xml extension. Alternatively, you can configure the extension programatically by providing an 
- * @{link @Alternative} subclass of SeamResteasyConfiguration.
+ * {@link @Alternative} subclass of SeamResteasyConfiguration.
  * 
  * This class allows declarative exception mapping to be used. The way exceptions are treated in the application is based on
- * what @{link {@link #getExceptionMappings()} returns. Override this method or use seam-xml module to set up exception mapping
+ * what {@link #getExceptionMappings()} returns. Override this method or use seam-xml module to set up exception mapping
  * declaratively.
  * 
  * @author <a href="mailto:jharting at redhat.com">Jozef Hartinger</a>

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 13:07:52 UTC (rev 13319)
+++ modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/ConfigurationListener.java	2010-06-29 13:38:42 UTC (rev 13320)
@@ -33,7 +33,7 @@
    {
       if (sce.getServletContext().getAttribute(Dispatcher.class.getName()) == null)
       {
-         // RESTEasy has not been initialized
+         // RESTEasy has not been started yet, let's start it
          bootstrapResteasy(sce.getServletContext());
       }
 
@@ -45,16 +45,19 @@
 
       registerProviders();
       registerResources();
-      unregisterResources(); // remove excluded resources
+      unregisterResources();
       dispatcher.setLanguageMappings(configuration.getLanguageMappings());
       registerMediaTypeMappings();
       registerExceptionMappings();
    }
 
+   /**
+    * Bootstrap RESTEasy
+    */
    protected void bootstrapResteasy(ServletContext servletContext)
    {
       log.info("Starting RESTEasy.");
-      SeamResteasyListenerBootstrap bootstrap = new SeamResteasyListenerBootstrap(servletContext);
+      SeamResteasyBootstrap bootstrap = new SeamResteasyBootstrap(servletContext);
       ResteasyDeployment deployment = bootstrap.createDeployment();
       deployment.start();
 
@@ -63,7 +66,10 @@
       servletContext.setAttribute(Registry.class.getName(), deployment.getRegistry());
    }
 
-   private void registerResources()
+   /**
+    * Register resources specified in {@link SeamResteasyConfiguration}.
+    */
+   protected void registerResources()
    {
       for (Class<?> clazz : configuration.getResources())
       {
@@ -72,7 +78,12 @@
       }
    }
    
-   private void unregisterResources()
+   /**
+    * Unregister resources specified in {@link SeamResteasyConfiguration}.
+    * This method is used for explicit exclusion of resources that would be
+    * registered by auto-scanning.
+    */
+   protected void unregisterResources()
    {
       for (Class<?> clazz : configuration.getExcludedResources())
       {
@@ -81,7 +92,10 @@
       }
    }
 
-   private void registerProviders()
+   /**
+    * Register providers specified in {@link SeamResteasyConfiguration}.
+    */
+   protected void registerProviders()
    {
       for (Class<?> clazz : configuration.getProviders())
       {
@@ -90,7 +104,10 @@
       }
    }
 
-   private void registerExceptionMappings()
+   /**
+    * Register exception mappers based on {@link SeamResteasyConfiguration}.
+    */
+   protected void registerExceptionMappings()
    {
       for (Entry<Class<? extends Throwable>, Integer> item : configuration.getExceptionMappings().entrySet())
       {
@@ -122,7 +139,10 @@
       }
    }
 
-   private void registerMediaTypeMappings()
+   /**
+    * Register media mappings based on {@link SeamResteasyConfiguration}.
+    */
+   protected void registerMediaTypeMappings()
    {
       Map<String, MediaType> mediaTypeMappings = new HashMap<String, MediaType>();
       for (Entry<String, String> entry : configuration.getMediaTypeMappings().entrySet())

Modified: modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/GenericExceptionMapper.java
===================================================================
--- modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/GenericExceptionMapper.java	2010-06-29 13:07:52 UTC (rev 13319)
+++ modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/GenericExceptionMapper.java	2010-06-29 13:38:42 UTC (rev 13320)
@@ -3,6 +3,12 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.ExceptionMapper;
 
+/**
+ * GenericExceptionMapper allows exceptions to be mapped to HTTP status codes declaratively (at runtime).
+ * @author Jozef Hartinger
+ *
+ * @param <T> exception
+ */
 public class GenericExceptionMapper<T extends Throwable> implements ExceptionMapper<T>
 {
    private int status;

Added: modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/SeamResteasyBootstrap.java
===================================================================
--- modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/SeamResteasyBootstrap.java	                        (rev 0)
+++ modules/resteasy/trunk/impl/src/main/java/org/jboss/seam/resteasy/configuration/SeamResteasyBootstrap.java	2010-06-29 13:38:42 UTC (rev 13320)
@@ -0,0 +1,50 @@
+package org.jboss.seam.resteasy.configuration;
+
+import javax.servlet.FilterRegistration;
+import javax.servlet.ServletContext;
+
+import org.jboss.resteasy.plugins.server.servlet.ListenerBootstrap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * @author Jozef Hartinger
+ *
+ */
+public class SeamResteasyBootstrap extends ListenerBootstrap
+{
+   private FilterRegistration filter;
+   private static final Logger log = LoggerFactory.getLogger(SeamResteasyBootstrap.class);
+   
+   public SeamResteasyBootstrap(ServletContext servletContext)
+   {
+      super(servletContext);
+      filter = servletContext.getFilterRegistration("Resteasy");
+      if (filter != null)
+      {
+         log.debug("Found RESTEasy filter registration.");
+      }
+   }
+
+   @Override
+   public String getInitParameter(String name)
+   {
+      return getParameter(name);
+   }
+
+   @Override
+   public String getParameter(String name)
+   {
+      String value = null;
+      if (filter != null)
+      {
+         value = filter.getInitParameter(name);
+      }
+      if (value == null)
+      {
+         value = super.getInitParameter(name);
+      }
+      return value;
+   }
+}

Added: modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/SeamResteasyClientTest.java
===================================================================
--- modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/SeamResteasyClientTest.java	                        (rev 0)
+++ modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/SeamResteasyClientTest.java	2010-06-29 13:38:42 UTC (rev 13320)
@@ -0,0 +1,80 @@
+package org.jboss.seam.resteasy.test;
+
+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.configuration.SeamResteasyBootstrap;
+import org.jboss.seam.resteasy.test.configuration.CustomSeamResteasyConfiguration;
+import org.jboss.seam.resteasy.test.configuration.EntityNotFoundException;
+import org.jboss.seam.resteasy.test.configuration.ExcludedResource;
+import org.jboss.seam.resteasy.test.configuration.TestProvider;
+import org.jboss.seam.resteasy.test.configuration.TestResource;
+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;
+
+ at Run(RunModeType.AS_CLIENT)
+public abstract class SeamResteasyClientTest extends Arquillian
+{
+   protected HttpClient client = new HttpClient();
+   
+   @Deployment
+   public static WebArchive createDeployment()
+   {
+      JavaArchive jar = createSeamResteasyLibrary();
+      WebArchive war = createTestApplication();
+      war.addLibrary(jar);
+      return war;
+   }
+   
+   public static JavaArchive createSeamResteasyLibrary()
+   {
+      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(SeamResteasyBootstrap.class);
+      jar.addClass(ConfigurationListener.class);
+      jar.addClass(GenericExceptionMapper.class);
+      jar.addClass(ValidationExceptionMapper.class);
+      jar.addClass(ValidationException.class);
+      jar.addClass(SeamResteasyClientTest.class); // ARQ-165
+      return jar;
+   }
+   
+   public static WebArchive createTestApplication()
+   {
+      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.addClass(ExcludedResource.class);
+      war.addClass(Student.class);
+      war.addResource("META-INF/beans.xml", ArchivePaths.create("WEB-INF/beans.xml"));
+      war.setWebXML("org/jboss/seam/resteasy/test/configuration/web.xml");
+      return war;
+   }
+   
+   protected 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);
+      }
+   }
+}

Added: modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/Student.java
===================================================================
--- modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/Student.java	                        (rev 0)
+++ modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/Student.java	2010-06-29 13:38:42 UTC (rev 13320)
@@ -0,0 +1,24 @@
+package org.jboss.seam.resteasy.test;
+
+/**
+ * Sample domain class
+ */
+public class Student
+{
+   private String name;
+
+   public Student(String name)
+   {
+      this.name = name;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+}

Added: modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ExcludedResource.java
===================================================================
--- modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ExcludedResource.java	                        (rev 0)
+++ modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ExcludedResource.java	2010-06-29 13:38:42 UTC (rev 13320)
@@ -0,0 +1,22 @@
+package org.jboss.seam.resteasy.test.configuration;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.jboss.seam.resteasy.configuration.SeamResteasyConfiguration;
+
+/**
+ * This resource is registered by auto-scanning and is later on excluded via {@link SeamResteasyConfiguration}
+ * @author Jozef Hartinger
+ *
+ */
+ at Path("/excluded")
+ at Produces("text/plain")
+public class ExcludedResource
+{
+   @GET
+   public void echo()
+   {
+   }
+}

Added: modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ExclusionTest.java
===================================================================
--- modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ExclusionTest.java	                        (rev 0)
+++ modules/resteasy/trunk/impl/src/test/java/org/jboss/seam/resteasy/test/configuration/ExclusionTest.java	2010-06-29 13:38:42 UTC (rev 13320)
@@ -0,0 +1,30 @@
+package org.jboss.seam.resteasy.test.configuration;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.api.Run;
+import org.jboss.arquillian.api.RunModeType;
+import org.jboss.seam.resteasy.test.SeamResteasyClientTest;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.testng.annotations.Test;
+
+ at Run(RunModeType.AS_CLIENT)
+public class ExclusionTest extends SeamResteasyClientTest
+{
+   @Deployment
+   public static WebArchive createDeployment()
+   {
+      JavaArchive jar = createSeamResteasyLibrary();
+      WebArchive war = createTestApplication();
+      war.setWebXML("org/jboss/seam/resteasy/test/configuration/excluded-web.xml");
+      war.addLibrary(jar);
+      return war;
+   }
+   
+   @Test
+   public void testExcludedResourceNotRegistered() throws Exception
+   {
+      // the resource should be added by auto-scanning and then removed by seam-resteasy configuration 
+      test("http://localhost:8080/test/excluded", 404, null);
+   }
+}

Added: modules/resteasy/trunk/impl/src/test/resources/org/jboss/seam/resteasy/test/configuration/excluded-web.xml
===================================================================
--- modules/resteasy/trunk/impl/src/test/resources/org/jboss/seam/resteasy/test/configuration/excluded-web.xml	                        (rev 0)
+++ modules/resteasy/trunk/impl/src/test/resources/org/jboss/seam/resteasy/test/configuration/excluded-web.xml	2010-06-29 13:38:42 UTC (rev 13320)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="
+      http://java.sun.com/xml/ns/javaee
+      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+</web-app>
\ No newline at end of file

Modified: modules/resteasy/trunk/pom.xml
===================================================================
--- modules/resteasy/trunk/pom.xml	2010-06-29 13:07:52 UTC (rev 13319)
+++ modules/resteasy/trunk/pom.xml	2010-06-29 13:38:42 UTC (rev 13320)
@@ -72,7 +72,7 @@
 		<dependency>
 			<groupId>org.jboss.resteasy</groupId>
 			<artifactId>resteasy-jaxrs</artifactId>
-			<version>2.0-beta-3</version>
+			<version>2.0-beta-4</version>
 			<scope>provided</scope>
 		</dependency>
 		<!-- Required until the Servlet 3.0 API can be resolved in Central -->
@@ -102,7 +102,8 @@
 		<dependency>
 			<groupId>org.jboss.jbossas</groupId>
 			<artifactId>jboss-as-client</artifactId>
-			<version>6.0.0.20100429-M3</version>
+			<version>6.0.0-SNAPSHOT</version>
+<!--			<version>6.0.0.20100429-M3</version>-->
 			<type>pom</type>
 			<scope>test</scope>
 		</dependency>
@@ -128,7 +129,7 @@
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-dependency-plugin</artifactId>
 				<configuration>
-					<includeArtifactIds>arquillian-testng,arquillian-api,arquillian-spi,commons-httpclient,testng,shrinkwrap-api,shrinkwrap-impl-base,resteasy-jaxrs</includeArtifactIds>
+					<includeArtifactIds>arquillian-testng,arquillian-api,arquillian-spi,commons-httpclient,testng,shrinkwrap-api,shrinkwrap-impl-base</includeArtifactIds>
 					<outputDirectory>${basedir}/test-dependencies</outputDirectory>
 				</configuration>
 			</plugin>



More information about the seam-commits mailing list