You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Alejandro Vilar <al...@synacom.com.bo> on 2010/04/27 16:23:16 UTC

Web queries (No content response)

Hi, I have a query for a rest server which response code is 204, but I have
an exception while the response is processed in this section:

 

Class: org.apache.pivot.web.Query

 

           // Read the response body

            if (method == Method.GET) {

                InputStream inputStream = null;

                try {

                    inputStream = connection.getInputStream();

                    value = serializer.readObject(new
MonitoredInputStream(inputStream));//ßexception

                } finally {

                    if (inputStream != null) {

                        inputStream.close();

                    }

                }

            }

And that's because I get a response without content, any way the above code
is trying to read the response body and getting the serialized content, as
the response code description says "there is no content" maybe this process
should be avoided. I can fix it using a empty serializer, but maybe it would
be useful a method such as Query.doNotProcessResponseBody(), or a switch for
each type of response code or do not read the content until is required(some
kind of cache(?)).

 

What you think?

 

Regards,

Alejandro

 

 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.5> HTTP RFC
- 10.2.5 204 No Content 

 


RE: Web queries (No content response)

Posted by Alejandro Vilar <al...@synacom.com.bo>.
Hi Greg,

 

In the middle I’m searching for a better response code, currently I’m using
only response codes to know the server’s service status for example:

Get: servername:port/status

If service is unavailable could use
<http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.4> HTTP RFC
- 10.5.4 503 Service Unavailable response code and if it is ok return
success with no content.

 

Maybe I could return a response with content body “unavailable/available”,
but I think use only response codes is useful instead of push content that
is irrelevant (in this case).

 

Cheers,

Alejandro

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Martes, 27 de Abril de 2010 11:01 a.m.
To: user@pivot.apache.org
Subject: Re: Web queries (No content response)

 

FYI, I just checked in a check for HTTP 200, so your code should run OK now.
But I'm still curious to know - what is the use case for returning no
content from a GET? I suppose you could be returning response headers only,
but that seems pretty esoteric...

 

 

On Apr 27, 2010, at 10:57 AM, Greg Brown wrote:





It seems odd that a GET request wouldn't return any content. We could check
for a 200 response before reading from the input stream, but maybe a
different HTTP method would be more appropriate?

 

 

On Apr 27, 2010, at 10:23 AM, Alejandro Vilar wrote:





Hi, I have a query for a rest server which response code is 204, but I have
an exception while the response is processed in this section:

 

Class: org.apache.pivot.web.Query

 

           // Read the response body

            if (method == Method.GET) {

                InputStream inputStream = null;

                try {

                    inputStream = connection.getInputStream();

                    value = serializer.readObject(new
MonitoredInputStream(inputStream));//ßexception

                } finally {

                    if (inputStream != null) {

                        inputStream.close();

                    }

                }

            }

And that's because I get a response without content, any way the above code
is trying to read the response body and getting the serialized content, as
the response code description says "there is no content" maybe this process
should be avoided. I can fix it using a empty serializer, but maybe it would
be useful a method such asQuery.doNotProcessResponseBody(), or a switch for
each type of response code or do not read the content until is required(some
kind of cache(?)).

 

What you think?

 

Regards,

Alejandro

 

 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.5> HTTP RFC
- 10.2.5 204 No Content

 

 

 


Re: Web queries (No content response)

Posted by Greg Brown <gk...@mac.com>.
FYI, I just checked in a check for HTTP 200, so your code should run OK now. But I'm still curious to know - what is the use case for returning no content from a GET? I suppose you could be returning response headers only, but that seems pretty esoteric...


On Apr 27, 2010, at 10:57 AM, Greg Brown wrote:

> It seems odd that a GET request wouldn't return any content. We could check for a 200 response before reading from the input stream, but maybe a different HTTP method would be more appropriate?
> 
> 
> On Apr 27, 2010, at 10:23 AM, Alejandro Vilar wrote:
> 
>> Hi, I have a query for a rest server which response code is 204, but I have an exception while the response is processed in this section:
>>  
>> Class: org.apache.pivot.web.Query
>>  
>>            // Read the response body
>>             if (method == Method.GET) {
>>                 InputStream inputStream = null;
>>                 try {
>>                     inputStream = connection.getInputStream();
>>                     value = serializer.readObject(new MonitoredInputStream(inputStream));//ßexception
>>                 } finally {
>>                     if (inputStream != null) {
>>                         inputStream.close();
>>                     }
>>                 }
>>             }
>> And that's because I get a response without content, any way the above code is trying to read the response body and getting the serialized content, as the response code description says "there is no content" maybe this process should be avoided. I can fix it using a empty serializer, but maybe it would be useful a method such asQuery.doNotProcessResponseBody(), or a switch for each type of response code or do not read the content until is required(some kind of cache(?)).
>>  
>> What you think?
>>  
>> Regards,
>> Alejandro
>>  
>> HTTP RFC - 10.2.5 204 No Content
>>  
> 


Re: Web queries (No content response)

Posted by Greg Brown <gk...@mac.com>.
It seems odd that a GET request wouldn't return any content. We could check for a 200 response before reading from the input stream, but maybe a different HTTP method would be more appropriate?


On Apr 27, 2010, at 10:23 AM, Alejandro Vilar wrote:

> Hi, I have a query for a rest server which response code is 204, but I have an exception while the response is processed in this section:
>  
> Class: org.apache.pivot.web.Query
>  
>            // Read the response body
>             if (method == Method.GET) {
>                 InputStream inputStream = null;
>                 try {
>                     inputStream = connection.getInputStream();
>                     value = serializer.readObject(new MonitoredInputStream(inputStream));//ßexception
>                 } finally {
>                     if (inputStream != null) {
>                         inputStream.close();
>                     }
>                 }
>             }
> And that's because I get a response without content, any way the above code is trying to read the response body and getting the serialized content, as the response code description says "there is no content" maybe this process should be avoided. I can fix it using a empty serializer, but maybe it would be useful a method such asQuery.doNotProcessResponseBody(), or a switch for each type of response code or do not read the content until is required(some kind of cache(?)).
>  
> What you think?
>  
> Regards,
> Alejandro
>  
> HTTP RFC - 10.2.5 204 No Content
>