users@jersey.java.net

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

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 07 Sep 2009 19:56:01 +0200

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
>