Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8873C18A5F for ; Mon, 22 Feb 2016 16:57:16 +0000 (UTC) Received: (qmail 26528 invoked by uid 500); 22 Feb 2016 16:57:16 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 26475 invoked by uid 500); 22 Feb 2016 16:57:16 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 26465 invoked by uid 99); 22 Feb 2016 16:57:16 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Feb 2016 16:57:16 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EE304E0362; Mon, 22 Feb 2016 16:57:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: <13219cd20d614164b942b6b620037698@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: [CXF-6793] Adding a test Date: Mon, 22 Feb 2016 16:57:15 +0000 (UTC) Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 44a5876d4 -> dd1fe4ed3 [CXF-6793] Adding a test Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/dd1fe4ed Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/dd1fe4ed Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/dd1fe4ed Branch: refs/heads/3.0.x-fixes Commit: dd1fe4ed3fcae1d106b439a84db7a02529d25ef8 Parents: 44a5876 Author: Sergey Beryozkin Authored: Mon Feb 22 14:07:43 2016 +0000 Committer: Sergey Beryozkin Committed: Mon Feb 22 16:56:57 2016 +0000 ---------------------------------------------------------------------- .../systest/jaxrs/BookServerAsyncClient.java | 58 +++++++++++++++++++- .../org/apache/cxf/systest/jaxrs/BookStore.java | 2 +- .../cxf/systest/jaxrs/JAXRSAsyncClientTest.java | 36 ++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/dd1fe4ed/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java index f3d7b62..71ba304 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServerAsyncClient.java @@ -19,8 +19,23 @@ package org.apache.cxf.systest.jaxrs; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.MessageBodyWriter; + import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; +import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; import org.apache.cxf.testutil.common.AbstractBusTestServerBase; @@ -39,7 +54,7 @@ public class BookServerAsyncClient extends AbstractBusTestServerBase { sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true)); sf.setAddress("http://localhost:" + PORT + "/"); - + sf.setProvider(new BooleanReaderWriter()); sf.getProperties(true).put("default.content.type", "*/*"); server = sf.create(); BusFactory.setDefaultBus(null); @@ -63,4 +78,45 @@ public class BookServerAsyncClient extends AbstractBusTestServerBase { System.out.println("done!"); } } + + @Consumes("text/boolean") + @Produces("text/boolean") + public static class BooleanReaderWriter implements + MessageBodyReader, MessageBodyWriter { + + @Override + public boolean isReadable(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3) { + return true; + } + + @Override + public Object readFrom(Class arg0, Type arg1, Annotation[] arg2, MediaType arg3, + MultivaluedMap arg4, InputStream is) throws IOException, + WebApplicationException { + return Boolean.valueOf(IOUtils.readStringFromStream(is)); + } + + @Override + public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, + MediaType mediaType) { + return true; + } + + @Override + public long getSize(Boolean t, Class type, Type genericType, Annotation[] annotations, + MediaType mediaType) { + return -1; + } + + @Override + public void writeTo(Boolean t, Class type, Type genericType, Annotation[] annotations, + MediaType mediaType, MultivaluedMap httpHeaders, + OutputStream os) throws IOException, WebApplicationException { + byte[] bytes = t.toString().getBytes("UTF-8"); + os.write(bytes); + + } + + + } } http://git-wip-us.apache.org/repos/asf/cxf/blob/dd1fe4ed/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java index 60a7341..75ed5d3 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java @@ -540,7 +540,7 @@ public class BookStore { @GET @Path("books/check/{id}") - @Produces("text/plain") + @Produces("text/plain,text/boolean") public boolean checkBook(@PathParam("id") Long id) { return books.containsKey(id); } http://git-wip-us.apache.org/repos/asf/cxf/blob/dd1fe4ed/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java index d400bce..53e982c 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientTest.java @@ -254,6 +254,22 @@ public class JAXRSAsyncClientTest extends AbstractBusClientServerTestBase { } @Test + public void testGenericInvocationCallback() throws Exception { + InvocationCallback callback = createGenericInvocationCallback(); + String address = "http://localhost:" + PORT + "/bookstore/books/check/123"; + Future f = ClientBuilder.newBuilder().register(new BookServerAsyncClient.BooleanReaderWriter()) + .build().target(address) + .request().accept("text/boolean").async().get(callback); + Object o = f.get(); + assertTrue((Boolean)o); + assertTrue(((GenericInvocationCallback)callback).getResult()); + } + + private InvocationCallback createGenericInvocationCallback() { + return new GenericInvocationCallback(); + } + + @Test public void testGetBookAsync404Callback() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404"; WebClient wc = createWebClient(address); @@ -325,6 +341,7 @@ public class JAXRSAsyncClientTest extends AbstractBusClientServerTestBase { } + public static class TestResponseFilter implements ClientResponseFilter { @Override @@ -335,4 +352,23 @@ public class JAXRSAsyncClientTest extends AbstractBusClientServerTestBase { } } + private static class GenericInvocationCallback implements InvocationCallback { + private Object result; + + @Override + public void completed(final Object o) { + result = o; + } + + @Override + public void failed(final Throwable throwable) { + // complete + } + + public Boolean getResult() { + return (Boolean)result; + } + + + } }