users@jersey.java.net

RE: [Jersey] Implicit views and _at_ImplicitProduces

From: Rabick, Mark A (IS) <"Rabick,>
Date: Thu, 21 May 2009 15:26:48 -0500

Thanks Paul.

I verified that the resource method was returning the expected
status/URI:

mapUri:
http://localhost:7001/i3/cnodb/cdal/rest/v1/attributemaps/70489910000032
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20
Node - getEntityAttributeMap [END] response status: 303

I set the Client.setFollowRedirects(Boolean.FALSE) my Junit test passed
- received a status 303 with the URI. I have to figure out what's going
on with the redirected URI. The key value I'm appending to the URI is
an explicit foreign key constraint in our database. The key is a
char(32) so I'm not sure about the spaces (%20)

The resource method for the redirected target URI is:

@Path("{mapsk: [a-zA-Z0-9 ]{32}}")
        public AttributeMapV1Resource
getMapV1Resource(@PathParam("mapsk") String mapsk)

Maybe the regex is incorrect? The sk characters need to be letters,
digits, or a space.

--mark

_______________________________________________
Mark A. Rabick - Software Engineer
Em: mark.rabick_at_ngc.com

 

> -----Original Message-----
> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Sent: Thursday, May 21, 2009 2:59 PM
> To: users_at_jersey.dev.java.net
> Subject: Re: [Jersey] Implicit views and @ImplicitProduces
>
>
> 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.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>