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