You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2015/02/05 04:05:10 UTC

cxf git commit: CXF-6132: Provide JAX-RS ServletContextInitializer. Adding more test cases.

Repository: cxf
Updated Branches:
  refs/heads/master 6bf377f6a -> 1d9e79ef3


CXF-6132: Provide JAX-RS ServletContextInitializer. Adding more test cases.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/1d9e79ef
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1d9e79ef
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1d9e79ef

Branch: refs/heads/master
Commit: 1d9e79ef36bf14e25d7cd2cccb0d804a048aef64
Parents: 6bf377f
Author: reta <dr...@gmail.com>
Authored: Wed Feb 4 22:04:12 2015 -0500
Committer: reta <dr...@gmail.com>
Committed: Wed Feb 4 22:04:38 2015 -0500

----------------------------------------------------------------------
 .../JaxrsServletContainerInitializer.java       |  5 +-
 .../jetty/JettyEmptyApplicationTest.java        | 64 ++++++++++++++++++
 .../jetty/JettyEmptyPathApplicationTest.java    | 71 ++++++++++++++++++++
 .../applications/empty/BookApplication.java     | 26 +++++++
 .../applications/emptypath/BookApplication.java | 24 +++++++
 .../src/test/resources/WEB-INF/web-subclass.xml | 10 +++
 6 files changed, 198 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1d9e79ef/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java
