MEECROWAVE-172 ensure apps can use RequestDispatcher
git-svn-id: https://svn.apache.org/repos/asf/openwebbeans/meecrowave/trunk@1850569 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/integration-tests/dispatch-jsp/pom.xml b/integration-tests/dispatch-jsp/pom.xml
new file mode 100644
index 0000000..e39b1e5
--- /dev/null
+++ b/integration-tests/dispatch-jsp/pom.xml
@@ -0,0 +1,54 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>integration-tests</artifactId>
+ <groupId>org.apache.meecrowave</groupId>
+ <version>1.2.5-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dispatch-jsp</artifactId>
+ <name>Meecrowave :: Integration Tests :: JSP Dispatch</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.meecrowave</groupId>
+ <artifactId>meecrowave-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-jasper</artifactId>
+ <version>${tomcat.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpoint.java b/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpoint.java
new file mode 100644
index 0000000..2191113
--- /dev/null
+++ b/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpoint.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.meecrowave.it.jsp.dispatch;
+
+import static org.apache.meecrowave.it.jsp.dispatch.Model.view;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("dispatch")
+@ApplicationScoped
+public class DispatchEndpoint {
+ @GET
+ @Produces(MediaType.TEXT_HTML)
+ public Model get() {
+ return view("/WEB-INF/dispatch.jsp")
+ .set("title", "Endpoint");
+ }
+}
diff --git a/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/Model.java b/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/Model.java
new file mode 100644
index 0000000..fc2431e
--- /dev/null
+++ b/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/Model.java
@@ -0,0 +1,46 @@
+/*
+ * 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.meecrowave.it.jsp.dispatch;
+
+import static java.util.Collections.unmodifiableMap;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Model {
+ final String path;
+ final Map<String, Object> data = new HashMap<>();
+
+ private Model(final String path) {
+ this.path = path;
+ }
+
+ public Model set(final String name, final Object data) {
+ this.data.put(name, data);
+ return this;
+ }
+
+ public Map<String, Object> getData() {
+ return unmodifiableMap(data);
+ }
+
+ public static Model view(final String path) {
+ return new Model(path);
+ }
+}
diff --git a/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/ModelRenderer.java b/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/ModelRenderer.java
new file mode 100644
index 0000000..b9a5fac
--- /dev/null
+++ b/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/ModelRenderer.java
@@ -0,0 +1,68 @@
+/*
+ * 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.meecrowave.it.jsp.dispatch;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.enterprise.context.Dependent;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.InternalServerErrorException;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+@Dependent
+@Produces(MediaType.TEXT_HTML)
+public class ModelRenderer implements MessageBodyWriter<Model> {
+ @Context
+ private HttpServletRequest request;
+
+ @Context
+ private HttpServletResponse response;
+
+ @Override
+ public boolean isWriteable(final Class<?> type, final Type genericType,
+ final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type == Model.class;
+ }
+
+ @Override
+ public void writeTo(final Model model, Class<?> type,
+ final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders,
+ final OutputStream entityStream) throws WebApplicationException, IOException {
+ model.data.forEach(request::setAttribute);
+ try {
+ request.getRequestDispatcher(model.path).forward(request, response);
+ } catch (final ServletException e) {
+ throw new InternalServerErrorException(e.getMessage(), e);
+ }
+ }
+}
diff --git a/integration-tests/dispatch-jsp/src/main/resources/META-INF/resources/WEB-INF/dispatch.jsp b/integration-tests/dispatch-jsp/src/main/resources/META-INF/resources/WEB-INF/dispatch.jsp
new file mode 100644
index 0000000..c624fa3
--- /dev/null
+++ b/integration-tests/dispatch-jsp/src/main/resources/META-INF/resources/WEB-INF/dispatch.jsp
@@ -0,0 +1,31 @@
+<%
+/*
+ * 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.
+ */
+%>
+<%@ page language="java" pageEncoding="UTF-8" session="false"%>
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Meecrowave :: IT :: Dispatch</title>
+</head>
+<body>
+ <h2><%= request.getAttribute("title") %></h2>
+</body>
+</html>
diff --git a/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpointTest.java b/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpointTest.java
new file mode 100644
index 0000000..4a85ea8
--- /dev/null
+++ b/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpointTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.meecrowave.it.jsp.dispatch;
+
+import static javax.ws.rs.core.MediaType.TEXT_HTML_TYPE;
+import static org.junit.Assert.assertEquals;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+
+import org.apache.meecrowave.Meecrowave;
+import org.junit.Test;
+
+public class DispatchEndpointTest {
+ @Test
+ public void dispatch() {
+ final Client client = ClientBuilder.newClient();
+ try (final Meecrowave container = new Meecrowave(new Meecrowave.Builder()
+ .randomHttpPort()
+ .includePackages("org.apache.meecrowave.it.jsp.dispatch"))
+ .bake()) {
+ final String html = client.target("http://localhost:" + container.getConfiguration().getHttpPort())
+ .path("dispatch")
+ .request(TEXT_HTML_TYPE)
+ .get(String.class);
+ assertEquals("\n\n" +
+ "<!DOCTYPE html>\n" +
+ "<html>\n<head>\n<meta charset=\"utf-8\">\n" +
+ "<title>Meecrowave :: IT :: Dispatch</title>\n" +
+ "</head>\n<body>\n" +
+ " <h2>Endpoint</h2>\n" +
+ "</body>\n</html>\n", html);
+ } finally {
+ client.close();
+ }
+ }
+}
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 7a99027..56fae14 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -43,6 +43,7 @@
<module>ssl</module>
<module>sse</module>
<module>no-cxf</module>
+ <module>dispatch-jsp</module>
</modules>
<build>
diff --git a/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java b/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
index 96e773d..6b2a3ff 100644
--- a/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
+++ b/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
@@ -159,8 +159,8 @@
}
@Provider
- @Produces({MediaType.APPLICATION_JSON, "*/*+json"})
- @Consumes({MediaType.APPLICATION_JSON, "*/*+json"})
+ @Produces({MediaType.APPLICATION_JSON, "application/*+json"})
+ @Consumes({MediaType.APPLICATION_JSON, "application/*+json"})
public static class ConfiguredJsonbJaxrsProvider<T> extends JsonbJaxrsProvider<T> {
private final Jsonb jsonb;
diff --git a/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java b/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java
index f03e326..f1477d5 100644
--- a/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java
+++ b/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java
@@ -140,7 +140,7 @@
}
});
jaxrs.setAsyncSupported(true);
- jaxrs.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, builder.getJaxrsMapping());
+ jaxrs.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC), true, builder.getJaxrsMapping());
ofNullable(builder.getCxfServletParams()).ifPresent(m -> m.forEach(jaxrs::setInitParameter));
}
diff --git a/meecrowave-core/src/test/java/org/apache/meecrowave/AsyncTest.java b/meecrowave-core/src/test/java/org/apache/meecrowave/AsyncTest.java
new file mode 100644
index 0000000..cf7fead
--- /dev/null
+++ b/meecrowave-core/src/test/java/org/apache/meecrowave/AsyncTest.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.meecrowave;
+
+import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
+import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
+import static org.junit.Assert.assertEquals;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+
+import org.junit.Test;
+
+public class AsyncTest {
+ @Test
+ public void inject() {
+ try (final Meecrowave meecrowave = new Meecrowave(
+ new Meecrowave.Builder()
+ .randomHttpPort()
+ .includePackages(AsyncTest.class.getName())).bake()) {
+ final Client client = ClientBuilder.newClient();
+ try {
+ assertEquals("asynced", client.target("http://localhost:" + meecrowave.getConfiguration().getHttpPort())
+ .path("AsyncTest/Async")
+ .request(TEXT_PLAIN_TYPE)
+ .get(String.class));
+ } finally {
+ client.close();
+ }
+ }
+ }
+
+ @Path("AsyncTest/Async")
+ @ApplicationScoped
+ public static class Async {
+ @GET
+ @Produces(TEXT_PLAIN)
+ public void get(@Suspended final AsyncResponse response) {
+ new Thread(() -> response.resume("asynced")).start();
+ }
+ }
+}