On Sep 7, 2009, at 6:34 PM, Morten wrote:
> You have to call close otherwise you get hangs as you reported. I
> have reported a bug about this to get an exception instead but it is
> a difficult fix.
>
It is not necessary to close anything for such use of the Client API.
It is only necessary to close when ClientResponse is returned or a
type is an instance of Closeable.
Paul.
> /Morten
>
> --- Den man 7/9/09 skrev Markus KARG <markus.karg_at_gmx.net>:
>
>> Fra: Markus KARG <markus.karg_at_gmx.net>
>> Emne: [Jersey] Getting nuts with hangs in Client API
>> Til: users_at_jersey.dev.java.net
>> Dato: mandag 7. september 2009 18.15
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> 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
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
> Trænger du til at se det store billede? Kelkoo giver dig gode
> tilbud på LCD TV! Se her http://dk.yahoo.com/r/pat/lcd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>