users@jersey.java.net

Re: [Jersey] Documentation for 1.0

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 02 Oct 2008 12:55:04 +0100

On Oct 2, 2008, at 12:38 PM, tarjei wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi, this looks very good!
> Paul Sandoz wrote:
>> First complete draft done:
>>
>> http://wikis.sun.com/display/Jersey/Overview+of+JAX-RS+1.0+Features
> Trying to be the devils advocate with regard to the above document, I
> came up with a few inputs:
>
>
> 1. Maybe some of the examples should be methods for a PUT or HEAD
> request - just to show that they are treated the same?
>

I can point to samples that use PUT. Also i can mention that HEAD/
OPTIONS is supported automatically.


> 2. An example of a a POST handling file upload would probably be a
> good
> idea.
>
> 3. In the same way, maybe an example showing how to return a binary
> file
> , something like:
> @GET
> @Path("/images/{image}")
> @Produces("*/*")
> public Response getImage(@PathParam("image") String image) {
> File f = new File(image);
>
> if (!f.exists()) {
> // File is not present
> log.error("No file " + f.getAbsolutePath() + "present in
> the
> database");
> throw new WebApplicationException(404);
> }
> String mt = null;
> InputStream in = null;
> try {
> mt = new MimetypesFileTypeMap().getContentType(f);
> in = new BufferedInputStream(new FileInputStream(f));
> } catch (FileNotFoundException e) {
> throw new WebApplicationException(404);
> }
> Response r = Response.ok(in).type(mt).build();
> return r;
> }
>

OK. Do you know you can use File directly as follows:

   @GET
    @Path("/images/{image}")
    @Produces("*/*")
    public Response getImage(@PathParam("image") String image) {
        File f = new File(image);

        if (!f.exists()) {
            // File is not present
            log.error("No file " + f.getAbsolutePath() + "present in the
database");
            throw new WebApplicationException(404);
        }

        String mt = new MimetypesFileTypeMap().getContentType(f);
        return Response.ok(f, mt).build();
    }

This might be good as a general example for a resource that supports
file browsing and may be reused as a sub-resource.


> 4. Is there a difference between @PATH("/test" and @PATH("/test/") and
> @PATH("test/") ? If not, state that - and if there is explain it :)
>

No. Good point.


> Hmm, maybe there should be way to test anotations? Something like:
>
> JerseyTest jersey = new JerseyTest(new myResource());
>
> Response r = jersey.request(JerseyTest.GET, "/someurl");
>
> ? I'm not sure if it is a good idea, but right now annotations are a
> bit
> like untestable code.
>

Working on it. The best way to test is to deploy and invoke over HTTP
using the Jersey client API. We are going to make it really easy to
write such tests using JUnit, even though they are not unit tests the
JUnit framework is very convenient or such purposes.


> 5. One thing I feel is missing is some hints on the relationship
> between
> a representation and JAXB. This might be because I'm a JAXB newbie,
> but
> that is an area where there is a lot of "magic" so to explain it fully
> might be a good idea - probably with a small example like:
> class User {
> String username;
> }
> @PATH("/")
> class MyResource {
>
> @GET
> User getUser(){}
>
> @POST
> User updateUser(User user) {}
> }
> ...
>


See the jaxb sample:

http://download.java.net/maven/2/com/sun/jersey/samples/jaxb/1.0-ea-SNAPSHOT/jaxb-1.0-ea-SNAPSHOT-project.zip


> + an example of what the client may post to modify this user.
>
> Ok, I guess this is quite a lot, but my last point is more general
> for a
> lot of java documentation: The classes referenced in the text should
> be
> links so that it is possible to quickly find the javadoc of a special
> class.
>

Agreed, i plan to add links.


>
> Apart from that, good work !
> I hope this isn't too overwhelming - also I might have missed
> something
> in the docs.
>

No, very useful feedback.

Paul.


> Kind regards,
> Tarjei
>
>
>>
>> Paul.
>>
>> On Sep 29, 2008, at 6:04 PM, Paul Sandoz wrote:
>>
>>> Hi,
>>>
>>> I have started filling out a brief overview of JAX-RS 1.0:
>>>
>>> http://wikis.sun.com/display/Jersey/Overview+of+JAX-RS+1.0+Features
>>>
>>> in preparation for the 1.0 release.
>>>
>>> I plan to do two more:
>>>
>>> 1) An over of advanced JAX-RS 1.0 features
>>>
>>> 2) An overview of Jersey features.
>>>
>>> Feel free to provide feedback. Do people find this sort of thing
>>> useful?
>>>
>>> Paul.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFI5LLIYVRKCnSvzfIRAmgYAJ4i+cfhmvbbjTWSOAmR2++upgz/VwCbBdwC
> /C/QzP6dHoUGiSpPic30kq0=
> =YlFU
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>