dev@jersey.java.net

Re: [Jersey] HTTP Result Code "-1"

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 18 Dec 2008 16:55:53 +0100

Hi Markus,

-1 is indeed odd. The HttpURLConnection JavaDoc states:

    Returns -1 if no code can be discerned from the response (i.e.,
the response is not valid HTTP).

What standalone server are you using? the LW HTTP server? Is the
server side handling concurrent requests from multiple clients?

My guess is it is more likely to be a bug in the standalone server (or
Jersey's interaction with it).

Do have a restriction that you cannot depend on the Jersey client API?
if not it could make things easier for you.

You could test with curl logging output to try and debug further. If
you are not familiar with curl i can send you an example.

Paul.

On Dec 18, 2008, at 3:56 PM, Markus Karg wrote:

> I am not sure whether this is a bug that should be reported using
> the issue tracker, so before typing in a potentially non-existing
> bug, I'd rather like to ask you whether that is a bug at all... ;-)
>
> I just discovered (Jersey-1.0.1) that sometimes I get a Result Code
> of -1 from the following code:
>
> private final void saveModifiedData(final
> ManufacturedAmountXML producedData) throws IOException,
> JAXBException {
> final HttpURLConnection urlConnection =
> (HttpURLConnection) newURL(String.format("http://%s/quipsy/
> manufacturedAmount/Amount.xml", this.host))
> .openConnection();
> try {
> urlConnection.setDoOutput(true);
> urlConnection.setRequestMethod("PUT");
> final OutputStream outputStream =
> urlConnection.getOutputStream();
> try {
>
> JAXBContext
> .newInstance
> (ManufacturedAmountXML
> .class).createMarshaller().marshal(producedData, outputStream);
>
> System.out.println(urlConnection.getResponseCode());
> } finally {
> outputStream.close();
> }
> } finally {
> urlConnection.disconnect();
> }
> }
>
> when executing it agains a Jersey-1.0.1 standalone server (not
> GlassFish).
>
> The PUT is correctly processed in my JAX-RS resource and the body is
> completely transfered, it is just the response code that is
> "strange". Typically I get a 204 No Content (what is OK) but
> sometimes I get -1.
>
> Is that a bug in Jersey or is it my fault?
>
> Thanks
> Markus
>
> QUIPSY QUALITY GmbH & Co. KG
> Ein Unternehmen der MES-Gruppe
> Stuttgarter Strasse 23
> D-75179 Pforzheim
> Tel: 07231-9189-52
> Fax: 07231-9189-59
> www.quipsy.de
> karg_at_quipsy.de
> Registergericht Mannheim HRA 701214
> Geschäftsführer: Nils Schroeder
>
> Diese E-Mail enthält persönliche, vertrauliche und vor Weitergabe
> geschützte Informationen und ist ausschließlich für den vorgesehenen
> o.g. Empfänger (Adressaten) bestimmt. Falls Sie diese E-Mail
> versehentlich erhalten haben und nicht der vorgesehene Empfänger
> sind, bitten wir Sie, die E-Mail und deren Anhänge nicht
> aufzubewahren, nicht zu vervielfältigen, nicht zu nutzen und nicht
> weiterzugeben. Bitte informieren Sie uns als Absender über diesen
> Zustellungsfehler und löschen Sie die E-Mail.
>
>
> <image001.jpg>
>
> <Markus KARG.vcf>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: dev-help_at_jersey.dev.java.net