Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 65068200CB9 for ; Sun, 2 Jul 2017 16:47:03 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 633FA160BFE; Sun, 2 Jul 2017 14:47:03 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 83970160BD7 for ; Sun, 2 Jul 2017 16:47:02 +0200 (CEST) Received: (qmail 51744 invoked by uid 500); 2 Jul 2017 14:47:01 -0000 Mailing-List: contact commits-help@openwebbeans.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwebbeans.apache.org Delivered-To: mailing list commits@openwebbeans.apache.org Received: (qmail 51733 invoked by uid 99); 2 Jul 2017 14:47:01 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Jul 2017 14:47:01 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 8B4C13A0611 for ; Sun, 2 Jul 2017 14:47:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1800565 - /openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java Date: Sun, 02 Jul 2017 14:46:59 -0000 To: commits@openwebbeans.apache.org From: rmannibucau@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170702144700.8B4C13A0611@svn01-us-west.apache.org> archived-at: Sun, 02 Jul 2017 14:47:03 -0000 Author: rmannibucau Date: Sun Jul 2 14:46:58 2017 New Revision: 1800565 URL: http://svn.apache.org/viewvc?rev=1800565&view=rev Log: adding OctectStreamMediaTypeTest for Mark Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java - copied, changed from r1800462, openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/ContextInProxiedInstancesTest.java Copied: openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java (from r1800462, openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/ContextInProxiedInstancesTest.java) URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java?p2=openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java&p1=openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/ContextInProxiedInstancesTest.java&r1=1800462&r2=1800565&rev=1800565&view=diff ============================================================================== --- openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/ContextInProxiedInstancesTest.java (original) +++ openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/OctectStreamMediaTypeTest.java Sun Jul 2 14:46:58 2017 @@ -22,80 +22,75 @@ import org.apache.tomcat.util.http.fileu import org.junit.Test; import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.context.Dependent; -import javax.enterprise.context.Initialized; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Observes; -import javax.enterprise.inject.spi.CDI; -import javax.servlet.ServletContext; import javax.ws.rs.GET; import javax.ws.rs.Path; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.UriInfo; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.StreamingOutput; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.charset.StandardCharsets; import static org.junit.Assert.assertEquals; -public class ContextInProxiedInstancesTest { +public class OctectStreamMediaTypeTest { @Test public void fields() throws IOException { try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder() .randomHttpPort() - .includePackages(ContextInProxiedInstancesTest.class.getName())).bake()) { - // proxies can use @Context - try (final InputStream stream = new URL("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/app").openStream()) { - assertEquals("app", Streams.asString(stream, "UTF-8")); + .includePackages(OctectStreamMediaTypeTest.class.getName())).bake()) { + try (final InputStream stream = new URL( + "http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/OctectStreamMediaTypeTest/response").openStream()) { + assertEquals("resp", Streams.asString(stream, "UTF-8")); } - try (final InputStream stream = new URL("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/req").openStream()) { - assertEquals("req", Streams.asString(stream, "UTF-8")); + try (final InputStream stream = new URL( + "http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/OctectStreamMediaTypeTest/streaming").openStream()) { + assertEquals("stream", Streams.asString(stream, "UTF-8")); } - // not proxied can also - try (final InputStream stream = new URL("http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/dep").openStream()) { - assertEquals("dep", Streams.asString(stream, "UTF-8")); + try (final InputStream stream = new URL( + "http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/OctectStreamMediaTypeTest/string").openStream()) { + assertEquals("string", Streams.asString(stream, "UTF-8")); } - assertEquals(Dep.class, CDI.current().select(Dep.class).get().getClass()); // ensure it is not proxied but injection works (thanks CXF) + /* too ambiguous to have it working, you can add it in ignored list of johnzon provider if you want to handle it particularly + try (final InputStream stream = new URL( + "http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/OctectStreamMediaTypeTest/bytes").openStream()) { + assertEquals("bytes", Streams.asString(stream, "UTF-8")); + } + */ } } - @Path("app") + @Path("OctectStreamMediaTypeTest") @ApplicationScoped public static class App { - @Context - private UriInfo uri; - - public void init(@Observes @Initialized(ApplicationScoped.class) final ServletContext sc) { - // init without a Message + @GET + @Path("response") + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public Response getResponse() { + return Response.ok("resp").build(); } @GET - public String get() { - return uri.getPath(); + @Path("streaming") + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public StreamingOutput getStreamingOutput() { + return output -> output.write("stream".getBytes(StandardCharsets.UTF_8)); } - } - - @Path("req") - @RequestScoped - public static class Req { - @Context - private UriInfo uri; @GET - public String get() { - return uri.getPath(); + @Path("string") + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public String getString() { + return "string"; } - } - - @Path("dep") - @Dependent - public static class Dep { - @Context - private UriInfo uri; @GET - public String get() { - return uri.getPath(); + @Path("bytes") + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public byte[] getBytes() { + return "bytes".getBytes(StandardCharsets.UTF_8); } } }