users@jersey.java.net

[Jersey] Re: Jersey nonblocking client issue

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Thu, 03 Nov 2011 17:11:05 +0100

it is valid issue.

I've just confirmed that it works with plain Client implementation and
doesn't work with NonBlockingClient. Can you please file an issue?
http://java.net/jira/browse/JERSEY

Thanks,
Pavel

On 11/3/11 5:00 PM, Chris Berry wrote:
> I think I understand why we are seeing it and your test is not.
> If we change the test to what I have here --- it will fail.
> Using the Non-blocking client for an AsyncWebResource instead of a
> synchronous WebResource.
>
> Perhaps I'm doing something wrong though.
>
> Thanks again for your time,
> Cheers,
> -- Chris
>
> @Test
> public void testClientFilter() throws Exception {
> final List<Object> l = new ArrayList<Object>();
>
> Assert.assertTrue(l.size() == 0);
>
> NonBlockingClient c = NonBlockingClient.create();
> c.addFilter(new ClientFilter() {
> @Override
> public ClientResponse handle(ClientRequest cr) throws
> ClientHandlerException {
> l.add(new String("before"));
> final ClientResponse clientResponse =
> getNext().handle(cr);
> l.add(new String("after"));
> return clientResponse;
> }
> });
>
> WebResource r1 = c.resource("http://api-listings-test/");
> String stuff = r1.get(String.class);
> Assert.assertTrue(l.size() == 2);
>
> l.clear();
> Assert.assertTrue(l.size() == 0);
>
> AsyncWebResource r2 =
> c.asyncResource("http://api-listings-test/");
> Future<String> future = r2.get(String.class);
> stuff = future.get();
> Assert.assertTrue(l.size() == 2);
> }
>
> On 11/3/11 10:14 AM, "Chris Berry" <cberry_at_homeaway.com> wrote:
>
> It may be how we are using it?
> I don't see it working, and will investigate further.
>
> Thanks so much again for your help.
>
> On 11/3/11 10:09 AM, "Pavel Bucek" <pavel.bucek_at_oracle.com> wrote:
>
> I already replied privately, but..
>
> following testcase passes:
>
> final List<Object> l = new ArrayList<Object>();
>
> assertTrue(l.size() == 0);
>
> NonBlockingClient c = NonBlockingClient.create();
> c.addFilter(new ClientFilter() {
> @Override
> public ClientResponse handle(ClientRequest cr)
> throws ClientHandlerException {
> l.add(new String("before"));
> final ClientResponse clientResponse =
> getNext().handle(cr);
> l.add(new String("after"));
>
> return clientResponse;
> }
> });
>
> WebResource r = c.resource(getUri().path("/").build());
> r.get(String.class);
>
> assertTrue(l.size() == 2);
>
> can you share IWasHereFilter filter implementation?
>
> Regards,
> Pavel
>
> On 11/3/11 4:00 PM, Chris Berry wrote:
>
> Re: Jersey nonblocking client issue Sorry, but it is NOT
> fixed in 1.10.
> Let me know if you cannot reproduce --- and I could
> probably create a simple test case for you.
>
> It is easy to see it not working.
> Just create the non-blocking client --- and drop a
> ClientFilter into it that, say, just logs "I was here"
> And you'll never see the log...
>
> client.addFilter(new IWasHereFilter());
>
> To users_at_jersey.java.net,
> FYI; This is an email thread that began as a private
> thread, but was moved here for posterity....
>
> Thanks,
> -- Chris
>
> On 11/3/11 9:09 AM, "Chris Berry" <cberry_at_homeaway.com>
> wrote:
>
>
> Thank you so much.
> Perhaps it will "just work" if I try the latest/greatest.
> I will and let you know.
>
> There is not much info in Google on the non-blocking
> client.
> And I didn't find the 1.10. Sorry.
>
> Would you like me to transcribe this thread to
> jersey-users (or whatever that list is named)??
>
> Thank you again fro responding!
> Cheers,
> -- Chris
>
> On 11/3/11 9:03 AM, "Pavel Bucek"
> <pavel.bucek_at_oracle.com> wrote:
>
>
> Hi Chris,
>
> ad ClientFilter issue - it should work. We do
> have some tests related to this area, but I'm
> going to investigate and maybe will commit it back
> to the source repository; I'll update you with
> what I find.
>
> ad moving from experimental - that was done some
> time ago, its in contribs now and its part of
> stable releases since 1.9 I guess..
>
> <groupId>com.sun.jersey.contribs</groupId>
> <artifactId>jersey-non-blocking-client</artifactId>
> <version>1.10</version>
>
> ^^ that should work for you.
>
> I don't have any problem with you contacting me
> directly, but this doesn't seem to be private, so
> it could be posted on our user list - others might
> benefit from our conversation too.
>
> Regards,
> Pavel
>
> On 11/2/11 9:30 PM, Chris Berry wrote:
>
> Jersey nonblocking client issue Hello Pavel,
> Your blog said to contact you directly over
> your new Jersy NonBlockingHttpClient --- I
> hope that it is not too presumptuous --- but I
> have done so...
>
> First -- Long story short, I have been
> experimenting with your NonBlockingClient.
> I am very excited to use it. It is exactly
> what we all need !!
> But it does not appear to be honoring
> ClientFilters --- which we use often.
>
> We configure it using the code shown below.
> (A client is initialized once by Spring as a
> singleton)
> And my ClientFilters are never invoked.
>
> I think this is a bug??
>
> Second --- do you have any estimate when the
> project will move from /experimental?? (That
> word scares people ;-)
> And any estimate when it will become a
> Non-SNAPSHOT??
>
> Again sorry to bother you...
>
> Thanks,
> -- Chris
>
>
>
> protected void initClient() {
> if (client == null) {
> // For many properties, we
> must configure them BEFORE we create the
> Client
> // In particular, the
> Executor for Async
> ClientConfig clientConfig;
> if (nonblocking) {
> clientConfig = new
> DefaultNonBlockingClientConfig();
> } else {
> clientConfig = new
> DefaultClientConfig();
> }
> clientConfig.getProperties().put(ClientConfig.PROPERTY_THREADPOOL_SIZE,
> threadPoolSize);
> clientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT,
> connectTimeout);
> clientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT,
> readTimeout);
>
> if (async && nonblocking) {
> client =
> NonBlockingClient.create(clientConfig);
> } else {
> client =
> Client.create(clientConfig);
> }
> }
>
> // inject perf4j stats if not
> present
> if
> (!hasPerfFilter(getClientFilters()) &&
> !hasPerfFilter(filtersToAdd)) {
> client.addFilter(new
> Perf4jFilter(getServiceName()));
> }
>
> // add our filters to the client
> for (ClientFilter filter :
> filtersToAdd) {
> client.addFilter(filter);
> }
>
> if (log.isDebugEnabled()) {
> log.debug(getServiceName() +
> ": Initialized Client: " + client + " with
> filters: " + getFilterChain());
> }
> }
>
>
>
>
>
>
>
>
>
>
>
>
>