You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by wildPengiun <Si...@gossinteractive.com> on 2008/09/25 10:29:12 UTC
CXF REST Service
I have a simple REST (GET) that retrieves a binary from the server byte[]. My
problem is that the @producemime attribute is static (set at design time). I
will not know the type of media JPEG, Word Document etc until run-time. Is
there a way that I can set the value of @producemime at run-time or is there
another way of doing it ?
Many thanks.
--
View this message in context: http://www.nabble.com/CXF-REST-Service-tp19665190p19665190.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: CXF REST Service
Posted by wildPengiun <Si...@gossinteractive.com>.
Works very well, thanks for that.
Sergey Beryozkin wrote:
>
> Hi
>
>
> In your method, instead of returning byte[] directly, return JAX-RS
> Response and set
> your byte[] on that Response, as well as the status code and the media
> type :
>
> return Response.ok().type(theMediaType).entity(byteArray).build();
>
> and you can remove @ProduceMime on the method itself. It will lead to all
> of the input HTTP Accept values be accepted during a
> method match, so you might want to do some additional matching in your
> method based on the value of @Context HttpHeaders. You can do
> this type of pre-match in a provate CXF filter if you do not want to do it
> in the application code.
>
> Cheers, Sergey
>
>
>>
>> I have a simple REST (GET) that retrieves a binary from the server
>> byte[]. My
>> problem is that the @producemime attribute is static (set at design
>> time). I
>> will not know the type of media JPEG, Word Document etc until run-time.
>> Is
>> there a way that I can set the value of @producemime at run-time or is
>> there
>> another way of doing it ?
>>
>> Many thanks.
>> --
>> View this message in context:
>> http://www.nabble.com/CXF-REST-Service-tp19665190p19665190.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>
>
--
View this message in context: http://www.nabble.com/CXF-REST-Service-tp19665190p19666573.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: CXF REST Service
Posted by Sergey Beryozkin <se...@iona.com>.
Hi
In your method, instead of returning byte[] directly, return JAX-RS Response and set
your byte[] on that Response, as well as the status code and the media type :
return Response.ok().type(theMediaType).entity(byteArray).build();
and you can remove @ProduceMime on the method itself. It will lead to all of the input HTTP Accept values be accepted during a
method match, so you might want to do some additional matching in your method based on the value of @Context HttpHeaders. You can do
this type of pre-match in a provate CXF filter if you do not want to do it in the application code.
Cheers, Sergey
>
> I have a simple REST (GET) that retrieves a binary from the server byte[]. My
> problem is that the @producemime attribute is static (set at design time). I
> will not know the type of media JPEG, Word Document etc until run-time. Is
> there a way that I can set the value of @producemime at run-time or is there
> another way of doing it ?
>
> Many thanks.
> --
> View this message in context: http://www.nabble.com/CXF-REST-Service-tp19665190p19665190.html
> Sent from the cxf-user mailing list archive at Nabble.com.
----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland