tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1607042 - in /tomee/tomee/trunk: container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/WebXmlSpecApplicationTest.java
Date Tue, 01 Jul 2014 11:05:14 GMT
Author: rmannibucau
Date: Tue Jul  1 11:05:13 2014
New Revision: 1607042

URL: http://svn.apache.org/r1607042
Log:
TOMEE-1262 supporting javax.ws.rs.core.Application in web.xml without init param

Added:
    tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/WebXmlSpecApplicationTest.java
      - copied, changed from r1606980, tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CDIApplicationTest.java
Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1607042&r1=1607041&r2=1607042&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
Tue Jul  1 11:05:13 2014
@@ -97,6 +97,7 @@ import org.apache.openejb.jee.SecurityId
 import org.apache.openejb.jee.SecurityRoleRef;
 import org.apache.openejb.jee.ServiceRef;
 import org.apache.openejb.jee.Servlet;
+import org.apache.openejb.jee.ServletMapping;
 import org.apache.openejb.jee.Session;
 import org.apache.openejb.jee.SessionBean;
 import org.apache.openejb.jee.SessionType;
@@ -2118,9 +2119,21 @@ public class AnnotationDeployer implemen
              * Servlet classes are scanned
              */
             for (final Servlet servlet : webApp.getServlet()) {
+                final String servletName = servlet.getServletName();
+                if ("javax.ws.rs.core.Application".equals(servletName)) {
+                    servlet.setServletName(ProvidedJAXRSApplication.class.getName());
+                    webModule.getRestApplications().add(ProvidedJAXRSApplication.class.getName());
+                    for (final ServletMapping mapping : webApp.getServletMapping()) {
+                        if (servletName.equals(mapping.getServletName())) {
+                            mapping.setServletName(ProvidedJAXRSApplication.class.getName());
+                        }
+                    }
+                    continue;
+                }
+
                 String servletClass = realClassName(servlet.getServletClass());
                 if (servletClass == null) { // try with servlet name, @see org.apache.openejb.arquillian.tests.jaxrs.basicapp.BasicApplication
-                    servletClass = realClassName(servlet.getServletName());
+                    servletClass = realClassName(servletName);
                 }
 
                 if (servletClass != null && servlet.getJspFile() == null) { // jaxrs
application doesn't have a jsp file
@@ -2135,7 +2148,7 @@ public class AnnotationDeployer implemen
                             if (servlet.getServletClass() != null) {
                                 throw new OpenEJBException("Unable to load servlet class:
" + servletClass, e);
                             } else {
-                                logger.error("servlet " + servlet.getServletName() + " has
no servlet-class defined and is not a subclass of Application");
+                                logger.error("servlet " + servletName + " has no servlet-class
defined and is not a subclass of Application");
                             }
                         }
                     }
@@ -5573,4 +5586,7 @@ public class AnnotationDeployer implemen
     }
 
 
+    public static class ProvidedJAXRSApplication extends Application {
+        // no-method
+    }
 }

Copied: tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/WebXmlSpecApplicationTest.java
(from r1606980, tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CDIApplicationTest.java)
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/WebXmlSpecApplicationTest.java?p2=tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/WebXmlSpecApplicationTest.java&p1=tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CDIApplicationTest.java&r1=1606980&r2=1607042&rev=1607042&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CDIApplicationTest.java
(original)
+++ tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/WebXmlSpecApplicationTest.java
Tue Jul  1 11:05:13 2014
@@ -27,6 +27,8 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
 import javax.ws.rs.core.Application;
 import java.util.HashSet;
 import java.util.Set;
@@ -36,41 +38,25 @@ import static org.junit.Assert.assertTru
 
 @EnableServices("jax-rs")
 @RunWith(ApplicationComposer.class)
-public class CDIApplicationTest {
+public class WebXmlSpecApplicationTest {
     @Module
-    @Classes(cdi = true, value = { MyCdiRESTApplication.class, MyFirstRestClass.class,  ACdiBeanInjectedInApp.class
})
+    @Classes(Resource.class)
     public WebApp war() {
         return new WebApp()
                 .contextRoot("foo")
-                .addServlet("REST Application", Application.class.getName())
-                .addInitParam("REST Application", "javax.ws.rs.Application", MyCdiRESTApplication.class.getName());
+                .addServlet(Application.class.getName(), null, "/resources/*");
     }
 
     @Test
-    public void isCdi() {
-        assertTrue(MyCdiRESTApplication.injection);
-        assertEquals("Hi from REST World!", WebClient.create("http://localhost:4204/foo/").path("/first/hi").get(String.class));
+    public void checkItIsDeployed() {
+        assertEquals("r", WebClient.create("http://localhost:4204/foo/").path("/resources/r").get(String.class));
     }
 
-    public static class ACdiBeanInjectedInApp {}
-
-    public static class MyCdiRESTApplication extends Application {
-        public static boolean injection = false;
-
-        @Inject
-        private ACdiBeanInjectedInApp cdi;
-
-        public Set<Class<?>> getClasses() {
-            injection = cdi != null;
-
-            if (cdi == null) {
-                throw new NullPointerException();
-            }
-
-            // if no class are returned we use scanning, since we don't test rest deployment
we put a single class
-            final Set<Class<?>> clazz = new HashSet<Class<?>>();
-            clazz.add(MyFirstRestClass.class);
-            return clazz;
+    @Path("r")
+    public static class Resource {
+        @GET
+        public String g() {
+            return "r";
         }
     }
 }



Mime
View raw message