----------------------------------------------------------------------
diff --git a/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java b/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java
index 89c6b39..c872926 100644
--- a/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java
+++ b/rt/rs/http-sci/src/main/java/org/apache/cxf/jaxrs/servlet/JaxrsServletContainerInitializer.java
@@ -82,7 +82,7 @@ public class JaxrsServletContainerInitializer implements ServletContainerInitial
         // If application is null or empty then try to create a new application from available
         // resource and provider classes
         if (app == null
-            || app.getClasses().isEmpty() && app.getSingletons().isEmpty()) {
+            || (app.getClasses().isEmpty() && app.getSingletons().isEmpty())) {
             // The best effort at detecting a CXFNonSpringJaxrsServlet
             // Custom servlets using non-standard mechanisms to create Application will not be detected
             if (isCxfServletAvailable(ctx)) {
@@ -98,7 +98,8 @@ public class JaxrsServletContainerInitializer implements ServletContainerInitial
                     // Servlet mapping is obtained from a servlet registration 
                     // with a JAX-RS Application class name
                     servletMapping = getServletMapping(ctx, servletName);
-                }
+                } 
+                
                 app = new Application() {
                     @Override
                     public Set<Class<?>> getClasses() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/1d9e79ef/systests/rs-http-sci/src/test/java/org/apache/cxf/jaxrs/servlet/jetty/JettyEmptyApplicationTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-http-sci/src/test/java/org/apache/cxf/jaxrs/servlet/jetty/JettyEmptyApplicationTest.java b/systests/rs-http-sci/src/test/java/org/apache/cxf/jaxrs/servlet/jetty/JettyEmptyApplicationTest.java
new file mode 100644
index 0000000..af8a5be
--- /dev/null
+++ b/systests/rs-http-sci/src/test/java/org/apache/cxf/jaxrs/servlet/jetty/JettyEmptyApplicationTest.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.servlet.jetty;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.jaxrs.servlet.AbstractSciTest;
+import org.eclipse.jetty.util.resource.Resource;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+
+public class JettyEmptyApplicationTest extends AbstractSciTest {  
+    @Ignore
+    public static class EmbeddedJettyServer extends AbstractJettyServer {
+        public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class);
+
+        public EmbeddedJettyServer() {
+            super("/",
+                new Resource[] {
+                    // Limit the classpath scanning to org.apache.demo.resources package
+                    Resource.newClassPathResource("/org/apache/demo/resources"),
+                    // Include JAX-RS application from org.apache.applications.empty package
+                    Resource.newClassPathResource("/org/apache/demo/applications/empty"),
+                    // Include Jackson @Providers into classpath scanning
+                    Resource.newResource(JacksonJsonProvider.class.getProtectionDomain().getCodeSource().getLocation())
+                }, PORT);
+        }        
+    }
+    
+    @BeforeClass
+    public static void startServers() throws Exception {
+        AbstractResourceInfo.clearAllMaps();
+        assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true));
+        createStaticBus();
+    }
+    
+    @Override
+    protected int getPort() {
+        return EmbeddedJettyServer.PORT;
+    }
+
+    @Override
+    protected String getContextPath() {
+        return "/api";
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/1d9e79ef/systests/rs-http-sci/src/test/java/org/apache/cxf/jaxrs/servlet/jetty/JettyEmptyPathApplicationTest.java
----------------------------------------------------------------------
diff --git a/systests/rs-http-sci/src/test/java/org/apache/cxf/jaxrs/servlet/jetty/JettyEmptyPathApplicationTest.java b/systests/rs-http-sci/src/test/java/org/apache/cxf/jaxrs/servlet/jetty/JettyEmptyPathApplicationTest.java
new file mode 100644
index 0000000..0318bd8
--- /dev/null
+++ b/systests/rs-http-sci/src/test/java/org/apache/cxf/jaxrs/servlet/jetty/JettyEmptyPathApplicationTest.java
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.servlet.jetty;
+
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.jaxrs.servlet.AbstractSciTest;
+import org.eclipse.jetty.util.resource.Resource;
+import org.eclipse.jetty.webapp.WebAppContext;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+
+public class JettyEmptyPathApplicationTest extends AbstractSciTest {  
+    @Ignore
+    public static class EmbeddedJettyServer extends AbstractJettyServer {
+        public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class);
+
+        public EmbeddedJettyServer() {
+            super("/",
+                new Resource[] {
+                    // Limit the classpath scanning to org.apache.demo.resources package
+                    Resource.newClassPathResource("/org/apache/demo/resources"),
+                    // Include JAX-RS application from org.apache.applications.empty package
+                    Resource.newClassPathResource("/org/apache/demo/applications/emptypath"),
+                    // Include Jackson @Providers into classpath scanning
+                    Resource.newResource(JacksonJsonProvider.class.getProtectionDomain().getCodeSource().getLocation())
+                }, PORT);
+        }        
+        
+        @Override
+        protected void configureContext(final WebAppContext context) throws Exception {     
+            context.setDescriptor(Resource
+                .newClassPathResource("/WEB-INF/web-subclass.xml").getFile().toURI().getPath());
+        }
+    }
+    
+    @BeforeClass
+    public static void startServers() throws Exception {
+        AbstractResourceInfo.clearAllMaps();
+        assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true));
+        createStaticBus();
+    }
+    
+    @Override
+    protected int getPort() {
+        return EmbeddedJettyServer.PORT;
+    }
+
+    @Override
+    protected String getContextPath() {
+        return "/subapi";
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/1d9e79ef/systests/rs-http-sci/src/test/java/org/apache/demo/applications/empty/BookApplication.java
----------------------------------------------------------------------
diff --git a/systests/rs-http-sci/src/test/java/org/apache/demo/applications/empty/BookApplication.java b/systests/rs-http-sci/src/test/java/org/apache/demo/applications/empty/BookApplication.java
new file mode 100644
index 0000000..a90f529
--- /dev/null
+++ b/systests/rs-http-sci/src/test/java/org/apache/demo/applications/empty/BookApplication.java
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.demo.applications.empty;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@ApplicationPath("/api")
+public class BookApplication extends Application {    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/1d9e79ef/systests/rs-http-sci/src/test/java/org/apache/demo/applications/emptypath/BookApplication.java
----------------------------------------------------------------------
diff --git a/systests/rs-http-sci/src/test/java/org/apache/demo/applications/emptypath/BookApplication.java b/systests/rs-http-sci/src/test/java/org/apache/demo/applications/emptypath/BookApplication.java
new file mode 100644
index 0000000..cb91d5f
--- /dev/null
+++ b/systests/rs-http-sci/src/test/java/org/apache/demo/applications/emptypath/BookApplication.java
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.demo.applications.emptypath;
+
+import javax.ws.rs.core.Application;
+
+public class BookApplication extends Application {    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/1d9e79ef/systests/rs-http-sci/src/test/resources/WEB-INF/web-subclass.xml
----------------------------------------------------------------------
diff --git a/systests/rs-http-sci/src/test/resources/WEB-INF/web-subclass.xml b/systests/rs-http-sci/src/test/resources/WEB-INF/web-subclass.xml
new file mode 100644
index 0000000..fb8984a
--- /dev/null
+++ b/systests/rs-http-sci/src/test/resources/WEB-INF/web-subclass.xml
@@ -0,0 +1,10 @@
+<web-app version="3.0" 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_3_0.xsd">
+	<servlet>
+		<servlet-name>org.apache.demo.applications.emptypath.BookApplication</servlet-name>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>org.apache.demo.applications.emptypath.BookApplication</servlet-name>
+		<url-pattern>/subapi/*</url-pattern>
+	</servlet-mapping>
+</web-app>
\ No newline at end of file