users@jersey.java.net

Implicit views and _at_ImplicitProduces

From: Rabick, Mark A (IS) <"Rabick,>
Date: Thu, 21 May 2009 14:33:40 -0500

Can someone give me a short description of the notion of 'implicit views' describes by the @ImplicitProduces annotation javadocs?

        Defines the media type(s) that a resource class can produce for implicit views.

        The list of media types may be declared individually as String items or as a comma separated list of one or more String items.

        A quality source parameter, qs, may be declared as a paramter of a media type. The quality source will be multiple by the quality parameter, q, of an acceptable matching media type. This enables the application to prefer say "text/html" over "application/xml" even if the client declares a higher quality value for the latter than the former.

I have a sub-resource class that has a redirect method that returns a new URI in the Location header. There is no entity returned so I didn't put an @Produces annotation on the resource method. If I use the Jersey client api, I'm getting a 404 on the request:

The resource method is:

        @GET @Path("attributemap")
        public Response getEntityAttributeMap(@Context UriInfo uriInfo) {

                Node node = // get node from database
                if (node == null)
                        throw new NotFoundException("No node exists for node sk: " + _nodesk);
                
                String mapSk = node.getEntityAttributeMap().getEntityAttributeMapSk();
        
                /*
                 * Construct a URI for the given entity attribute map and return it
                 * in the location header.
                 */
                URI mapUri = uriInfo.getBaseUriBuilder().path("v1")
                                                                          .path("attributemaps")
                                                                        .path(mapSk).build();
                Response response = Response.status(Response.Status.SEE_OTHER).location(mapUri).build();
                
                System.out.println(" returning Response: " + response.toString());
                return response;
        }

My client code is:

                        ClientResponse response = _nodeResource.header(HttpHeaders.AUTHORIZATION, getBasicAuthHeader())
                                                                                                        .get(ClientResponse.class);
                        assertNotNull(response);
***** assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
                        URI mapUri = response.getLocation();
                        assertNotNull(mapUri);
                        writeln("mapUri = " + mapUri.toString());

Questions:
1. Is the @Produces annotation required on all resource methods? Even those with no 'entity'?
2. The ****** line above fails because the returned status is 404. Do I need to specify a type(MediaType.<something>) on the WebResource.Builder?

--mark

_______________________________________________
Mark A. Rabick
Software Engineer
Northrop Grumman - Integrated Mission Systems (IS/DSD/IMS)
3200 Samson Way
Bellevue, NE 68123
Ph: (402) 293-7091
Em: mark.rabick_at_ngc.com
Remember PFC Ross A. McGinnis...
  http://www.army.mil/medalofhonor/McGinnis/index.html
... MA2 Michael A. Monsoor, Lt. Michael P. Murphy, Cpl. Jason Dunham, SFC Paul Ray Smith and the rest...
  http://www.cmohs.org/recipients/most_recent.htm