users@jersey.java.net

Re: [Jersey] Extending BookStore example to make books updateable

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 07 Oct 2009 22:40:16 +0200

On Oct 7, 2009, at 3:41 PM, FSauer_at_dsthealthsolutions.com wrote:

>
> working with version 1.0.3 which has the @ImplicitProduces on the
> Bookstore resource.......
> I also noticed that IE favors the bookstore XML over the html, where
> firefox properly renders the html on the exact same URL
> How do we make sure we get the same results in spite of crazy
> browser Accept headers?

IE makes it harder for sure!


> What are the best practices for using resources for both the UI of
> the application as well as data sources?
> Based on my experience so far it looks like they should not be
> mixed....

I think where possible they should. It is just with Jersey we have a
little more work to do to make this easier for the developer. In
general i think we could make many improvements to the MVC area (i
know James would really like that!) it is just we are a small team
with limited resources. Hopefully after GlassFish is released we can
revisit and put a plan together.

IMHO i think what could help is a filter that normalizes the accept
header based on the User-Agent, and documentation should state than
non-browser-based clients should be clear in the media type they accept.

For example for IE if the media type is "*/*" it is normalized to
"text/html, */*".

Paul.

> <mime-attachment.gif> Frank Sauer
> Principal Architect
> DST Health Solutions
> 2500 Corporate Drive
> Birmingham, AL 35242
> (205)437-5204 (Office) (Direct)
> (205)568-4684 (Cell)
> fsauer_at_dsthealthsolutions.com
> It is impossible to sharpen a pencil with a blunt axe. It is equally
> vain to try to do it with ten blunt axes instead -- Edsger W. Dijkstra
>
>
>
>
> Paul Sandoz <Paul.Sandoz_at_Sun.COM>
> Sent by: Paul.Sandoz_at_Sun.COM
> 10/07/2009 03:36 AM
> Please respond to
> users_at_jersey.dev.java.net
>
> To
> users_at_jersey.dev.java.net
> cc
> Subject
> Re: [Jersey] Extending BookStore example to make books updateable
>
>
>
>
>
> Hi Frank,
>
> If you want to mix implicit views and explicit resource methods you
> need to annotate the resource class with @ImplicitProduces. For
> example:
>
> @ImplicitProduces("text/html;qs=5")
>
> Otherwise you need to convert the implicit views into explicit
> resource methods that return an instance of Viewable.
>
> What version of the Bookstore are you modifying?
>
> If you could zip up your Bookstore sample and send it to me i should
> be able to modify it for you. But i will likely on have time to do
> that next week.
>
> Paul.
>
> On Oct 6, 2009, at 5:25 PM, FSauer_at_dsthealthsolutions.com wrote:
>
>
> I am trying to extend the bookstore example so that the Book jsp has
> a form so the Books are editable.
> I added an updateItem method to the BookStore like so, but after I
> do that, the jsp for Book is no longer shown, get 405 'The specified
> HTTP method is not allowed for the requested resource ().'
> If I add @Get to getItem I get a 404 The requested resource () is
> not available. I am missing something but I don't know what it is....
> It works when I add '/update' at the end of the updateItem URI but
> I'm trying to avoid that.
> Also when I add '/update' to make it work, the method returns XML
> instead of coming back with an implicit View for the item. How do I
> make that work?
>
> Any help would be appreciated,
>
> Thanks,
>
> Frank
>
>
> @Path("items/{itemid}")
> public Item getItem(@PathParam("itemid") String itemid) {
> Item i = getItems().get(itemid);
> if (i == null)
> throw new NotFoundException("Item, " + itemid + ", is not
> found");
>
> return i;
> }
>
> @Path("items/{itemid}")
> @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
> @POST
> public Item updateItem(
> @PathParam("itemid") String itemid,
> @FormParam("title") String title,
> @FormParam("author") String author) {
> Item i = getItems().get(itemid);
> if (i != null) {
> i.setTitle(title);
> i.setAuthor(author);
> }
> return i;
> }
> <mime-attachment.gif> Frank Sauer
> Principal Architect
> DST Health Solutions
> 2500 Corporate Drive
> Birmingham, AL 35242
> (205)437-5204 (Office) (Direct)
> (205)568-4684 (Cell)
> fsauer_at_dsthealthsolutions.com
> It is impossible to sharpen a pencil with a blunt axe. It is equally
> vain to try to do it with ten blunt axes instead -- Edsger W. Dijkstra
>
>
>
>
> Please consider the environment before printing this email and any
> attachments.
>
> This e-mail and any attachments are intended only for the individual
> or company to which it is addressed and may contain information
> which is privileged, confidential and prohibited from disclosure or
> unauthorized use under applicable law. If you are not the intended
> recipient of this e-mail, you are hereby notified that any use,
> dissemination, or copying of this e-mail or the information
> contained in this e-mail is strictly prohibited by the sender. If
> you have received this transmission in error, please return the
> material received to the sender and delete all copies from your
> system.
>
>
>
>
>
> Please consider the environment before printing this email and any
> attachments.
>
> This e-mail and any attachments are intended only for the individual
> or company to which it is addressed and may contain information
> which is privileged, confidential and prohibited from disclosure or
> unauthorized use under applicable law. If you are not the intended
> recipient of this e-mail, you are hereby notified that any use,
> dissemination, or copying of this e-mail or the information
> contained in this e-mail is strictly prohibited by the sender. If
> you have received this transmission in error, please return the
> material received to the sender and delete all copies from your
> system.
>