You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2016/02/23 12:01:01 UTC
tomee git commit: TOMEE-1718 avoid NPE when jaxrs application if
configured without a servlet class
Repository: tomee
Updated Branches:
refs/heads/master 3bf5aa105 -> 87120faad
TOMEE-1718 avoid NPE when jaxrs application if configured without a servlet class
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/87120faa
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/87120faa
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/87120faa
Branch: refs/heads/master
Commit: 87120faad06a30e4dc898bc2492d155bc811ea1d
Parents: 3bf5aa1
Author: Romain manni-Bucau <rm...@gmail.com>
Authored: Tue Feb 23 11:00:23 2016 +0000
Committer: Romain manni-Bucau <rm...@gmail.com>
Committed: Tue Feb 23 11:00:23 2016 +0000
----------------------------------------------------------------------
.../embedded/JAXRSWebXmlMappingTest.java | 66 ++++++++++++++++++++
.../openejb/arquillian/embedded/SimpleApp.java | 22 +++++++
.../openejb/config/AnnotationDeployer.java | 23 +++++--
.../tomee/catalina/OpenEJBContextConfig.java | 4 +-
4 files changed, 108 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/87120faa/arquillian/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/embedded/JAXRSWebXmlMappingTest.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/embedded/JAXRSWebXmlMappingTest.java b/arquillian/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/embedded/JAXRSWebXmlMappingTest.java
new file mode 100644
index 0000000..ae4456c
--- /dev/null
+++ b/arquillian/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/embedded/JAXRSWebXmlMappingTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.openejb.arquillian.embedded;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.descriptor.api.Descriptors;
+import org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor;
+import org.jboss.shrinkwrap.descriptor.api.webcommon31.WebAppVersionType;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ws.rs.client.ClientBuilder;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Arquillian.class)
+public class JAXRSWebXmlMappingTest {
+ @Deployment(testable = false)
+ public static Archive<?> app() {
+ return ShrinkWrap.create(WebArchive.class, JAXRSWebXmlMappingTest.class.getSimpleName() + ".war")
+ .addClass(ARestService.class)
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .setWebXML(new StringAsset(
+ Descriptors.create(WebAppDescriptor.class)
+ .version(WebAppVersionType._3_1)
+ .getOrCreateServlet().servletName("javax.ws.rs.core.Application")
+ .getOrCreateInitParam().paramName("javax.ws.rs.Application").paramValue(SimpleApp.class.getName()).up()
+ .up()
+ .getOrCreateServletMapping().servletName("javax.ws.rs.core.Application").urlPattern("/rs/*").up()
+ .exportAsString()
+ ));
+ }
+
+ @ArquillianResource
+ private URL base;
+
+ @Test
+ public void noNpe() throws MalformedURLException { // TOMEE-1718
+ assertEquals(
+ "foo",
+ ClientBuilder.newBuilder().build().target(new URL(base, "rs/rest/foo").toExternalForm()).request().get(String.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/87120faa/arquillian/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/embedded/SimpleApp.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/embedded/SimpleApp.java b/arquillian/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/embedded/SimpleApp.java
new file mode 100644
index 0000000..72a560e
--- /dev/null
+++ b/arquillian/arquillian-tomee-embedded/src/test/java/org/apache/openejb/arquillian/embedded/SimpleApp.java
@@ -0,0 +1,22 @@
+/**
+ * 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.openejb.arquillian.embedded;
+
+import javax.ws.rs.core.Application;
+
+public class SimpleApp extends Application {
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/87120faa/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java b/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
index a06f68b..2d4569a 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
@@ -2211,12 +2211,23 @@ public class AnnotationDeployer implements DynamicDeployer {
*/
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());
+ if ("javax.ws.rs.core.Application".equals(servletName) || "javax.ws.rs.Application".equals(servletName)) {
+ // check first if there is a real application as init param
+ boolean done = false;
+ for (final ParamValue pv : servlet.getInitParam()) {
+ if ("javax.ws.rs.core.Application".equals(pv.getParamName()) || "javax.ws.rs.Application".equals(pv.getParamName())) {
+ webModule.getRestApplications().add(pv.getParamValue());
+ done = true;
+ break;
+ }
+ }
+ if (!done) {
+ 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;
http://git-wip-us.apache.org/repos/asf/tomee/blob/87120faa/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
index b3d06a4..910bffa 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/OpenEJBContextConfig.java
@@ -201,7 +201,9 @@ public class OpenEJBContextConfig extends ContextConfig {
try { // remove only "fake" servlets to let users use their own stuff
if (child != null) {
final String servletClass = StandardWrapper.class.cast(child).getServletClass();
- if ("org.apache.openejb.server.rest.OpenEJBRestServlet".equals(servletClass) || !HttpServlet.class.isAssignableFrom(info.loader().loadClass(servletClass))) {
+ if (servletClass == null
+ || "org.apache.openejb.server.rest.OpenEJBRestServlet".equals(servletClass)
+ || !HttpServlet.class.isAssignableFrom(info.loader().loadClass(servletClass))) {
context.removeChild(child);
}
}