On Aug 31, 2009, at 12:47 PM, Felipe Gaúcho wrote:
> humm.. if I return a Collection directly, it works.. but if I try to
> wrapp it in a Response object, I got the ugly error message again:
>
> @GET
> @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
> @Path("{offset}/{limit}")
> public Response selectAllByCompetition(
> @PathParam("institution") String institution,
> @PathParam("offset") int offset, @PathParam("limit") int limit,
> @QueryParam("competition") String name) {
> return Response.ok(
> detailsFacade.readAllByCompetition(offset, limit, institution,
> name)).build();
> }
>
> "A message body writer for Java type, class java.util.Vector, and MIME
> media type, application/xml, was not found"
>
You need to wrap the returned Collection<PujUserDetailsEntity> in a
GenericEntity[1] before you add it to the response.
Marc.
[1]
https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/core/GenericEntity.html
>
> -----------------
>
> if I do it directly, it works normally:
>
> @GET
> @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
> @Path("{offset}/{limit}")
> public Collection<PujUserDetailsEntity> selectAllByCompetition(
> @PathParam("institution") String institution,
> @PathParam("offset") int offset, @PathParam("limit") int limit,
> @QueryParam("competition") String name) {
> return detailsFacade.readAllByCompetition(offset, limit,
> institution,
> name);
> }
>
> * using Glassfish v2.1 with default TopLink ... :(
>
>
>
> On Sat, Aug 29, 2009 at 10:08 PM, Craig
> McClanahan<Craig.McClanahan_at_sun.com> wrote:
>> Felipe Gaúcho wrote:
>>
>> humm.. but I have already a response type..
>>
>> my method:
>>
>> @GET
>> @Produces( { MediaType.APPLICATION_XML,
>> MediaType.APPLICATION_JSON })
>> @Path("{offset}/{limit}/{groupId}")
>> public Collection<PujUserEntity> selectAllByGroup(
>> @PathParam("offset") int offset, @PathParam("limit") int limit,
>> @PathParam("offset") String groupId) {
>> return facade.readAllByGroupId(offset, limit, groupId);
>> }
>>
>>
>> How to set the chraset (and other headers) of the HTTP response ?
>>
>>
>> Your resource method is returning the entity
>> (Collection<PujUserEntity>)
>> directly. Have it return a "Response" object instead. Jersey will
>> set the
>> content type and content length for you, but you can set any other
>> headers
>> you want as in my example below.
>>
>> On Sat, Aug 29, 2009 at 7:25 PM, Craig
>> McClanahan<Craig.McClanahan_at_sun.com> wrote:
>>
>>
>> Felipe Gaúcho wrote:
>>
>>
>> How to set the response encoding of my Jersey resources ?
>>
>> * or other response HTTP headers ?
>>
>>
>>
>>
>> Have your resource method return a "javax.ws.rs.core.Resonse"
>> instead of an
>> entity object class directly. You can use its "builder pattern"
>> APIs to add
>> as many headers as you like:
>>
>> @GET
>> public Response get(...) {
>>
>>
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Note the return type from the method
>>
>> Object entity = ...; // The object you would normally have been
>>
>>
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This would be
>> "facade.readAllByGroupId(offset, limit, groupId)" for you (or you
>> could just
>> pass this directly as the argument to the ok() method).
>>
>> returning
>> return Response.ok(entity).
>> header("Content-Language", "en-us").
>>
>>
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Set any header you want like this.
>> There
>> are also shortcuts like language() to set the Content-Language
>> header, tag()
>> to set an ETag, and so on.
>>
>>
>> build();
>> }
>>
>> There are also shortcut methds for many of the common HTTP headers,
>> as well
>> as a way to set status codes other than 200.
>>
>> Craig
>>
>>
>>
>> Craig
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>>
>>
>>
>>
>
>
>
> --
> Looking for a client application for this service:
> http://fgaucho.dyndns.org:8080/footprint-service/wadl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>