You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by "Dr. Stefano Sancese" <st...@sancese.com> on 2011/03/22 20:21:42 UTC
RESTFul
Hi,
I'm developing a RESTFul application using Pivot for the client side.
No problem with the GET, but now I'm working on PUT and I have a question:
What if the PUT can not be complete, for example because there is an
unique key constrain on a field that throws a duplicated error?
In this case I'd like to show to the user why the request can not be
completed and I wolud like to use the respons body for an extended message.
I digged the source and I found this code in
web/src/org/apache/pivot/web/Query.java (the class PutQuery extends) the
following code at line 499:
> // Read the response body
> if (*method == Method.GET*
> && status == Query.Status.OK) {
> InputStream inputStream = null;
> try {
> inputStream = connection.getInputStream();
> value = serializer.readObject(new
> MonitoredInputStream(inputStream));
> } finally {
> if (inputStream != null) {
> inputStream.close();
> }
> }
> }
So it looks like that only for the GET query the response body is read.
From http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10:
>
> 10.4.10 409 Conflict
>
> The request could not be completed due to a conflict with the current
> state of the resource. This code is only allowed in situations where
> it is expected that the user might be able to resolve the conflict and
> resubmit the request. The response body SHOULD include enough
>
> information for the user to recognize the source of the conflict.
> Ideally, the response entity would include enough information for the
> user or user agent to fix the problem; however, that might not be
> possible and is not required.
>
> Conflicts are most likely to occur in response to a PUT request. For
> example, if versioning were being used and the entity being PUT
> included changes to a resource which conflict with those made by an
> earlier (third-party) request, the server might use the 409 response
> to indicate that it can't complete the request. In this case, *the
> response entity *would likely contain a list of the differences
> between the two versions in a format defined by the response
> Content-Type.
>
I infer that, in case of error, the server can send a response.
Am I wrong?
Ciao
Stefano
--
Dr. Stefano Sancese
WatchGuard Certified System Professional - http://www.watchguard.com
Socio Clusit - Associazione Italiana per la Sicurezza Informatica
************************************************************************
In God we trust, all others we monitor (National Security Agency)
************************************************************************
Re: RESTFul
Posted by Greg Brown <gk...@verizon.net>.
> For HTTP 409 the standard recomends to put additional information in the body:
...
> Don't you think is more appropriate to modify the execute method in Query.java to permit the return of the response body for every kind of query and not only for the GET?
Possibly, but my feeling is no. The primary purpose of the web query API is to map the CRUD operations to HTTP in a relatively object-oriented manner:
GET = read
POST = create
PUT = create/update
DELETE = delete
As such, the API is geared towards this definition:
- GetQuery returns the value of an existing resource
- PostQuery creates a new resource and returns a URL
- PutQuery either creates a new resource or updates an existing one
- DeleteQuery deletes an existing resource
The primary distinction between POST and PUT is that, for a POST, the server provides the name of the resource, and for a PUT, the caller provides it. As a result, PostQuery returns a URL representing the location of the new resource, and PutQuery returns a Boolean to indicate whether the operation created or updated the named resource (note that not all implementations will necessarily support both). HTTP headers are used to convey any additional detail about the response.
Hope this helps.
Greg
Re: RESTFul
Posted by Greg Brown <gk...@verizon.net>.
> In fact I think that to have the two side (client a server) too flexible can bring to a total mess with too many option to choose from.
My thoughts exactly. :-)
Re: RESTFul
Posted by "Dr. Stefano Sancese" <st...@sancese.com>.
Il 25/03/2011 15:21, Dr. Stefano Sancese ha scritto:
> Il 25/03/2011 10:56, Sandro Martini ha scritto:
>> Ciao Stefano,
>> if you want in any case to create a ticket for the 2.1 release and
>> put there
>> some info (as soon as you have), just to keep all info in the same
>> place,
>> would be great.
>
> I'll do asap.
<snip>
Ciao Sandro,
I think that Greg was right!
With JAX-RS I can forge any kind of response and parse any kind of
request, so also if Pivot is more stringent, that's not a problem.
In fact I think that to have the two side (client a server) too flexible
can bring to a total mess with too many option to choose from.
Stefano
--
Dr. Stefano Sancese
WatchGuard Certified System Professional - http://www.watchguard.com
Socio Clusit - Associazione Italiana per la Sicurezza Informatica
************************************************************************
In God we trust, all others we monitor (National Security Agency)
************************************************************************
Re: RESTFul
Posted by "Dr. Stefano Sancese" <st...@sancese.com>.
Il 25/03/2011 10:56, Sandro Martini ha scritto:
> Ciao Stefano,
> if you want in any case to create a ticket for the 2.1 release and put there
> some info (as soon as you have), just to keep all info in the same place,
> would be great.
>
I'll do asap.
> But I'm sorry, I can't assure that your proposed changes will be accepted in
> core Pivot, sorry ...
>
Of course.
> I have very little experience in REST queries, but for what I've seen there
> are many frameworks REST-compatible but all working in different ways (at
> least for small differences), but I agree with you that JAX-RS is the
> default implementation, so maybe we could try to see how to plug-in it in
> Pivot.
> For example in a plug-in way like we done for JFreeChart: common interfaces
> in Pivot, and pluggable implementation in a Pivot-related project for
> example.
> But in any case, if you find some problem extending Pivot classes tell to
> us (in last weeks we removed some final methods from a user request), and
> let's see what we can do.
>
Thanks, for now I'm extending the pivot classes overriding the methods I
need to change.
> Then, if you want to share some code with us, you can attach it in JIRA
> (inside a zip), or if you are interested, I can give you some grant in one
> of others Pivot-related projects, like pivot-stuff.
>
>
> Thank you very much for your feedback.
>
> If you want to contact me privately (my address is in Pivot Web pages, and
> even in this mailing list) I'll be happy to help, if/for what I can :-) .
>
Grazie Sandro
Stafano
> Have a good day.
>
> Bye,
> Sandro
>
>
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/RESTFul-tp2716422p2729725.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>
>
--
Dr. Stefano Sancese
WatchGuard Certified System Professional - http://www.watchguard.com
Socio Clusit - Associazione Italiana per la Sicurezza Informatica
************************************************************************
In God we trust, all others we monitor (National Security Agency)
************************************************************************
Re: RESTFul
Posted by Sandro Martini <sa...@gmail.com>.
Ciao Stefano,
if you want in any case to create a ticket for the 2.1 release and put there
some info (as soon as you have), just to keep all info in the same place,
would be great.
But I'm sorry, I can't assure that your proposed changes will be accepted in
core Pivot, sorry ...
I have very little experience in REST queries, but for what I've seen there
are many frameworks REST-compatible but all working in different ways (at
least for small differences), but I agree with you that JAX-RS is the
default implementation, so maybe we could try to see how to plug-in it in
Pivot.
For example in a plug-in way like we done for JFreeChart: common interfaces
in Pivot, and pluggable implementation in a Pivot-related project for
example.
But in any case, if you find some problem extending Pivot classes tell to
us (in last weeks we removed some final methods from a user request), and
let's see what we can do.
Then, if you want to share some code with us, you can attach it in JIRA
(inside a zip), or if you are interested, I can give you some grant in one
of others Pivot-related projects, like pivot-stuff.
Thank you very much for your feedback.
If you want to contact me privately (my address is in Pivot Web pages, and
even in this mailing list) I'll be happy to help, if/for what I can :-) .
Have a good day.
Bye,
Sandro
--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/RESTFul-tp2716422p2729725.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
Re: RESTFul
Posted by "Dr. Stefano Sancese" <st...@sancese.com>.
Il 24/03/2011 11:19, Sandro Martini ha scritto:
> Ciao Stefano,
>
> even the signature of the execute method in PutQuery should be changed
> (currently it returns a Boolean), but with the change you proposed should
> return an Object ... (with a return Boolean when all is good otherwise
> something other like in GetQuery ...).
>
> So I think in any case should be a change for the 2.1 release and not before
> to avoid incompatible changes in the 2.0.x maintenance. But note that if
> others agree I'm not against to re-target it before.
>
> If you want to make a JIRA ticket for it (targeting the 2.1 release) and a
> reference to this thread (
> http://apache-pivot-users.399431.n3.nabble.com/RESTFul-td2716422.html ), is
> welcome.
>
Ciao Sandro,
since you suggest to make a ticket targeting the 2.1 release, I'll go on
with the development of my RESTful application and I'll try to write a
complete e comprensive set of suggestions.
I'm using JAX-RS, the de-facto standard I think (and I hope since I have
chosen to use it), for the server side.
I have already found a little mismach: when the JAX-RS return the
response to a succesfull PUT, it uses the 200 code to signal the request
has succeded.
I read on internet a lot of threads about RESTful and there is a lot of
arguing about what is the correct way to respond to a PUT POST or
DELETE, with which return code, which information put on the body and so
on; so it looks to me that there isn't a clear standard to refer to.
Perhaps - imvho - a solution is to choose a reference implementation for
the server side and adapt to it.
Since PIVOT, with JAXB for XML binding, is perfectly fit for develop a
RESTful client, I hope to find a way to use it flawlessly.
Stefano
> Comments ?
>
> Bye,
> Sandro
>
>
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/RESTFul-tp2716422p2724622.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>
>
--
Dr. Stefano Sancese
WatchGuard Certified System Professional - http://www.watchguard.com
Socio Clusit - Associazione Italiana per la Sicurezza Informatica
************************************************************************
In God we trust, all others we monitor (National Security Agency)
************************************************************************
Re: RESTFul
Posted by Greg Brown <gk...@verizon.net>.
> even the signature of the execute method in PutQuery should be changed
> (currently it returns a Boolean), but with the change you proposed should
> return an Object ... (with a return Boolean when all is good otherwise
> something other like in GetQuery ...).
See my previous email. The boolean in this case does not indicate success - it indicates whether or not the operation resulted in the creation of a resource on the server.
G
Re: RESTFul
Posted by Sandro Martini <sa...@gmail.com>.
Ciao Stefano,
even the signature of the execute method in PutQuery should be changed
(currently it returns a Boolean), but with the change you proposed should
return an Object ... (with a return Boolean when all is good otherwise
something other like in GetQuery ...).
So I think in any case should be a change for the 2.1 release and not before
to avoid incompatible changes in the 2.0.x maintenance. But note that if
others agree I'm not against to re-target it before.
If you want to make a JIRA ticket for it (targeting the 2.1 release) and a
reference to this thread (
http://apache-pivot-users.399431.n3.nabble.com/RESTFul-td2716422.html ), is
welcome.
Comments ?
Bye,
Sandro
--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/RESTFul-tp2716422p2724622.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
Re: RESTFul
Posted by "Dr. Stefano Sancese" <st...@sancese.com>.
Il 23/03/2011 12:57, Greg Brown ha scritto:
> Returning a response body from a PUT is not supported. PutQuery
> extends Query<Boolean> and returns a value of true when the query
> creates a resource on the server and false when it does not (i.e.
> updates an existing resource). I'd suggest returning an HTTP 409 and
> passing any additional information in a *response header*.
For HTTP 409 the standard recomends to put additional information in the
body:
>
> 10.4.10 409 Conflict
>
> The request could not be completed due to a conflict with the current
> state of the resource. This code is only allowed in situations where
> it is expected that the user might be able to resolve the conflict and
> resubmit the request. *The response body* SHOULD include enough
> information for the user to recognize the source of the conflict.
>
Don't you think is more appropriate to modify the execute method in
Query.java to permit the return of the response body for every kind of
query and not only for the GET?
Ciao
Stefano
>
>
> On Mar 22, 2011, at 3:21 PM, Dr. Stefano Sancese wrote:
>
>> Hi,
>>
>> I'm developing a RESTFul application using Pivot for the client side.
>>
>> No problem with the GET, but now I'm working on PUT and I have a
>> question:
>>
>> What if the PUT can not be complete, for example because there is an
>> unique key constrain on a field that throws a duplicated error?
>>
>> In this case I'd like to show to the user why the request can not be
>> completed and I wolud like to use the respons body for an extended
>> message.
>>
>> I digged the source and I found this code in
>> web/src/org/apache/pivot/web/Query.java (the class PutQuery extends)
>> the following code at line 499:
>>
>>> // Read the response body
>>> if (*method == Method.GET*
>>> && status == Query.Status.OK) {
>>> InputStream inputStream = null;
>>> try {
>>> inputStream = connection.getInputStream();
>>> value = serializer.readObject(new
>>> MonitoredInputStream(inputStream));
>>> } finally {
>>> if (inputStream != null) {
>>> inputStream.close();
>>> }
>>> }
>>> }
>>
>> So it looks like that only for the GET query the response body is read.
>>
>> From http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10:
>>
>>>
>>> 10.4.10 409 Conflict
>>>
>>> The request could not be completed due to a conflict with the
>>> current state of the resource. This code is only allowed in
>>> situations where it is expected that the user might be able to
>>> resolve the conflict and resubmit the request. The response body
>>> SHOULD include enough
>>>
>>> information for the user to recognize the source of the conflict.
>>> Ideally, the response entity would include enough information for
>>> the user or user agent to fix the problem; however, that might not
>>> be possible and is not required.
>>>
>>> Conflicts are most likely to occur in response to a PUT request. For
>>> example, if versioning were being used and the entity being PUT
>>> included changes to a resource which conflict with those made by an
>>> earlier (third-party) request, the server might use the 409 response
>>> to indicate that it can't complete the request. In this case, *the
>>> response entity *would likely contain a list of the differences
>>> between the two versions in a format defined by the response
>>> Content-Type.
>>>
>>
>> I infer that, in case of error, the server can send a response.
>>
>> Am I wrong?
>>
>>
>> Ciao
>>
>> Stefano
>>
>>
>> --
>> Dr. Stefano Sancese
>>
>> WatchGuard Certified System Professional -http://www.watchguard.com
>> Socio Clusit - Associazione Italiana per la Sicurezza Informatica
>>
>> ************************************************************************
>>
>> In God we trust, all others we monitor (National Security Agency)
>>
>> ************************************************************************
>>
>
--
Dr. Stefano Sancese
WatchGuard Certified System Professional - http://www.watchguard.com
Socio Clusit - Associazione Italiana per la Sicurezza Informatica
************************************************************************
In God we trust, all others we monitor (National Security Agency)
************************************************************************
Re: RESTFul
Posted by Greg Brown <gk...@verizon.net>.
Returning a response body from a PUT is not supported. PutQuery extends Query<Boolean> and returns a value of true when the query creates a resource on the server and false when it does not (i.e. updates an existing resource). I'd suggest returning an HTTP 409 and passing any additional information in a response header.
On Mar 22, 2011, at 3:21 PM, Dr. Stefano Sancese wrote:
> Hi,
>
> I'm developing a RESTFul application using Pivot for the client side.
>
> No problem with the GET, but now I'm working on PUT and I have a question:
>
> What if the PUT can not be complete, for example because there is an unique key constrain on a field that throws a duplicated error?
>
> In this case I'd like to show to the user why the request can not be completed and I wolud like to use the respons body for an extended message.
>
> I digged the source and I found this code in web/src/org/apache/pivot/web/Query.java (the class PutQuery extends) the following code at line 499:
>
>> // Read the response body
>> if (method == Method.GET
>> && status == Query.Status.OK) {
>> InputStream inputStream = null;
>> try {
>> inputStream = connection.getInputStream();
>> value = serializer.readObject(new MonitoredInputStream(inputStream));
>> } finally {
>> if (inputStream != null) {
>> inputStream.close();
>> }
>> }
>> }
>
> So it looks like that only for the GET query the response body is read.
>
> From http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10:
>
>> 10.4.10 409 Conflict
>>
>> The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough
>>
>> information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be possible and is not required.
>>
>> Conflicts are most likely to occur in response to a PUT request. For example, if versioning were being used and the entity being PUT included changes to a resource which conflict with those made by an earlier (third-party) request, the server might use the 409 response to indicate that it can't complete the request. In this case, the response entity would likely contain a list of the differences between the two versions in a format defined by the response Content-Type.
>>
>
> I infer that, in case of error, the server can send a response.
>
> Am I wrong?
>
>
> Ciao
>
> Stefano
>
>
> --
> Dr. Stefano Sancese
>
> WatchGuard Certified System Professional - http://www.watchguard.com
> Socio Clusit - Associazione Italiana per la Sicurezza Informatica
>
> ************************************************************************
>
> In God we trust, all others we monitor (National Security Agency)
>
> ************************************************************************