On May 21, 2009, at 9:33 PM, Rabick, Mark A (IS) wrote:
> 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.
>
It is used with resource classes that use templates like JSPs
implicitly for certain media types, and resource methods for other
media types. It is not related to the issue you are experiencing.
> 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'?
>
No. It is orthogonal to your issue.
>
> 2. The ****** line above fails because the returned status is 404.
> Do I need to specify a type(MediaType.<something>) on the
> WebResource.Builder?
>
I am guessing the problem is that the underlying HttpURLConnection is
performing automatic redirection to the URI in the first response and
the URI you have created does not point to an existing resource.
Can you verify by setting the redirect property on the Client?
https://jersey.dev.java.net/nonav/apidocs/1.1.0-ea/jersey/com/sun/jersey/api/client/Client.html
#setFollowRedirects(java.lang.Boolean)
Paul.