|
From: Bill B. <bb...@re...> - 2008-06-26 12:50:11
|
CCing dev list, comments inlined.
Stef Epardaud wrote:
> On Wed, Jun 25, 2008 at 11:58:58PM +0200, Peter Hilton wrote:
>> Great article!!! Thanks for showcasing RESTEasy!
>
> Many thanks to you for RESTeasy :)
>
>> * Can you provide some feedback on the bugs you had to fix in RESTEasy? I
>> could get them fixed really fast.
>
> To be honest I've stuck to the svn revision r104 ever since we got
> everything we wanted to work, you know how production software
> constraints are.
>
> Mostly I've fixed some exception handling bugs, for instance exceptions
> which were not correctly unwrapped to WebException.
>
> Here is the full list of changes, but I'm sure most have been fixed:
>
> MessageBodyParameterExtractor:
> - Throw HTTP_UNSUPPORTED_TYPE if request has no mediaType
> - Throw HTTP_UNSUPPORTED_TYPE if factory.createMessageBodyReader
> returned null
Ok, I'll double check that we have a test for this now.
> ResourceMethod:
> - Unwrap Exceptions in every catch (using Throwable.getCause()) in
> order to find possible WebApplicationException with a Response.
>
Good one.
> That's it!
> So it was really minimal and I'm sure they have been fixed since :)
>
>> * JAX-RS has ExceptionMappers these are available in RESTEasy beta 5.
>> public interface ExceptionMapper<E>
>> {
>> /**
>> * Map an exception to a {@link javax.ws.rs.core.Response}.
>> *
>> * @param exception the exception to map to a response
>> * @return a response mapped from the supplied exception
>> */
>> Response toResponse(E exception);
>> }
>
> That seems like a nice feature. While building the application, I've
> wondered about the correct way to declare my functions:
>
> @GET
> Order getOrder();
>
> or
>
> @GET
> Response getOrder();
>
> Basically we decided to make them all return Response, but this is not
> as much for exceptions as for normal returns. For instance on many POST
> and PUT we want to return a "Location:" HTTP header, and sometimes we
> return HTTP_CREATED or HTTP_OK, and I haven't found a way to make this
> work with just returning an instance.
>
> From a purely architectural point of view this is sad because the API
> interface doesn't reflect what is being returned, but I don't really
> know how an alternative would look like.
>
I don't think there's a nice way to do this. We played around with the
idea of having a @Location annotation with embeddable EL:
@Location("/blah/foo/${foo.id}")
MyBean post() {...}
But I just don't think it fits for every scenario because the response
codes may be different. How do you think we could change this?
>> * Any suggestions to make JAX-RS or RESTEasy better?
>
> I've had an issue with @Context UriInfo, which was never injected
> properly when declared as a field, so I had to make them parameters all
> the time, which pollutes the API interface, but I think the
> documentation said fields were supported so I'm sure this has been fixed
> since.
>
Its supported now.
> Also, we wanted to provide custom responses for each unsupported
> operations, like "POST is not supported for resource /foo", but because
> I haven't found a way to get access to the HTTP method name, I've had to
> write one resource handler for each unsupported method. It would be nice
> to provide either a way to customize any response generated by the JAX-RS
> framework (media type not supported, method not supported, resource does
> not exist).
>
This is probably a good idea in general and should done in conjunction
with any internationalization effort.
> For some reasons, the HTTP header returned by using
> Response.status(x).location("foo") is lowercased ("location:" instead of
> "Location:"). Even though this is perfectly acceptable in terms of the
> HTTP standard, it is uncommon I think.
>
This is legal too "lOcAtIoN" so, i just convert everything to lowercase
to make sure there's no errors in header processing anywhere just to be
safe.
> We've had a design question regarding encodings, for instance all our
> methods/resources produce "application/xml" on success, but "text/plain"
> on failure. We've had to declare that they can produce both with
> @ProduceMime( { "application/xml", "text/plain" }) and then set the mime
> type and encoding ourselves in each Response built and returned. Maybe
> this could be made easier?
>
> Last but probably the most important question: is there any planned
> support for generation of WADL or any cross-language RESTful API
> descriptor (if anything else than WADL exists) so that we could generate
> it directly from the server implementation? That would be very nice
> because I'm not really sure how one would go about implementing a client
> in a different language. Maybe it's just me being used to SOAP or CORBA
> ;)
>
I'm not sure, i have mixed feelings about WADL. How would you go about
implementing a client in a different language? Well, just use their
HTTP library. IMO, the code isn't much different than sending messaging
with any other messaging layer. Its actually less verbose than JMS to
do straight HTTP.
> I've just had a look at all the new features you've added since I
> stopped upgrading RESTeasy, they all look great, you've done an amazing
> job, many thanks for this quality software.
>
> To be honest the most gripes and problems I've had while using RESTeasy
> were with JAXB. While it has some really nice features, it is so limited
> for what we want to use it for... I've a huge list of improvements for
> JAXB ;)
>
Well, subscribe to our dev list and post the changes you want to JAXB!
https://lists.sourceforge.net/lists/listinfo/resteasy-developers
I need to refactor it yet again to make it easier to configure.
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com
|
|
From: Bill B. <bb...@re...> - 2008-06-26 13:43:12
|
Stef Epardaud wrote:
> On Thu, Jun 26, 2008 at 08:52:21AM -0400, Bill Burke wrote:
>> I don't think there's a nice way to do this. We played around with the
>> idea of having a @Location annotation with embeddable EL:
>>
>> @Location("/blah/foo/${foo.id}")
>> MyBean post() {...}
>>
>> But I just don't think it fits for every scenario because the response
>> codes may be different. How do you think we could change this?
>
> One way to do it would be to have a @Context Response injected on which
> we could set whatever info we want prior to returning MyBean. This way
> we can set both the HTTP code and the additional headers if needed.
>
>>> For some reasons, the HTTP header returned by using
>>> Response.status(x).location("foo") is lowercased ("location:" instead of
>>> "Location:"). Even though this is perfectly acceptable in terms of the
>>> HTTP standard, it is uncommon I think.
>> This is legal too "lOcAtIoN" so, i just convert everything to lowercase
>> to make sure there's no errors in header processing anywhere just to be
>> safe.
>
> I know this is legal, I'm just saying it is unusual, I would have made
> all the header handling case-insensitive while actually keeping the case
> set when the header was added, but it does not really matter much :)
>
>>> We've had a design question regarding encodings, for instance all our
>>> methods/resources produce "application/xml" on success, but "text/plain"
>>> on failure. We've had to declare that they can produce both with
>>> @ProduceMime( { "application/xml", "text/plain" }) and then set the mime
>>> type and encoding ourselves in each Response built and returned. Maybe
>>> this could be made easier?
>
> I think this point was skipped, maybe on purpose, but maybe not :)
> I don't have any suggestion for this one I'm afraid.
>
You don't have to put "text/plain" in your @ProduceMime. It is only for
matching against ACCEPT headers. You can override the content type
within Response
>> I'm not sure, i have mixed feelings about WADL. How would you go about
>> implementing a client in a different language? Well, just use their
>> HTTP library. IMO, the code isn't much different than sending messaging
>> with any other messaging layer. Its actually less verbose than JMS to
>> do straight HTTP.
>
> Well, writing client-side remote APIs seems to me like a thing of the
> past. When I want to talk to a web service, I expect that they either
> give me the client-side library, or even better a web service descriptor
> that I can use to automatically generate the client-side library in any
> language/framework. RESTful, HTTP, XML are all cross-platform standards,
> why should I expect to write manually a client-side library in .NET to
> be able to talk to my Java RESTful web service?
>
IMO, a client-side library distributed by the server is a no-no. Its ok
with a handful of clients, but what happens when you have 100, 1000,
10000 clients? Its starts to become a real pain to update and
distribute stubs. The lack of client stubs is one of the many reasons I
liked the REST approach to begin with.
> I suspect I can already auto-generate XML object representations in
> several languages using the JAXB-generated XSD, but having to write
> manually the whole client-side binding for each and every resource
> operation seems like a really boring task I would have hoped passé.
>
It just seemed to me that the amount of code I was saving using the
Resteasy client-proxy framework wasn't much compared to straight Apache
HttpClient code.
I think if you think of REST as a messaging pattern rather than an RPC
one, you start to feel differently about WADL and stub generation.
There are so many things you can do in a pure messaging paradigm that
you can't do in an RPC based system. For example, different clients may
want to handle different response codes, mime-types, and response
headers differently.
> Even though I have some doubts about WADL's ability to represent
> exceptions if only because they are not part of the server API (they are
> hidden in the Response object, even if declared in the "throws" clause,
> because they will then be converted into a Response object later on).
> SOAP does declare exceptions though, and it's handy.
>
>> Well, subscribe to our dev list and post the changes you want to JAXB!
>
> To be honest the changes I want to JAXB I haven't had time to implement
> them, and I'm not sure if my tight work deadlines will allow me to, but
> really I need to at least get a hand to the guys working on the next
> JAXB version if there is one under way to see if all the problems we
> have with it can/should be solved.
>
On JAXB, I meant, describe the changes you want in email, and we'll do
the work!
--
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com
|
|
From: Stef E. <st...@ep...> - 2008-06-26 14:04:41
|
On Thu, Jun 26, 2008 at 09:45:22AM -0400, Bill Burke wrote: > You don't have to put "text/plain" in your @ProduceMime. It is only for > matching against ACCEPT headers. You can override the content type > within Response But then how does it work if a client only accepts 'application/xml' and one of my exception sends 'text/plain' because XML is too verbose for exceptions? > IMO, a client-side library distributed by the server is a no-no. Its ok > with a handful of clients, but what happens when you have 100, 1000, > 10000 clients? Its starts to become a real pain to update and > distribute stubs. The lack of client stubs is one of the many reasons I > liked the REST approach to begin with. > > It just seemed to me that the amount of code I was saving using the > Resteasy client-proxy framework wasn't much compared to straight Apache > HttpClient code. > > I think if you think of REST as a messaging pattern rather than an RPC > one, you start to feel differently about WADL and stub generation. > There are so many things you can do in a pure messaging paradigm that > you can't do in an RPC based system. For example, different clients may > want to handle different response codes, mime-types, and response > headers differently. Being able to generate a WADL doesn't prevent one from writing a custom client. I understand your point, but what this means for us is that we have to write the client-side stubs API ourselves to deliver it to the clients. Suddenly I have a hard time explaining why we have to do more work in REST than SOAP to my boss. Don't get me wrong, we chose RESTful and JAX-RS because we like them better than SOAP, but it's hard to tell your boss you require more time because you chose a more pleasant framework :) > >To be honest the changes I want to JAXB I haven't had time to implement > >them, and I'm not sure if my tight work deadlines will allow me to, but > >really I need to at least get a hand to the guys working on the next > >JAXB version if there is one under way to see if all the problems we > >have with it can/should be solved. > > On JAXB, I meant, describe the changes you want in email, and we'll do > the work! As much as I'm impressed by the quality of RESTeasy and JAX-RS, I have a hard time believing you'll work on updating the JAXB standard just for me ;) I don't have any problem with the integration of JAXB in JAX-RS, but rather with the JAXB standard itself and its limitations in our use-cases. -- Stéphane Epardaud |
|
From: Bill B. <bb...@re...> - 2008-06-26 14:39:26
|
Stef Epardaud wrote: > On Thu, Jun 26, 2008 at 09:45:22AM -0400, Bill Burke wrote: >> You don't have to put "text/plain" in your @ProduceMime. It is only for >> matching against ACCEPT headers. You can override the content type >> within Response > > But then how does it work if a client only accepts 'application/xml' and > one of my exception sends 'text/plain' because XML is too verbose for > exceptions? > I guess you're talking about the client framework? It really depends on your return type >>> To be honest the changes I want to JAXB I haven't had time to implement >>> them, and I'm not sure if my tight work deadlines will allow me to, but >>> really I need to at least get a hand to the guys working on the next >>> JAXB version if there is one under way to see if all the problems we >>> have with it can/should be solved. >> On JAXB, I meant, describe the changes you want in email, and we'll do >> the work! > > As much as I'm impressed by the quality of RESTeasy and JAX-RS, I have a > hard time believing you'll work on updating the JAXB standard just for > me ;) > > I don't have any problem with the integration of JAXB in JAX-RS, but > rather with the JAXB standard itself and its limitations in our > use-cases. Oh, LOL Ok! Thought you meant RESTEasy + JAX-RS + JAXB! -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com |
|
From: Stef E. <st...@ep...> - 2008-06-26 14:45:35
|
On Thu, Jun 26, 2008 at 10:41:40AM -0400, Bill Burke wrote: > >But then how does it work if a client only accepts 'application/xml' and > >one of my exception sends 'text/plain' because XML is too verbose for > >exceptions? > > I guess you're talking about the client framework? It really depends on > your return type Now I remember exactly what my problem was: I declared my @ProduceMime to only generate 'application/xml' because that's all I return from my resources. And my clients only accept 'application/xml'. Now when I threw an exception, the mime type was 'text/plain' and the client could not accept it, so I needed to include 'text/plain' in my @ProduceMime (because if I throw exceptions which generate plain text responses, I do produce text/plain) and let my clients accept it too. Not very important ;) > >As much as I'm impressed by the quality of RESTeasy and JAX-RS, I have a > >hard time believing you'll work on updating the JAXB standard just for > >me ;) > > > >I don't have any problem with the integration of JAXB in JAX-RS, but > >rather with the JAXB standard itself and its limitations in our > >use-cases. > > Oh, LOL Ok! Thought you meant RESTEasy + JAX-RS + JAXB! See, now I'm disappointed ;) -- Stéphane Epardaud |
|
From: Stef E. <st...@ep...> - 2008-06-26 13:11:10
|
On Thu, Jun 26, 2008 at 08:52:21AM -0400, Bill Burke wrote:
> I don't think there's a nice way to do this. We played around with the
> idea of having a @Location annotation with embeddable EL:
>
> @Location("/blah/foo/${foo.id}")
> MyBean post() {...}
>
> But I just don't think it fits for every scenario because the response
> codes may be different. How do you think we could change this?
One way to do it would be to have a @Context Response injected on which
we could set whatever info we want prior to returning MyBean. This way
we can set both the HTTP code and the additional headers if needed.
> >For some reasons, the HTTP header returned by using
> >Response.status(x).location("foo") is lowercased ("location:" instead of
> >"Location:"). Even though this is perfectly acceptable in terms of the
> >HTTP standard, it is uncommon I think.
>
> This is legal too "lOcAtIoN" so, i just convert everything to lowercase
> to make sure there's no errors in header processing anywhere just to be
> safe.
I know this is legal, I'm just saying it is unusual, I would have made
all the header handling case-insensitive while actually keeping the case
set when the header was added, but it does not really matter much :)
> >We've had a design question regarding encodings, for instance all our
> >methods/resources produce "application/xml" on success, but "text/plain"
> >on failure. We've had to declare that they can produce both with
> >@ProduceMime( { "application/xml", "text/plain" }) and then set the mime
> >type and encoding ourselves in each Response built and returned. Maybe
> >this could be made easier?
I think this point was skipped, maybe on purpose, but maybe not :)
I don't have any suggestion for this one I'm afraid.
> I'm not sure, i have mixed feelings about WADL. How would you go about
> implementing a client in a different language? Well, just use their
> HTTP library. IMO, the code isn't much different than sending messaging
> with any other messaging layer. Its actually less verbose than JMS to
> do straight HTTP.
Well, writing client-side remote APIs seems to me like a thing of the
past. When I want to talk to a web service, I expect that they either
give me the client-side library, or even better a web service descriptor
that I can use to automatically generate the client-side library in any
language/framework. RESTful, HTTP, XML are all cross-platform standards,
why should I expect to write manually a client-side library in .NET to
be able to talk to my Java RESTful web service?
I suspect I can already auto-generate XML object representations in
several languages using the JAXB-generated XSD, but having to write
manually the whole client-side binding for each and every resource
operation seems like a really boring task I would have hoped passé.
Even though I have some doubts about WADL's ability to represent
exceptions if only because they are not part of the server API (they are
hidden in the Response object, even if declared in the "throws" clause,
because they will then be converted into a Response object later on).
SOAP does declare exceptions though, and it's handy.
> Well, subscribe to our dev list and post the changes you want to JAXB!
To be honest the changes I want to JAXB I haven't had time to implement
them, and I'm not sure if my tight work deadlines will allow me to, but
really I need to at least get a hand to the guys working on the next
JAXB version if there is one under way to see if all the problems we
have with it can/should be solved.
Thanks again for your feedback :)
--
Stéphane Epardaud
|