users@jersey.java.net

RE: [Jersey] Getting nuts with hangs in Client API

From: Markus KARG <markus.karg_at_gmx.net>
Date: Tue, 8 Sep 2009 09:48:21 +0200

Paul,

 

thank you for your tips and have nice holidays! Just came back from a great
short trip to Vienna, so if you don't know where to go to. ;-)

 

The idea with a 10 minutes sleep didn't help. :-(

 

Changing to Grizzly works well (but one really must give the package to scan
or Jersey will tell you that
"C:\C:\jersey-archive-1.0.3.1\lib\jsr311-api-1.0.jar, is not a jar file")!
:-)

 

So I assume that there is a bug in the http server used internally by
Jersey, and there is a bug in Jersey's ClassPath scanner (it seems to add
another C:\ to each JAR if not giving a package to scan).

 

For my presentation, this should work. But maybe you like to have a look
into the the above items after your holidays? :-)

 

Have lots of fun!

Markus

 

From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
Sent: Montag, 7. September 2009 19:56
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] Getting nuts with hangs in Client API
Importance: High

 

Hi Markus,

 

I think it might be because you are returning from the main method after the
server starts. What happens if you put a big sleep statement after the
server.start() ? e.g. sleep for 10 mins or so?

 

Alternatively you could switch to using Grizzly instead:

 

 
https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey/com/sun/jersey/api
/container/grizzly/GrizzlyServerFactory.html

 

https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.
3.1/jersey/getting-started.html

 

Notice the System.in statement used with Grizzly. However, i believe this
can cause issues on windows, so i recommend a really long sleep after wards
:-)

 

Hope this helps,

Paul.

 

On Sep 7, 2009, at 6:15 PM, Markus KARG wrote:





Please help me, I have to do a presentation on Jersey Client API but the
demo program just hangs all the time! ;-(

 

Server looks like this:

 

@Path("/RsChatroom")

public class JaxRsChat {

      private static volatile String content = "";

      @POST

      public void publish(String text) {

            content = content + '\n' + text;

      }

      @GET

      public String getContent() {

            return content;

      }

}

 

public class JaxRsChatContainer {

      public static void main(String[] arguments) throws IOException {

            HttpServer server =
HttpServerFactory.create("http://localhost:80/ADV/");

            server.start();

      }

}

 

Client looks like this:

 

public static void main(String[] arguments) throws InterruptedException {

      Client client = Client.create();

      WebResource resource =
client.resource("http://localhost:80/ADV/RsChatroom");

      while (true) {

            System.out.println(resource.get(String.class));

            resource.post(new Date().toString()); // Later will use user
input instead.

      }

}

 

Looks rather simple, but actually hangs at resource.get IN THE SECOND TURN!
If I comment out either resource.get() or resource.post(), then it correctly
runs endless.

 

But as soon as there was a single resource.post(), the subsequent
resource.get() HANGS. I was trying for hours, and do not see a solution.
Sometimes, it also runs a few times, and then says this:

 

Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException:
java.net.BindException: Address already in use: connect

 

Can anybody tell me how to fix that? My OS is Windows XP Home and Java is
JDK 1.6.0_16. Jersey is 1.0.3.1. I am rather desparate since I have to do a
presentation about the Client API next week and currently JUST NOTHING
WORKS. ;-( With cURL everything works pretty fine. Strange!

 

I don't believe that it is a bug in the client API since I tried using
HttpURLConnection instead of Client API and experienced the same problem
(waiting endless in Socket reading internally in the JRE).

 

Please help me! :-)

 

Thanks

Markus