openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1850569 - in /openwebbeans/meecrowave/trunk: integration-tests/ integration-tests/dispatch-jsp/ integration-tests/dispatch-jsp/src/ integration-tests/dispatch-jsp/src/main/ integration-tests/dispatch-jsp/src/main/java/ integration-tests/di...
Date Sun, 06 Jan 2019 17:06:15 GMT
Author: rmannibucau
Date: Sun Jan  6 17:06:14 2019
New Revision: 1850569

URL: http://svn.apache.org/viewvc?rev=1850569&view=rev
Log:
MEECROWAVE-172 ensure apps can use RequestDispatcher

Added:
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/pom.xml
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpoint.java
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/Model.java
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/ModelRenderer.java
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/resources/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/resources/META-INF/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/resources/META-INF/resources/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/resources/META-INF/resources/WEB-INF/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/resources/META-INF/resources/WEB-INF/dispatch.jsp
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/org/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/org/apache/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/it/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/it/jsp/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/it/jsp/dispatch/
    openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpointTest.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/AsyncTest.java
Modified:
    openwebbeans/meecrowave/trunk/integration-tests/pom.xml
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java

Added: openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/pom.xml?rev=1850569&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/pom.xml (added)
+++ openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/pom.xml Sun Jan  6 17:06:14
2019
@@ -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>

Added: openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpoint.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpoint.java?rev=1850569&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpoint.java
(added)
+++ openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpoint.java
Sun Jan  6 17:06:14 2019
@@ -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");
+    }
+}

Added: openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/Model.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/Model.java?rev=1850569&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/Model.java
(added)
+++ openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/Model.java
Sun Jan  6 17:06:14 2019
@@ -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);
+    }
+}

Added: openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/ModelRenderer.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/ModelRenderer.java?rev=1850569&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/ModelRenderer.java
(added)
+++ openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/java/org/apache/meecrowave/it/jsp/dispatch/ModelRenderer.java
Sun Jan  6 17:06:14 2019
@@ -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);
+        }
+    }
+}

Added: openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/resources/META-INF/resources/WEB-INF/dispatch.jsp
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/resources/META-INF/resources/WEB-INF/dispatch.jsp?rev=1850569&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/resources/META-INF/resources/WEB-INF/dispatch.jsp
(added)
+++ openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/main/resources/META-INF/resources/WEB-INF/dispatch.jsp
Sun Jan  6 17:06:14 2019
@@ -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>

Added: openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpointTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpointTest.java?rev=1850569&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpointTest.java
(added)
+++ openwebbeans/meecrowave/trunk/integration-tests/dispatch-jsp/src/test/java/org/apache/meecrowave/it/jsp/dispatch/DispatchEndpointTest.java
Sun Jan  6 17:06:14 2019
@@ -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();
+        }
+    }
+}

Modified: openwebbeans/meecrowave/trunk/integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/pom.xml?rev=1850569&r1=1850568&r2=1850569&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/pom.xml (original)
+++ openwebbeans/meecrowave/trunk/integration-tests/pom.xml Sun Jan  6 17:06:14 2019
@@ -43,6 +43,7 @@
     <module>ssl</module>
     <module>sse</module>
     <module>no-cxf</module>
+    <module>dispatch-jsp</module>
   </modules>
 
   <build>

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java?rev=1850569&r1=1850568&r2=1850569&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
Sun Jan  6 17:06:14 2019
@@ -159,8 +159,8 @@ public class ConfigurableBus extends Ext
     }
 
     @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;
 

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java?rev=1850569&r1=1850568&r2=1850569&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java
Sun Jan  6 17:06:14 2019
@@ -140,7 +140,7 @@ public class CxfCdiAutoSetup implements
             }
         });
         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));
     }
 

Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/AsyncTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/AsyncTest.java?rev=1850569&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/AsyncTest.java
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/AsyncTest.java
Sun Jan  6 17:06:14 2019
@@ -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();
+        }
+    }
+}



Mime
View raw message