users@jersey.java.net

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

From: <FSauer_at_dsthealthsolutions.com>
Date: Wed, 7 Oct 2009 08:41:52 -0500

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?
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....


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.





picture
(image/gif attachment: 01-part)