attempt to fix JAX-RS TCK after TOMEE-4406
diff --git a/tck/jax-rs/jax-rs-tests/src/test/conf/web.xml b/tck/jax-rs/jax-rs-tests/src/test/conf/web.xml
new file mode 100644
index 0000000..0634398
--- /dev/null
+++ b/tck/jax-rs/jax-rs-tests/src/test/conf/web.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
+ https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
+ version="6.0">
+
+ <!-- NotFoundServlet is injected into deployments using JaxRsTckExtension,
+ but we use this global web.xml because it is more convenient than overwriting web.xml in said Extension -->
+ <servlet>
+ <servlet-name>default</servlet-name>
+ <servlet-class>org.apache.tomee.tck.jaxrs.NotFoundServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>default</servlet-name>
+ <url-pattern>/</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tck/jax-rs/jax-rs-tests/src/test/java/org/apache/tomee/tck/jaxrs/JaxRsTckExtension.java b/tck/jax-rs/jax-rs-tests/src/test/java/org/apache/tomee/tck/jaxrs/JaxRsTckExtension.java
new file mode 100644
index 0000000..6158013
--- /dev/null
+++ b/tck/jax-rs/jax-rs-tests/src/test/java/org/apache/tomee/tck/jaxrs/JaxRsTckExtension.java
@@ -0,0 +1,38 @@
+/*
+ * 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.tomee.tck.jaxrs;
+
+import org.jboss.arquillian.container.spi.event.container.BeforeDeploy;
+import org.jboss.arquillian.core.api.annotation.Observes;
+import org.jboss.arquillian.core.spi.LoadableExtension;
+import org.jboss.shrinkwrap.api.container.ClassContainer;
+
+// inject NotFoundServlet into the deployment to make our global web.xml override work
+public class JaxRsTckExtension implements LoadableExtension {
+ @Override
+ public void register(ExtensionBuilder builder) {
+ builder.observer(getClass());
+ }
+
+ public void observeDeployment(@Observes BeforeDeploy bd) {
+ if (bd.getDeployment().getArchive() instanceof ClassContainer<?> classContainer) {
+ classContainer.addClass(NotFoundServlet.class);
+ }
+ }
+}
diff --git a/tck/jax-rs/jax-rs-tests/src/test/java/org/apache/tomee/tck/jaxrs/NotFoundServlet.java b/tck/jax-rs/jax-rs-tests/src/test/java/org/apache/tomee/tck/jaxrs/NotFoundServlet.java
new file mode 100644
index 0000000..84c2e5b
--- /dev/null
+++ b/tck/jax-rs/jax-rs-tests/src/test/java/org/apache/tomee/tck/jaxrs/NotFoundServlet.java
@@ -0,0 +1,36 @@
+/*
+ * 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.tomee.tck.jaxrs;
+
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+
+/**
+ * TCK likes to send requests to unknown URLs, which can cause a 405 in tomcats default servlet with non GET requests.
+ * This servlet will instead always return a 404 to make the TCK happy
+ */
+public class NotFoundServlet extends HttpServlet {
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
+ }
+}
diff --git a/tck/jax-rs/jax-rs-tests/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension b/tck/jax-rs/jax-rs-tests/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
new file mode 100644
index 0000000..1a7e101
--- /dev/null
+++ b/tck/jax-rs/jax-rs-tests/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
@@ -0,0 +1 @@
+org.apache.tomee.tck.jaxrs.JaxRsTckExtension
diff --git a/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/CXFJAXRSFilter.java b/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/CXFJAXRSFilter.java
index 02d324f..2bf3297 100644
--- a/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/CXFJAXRSFilter.java
+++ b/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/CXFJAXRSFilter.java
@@ -60,7 +60,7 @@
}
// if a servlet matched it always has priority over JAX-RS endpoints, see TOMEE-4406
- if (nonDefaultServletMatches(httpServletRequest)) {
+ if (!defaultServletMatched(httpServletRequest)) {
chain.doFilter(request, response);
return;
}
@@ -89,13 +89,13 @@
* Checks if the request matched a defined servlet mapping matches the given request
*
* @param request the HttpServletRequest to check
- * @return if the servlet mapping matches and is not the tomcat DefaultServlet
+ * @return true if the servlet request is mapped to the tomcat default servlet
*/
- private boolean nonDefaultServletMatches(final HttpServletRequest request) {
+ private boolean defaultServletMatched(final HttpServletRequest request) {
ServletRegistration servletRegistration = request.getServletContext().getServletRegistration(
request.getHttpServletMapping().getServletName());
- return !"org.apache.catalina.servlets.DefaultServlet".equals(servletRegistration.getClassName());
+ return "default".equals(servletRegistration.getName());
}
@Override