You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by anand sridhar <an...@gmail.com> on 2012/02/22 21:17:01 UTC

How to customize output based on content-type in header.

Hi,
I am developing REST services using CXF and am exposing each service to
provide output in multiple content types  viz , application./xml,
application/json, text/html etc...
To determine what content type every request should request for, I managed
to work out that I can use cxf extensions to provide the content type as
extension.

like /api/service.xml, /api/service.json  and so on.

However, I would like to know if it is possible to provide the content type
through request header and how in CXF I can read and provide output in
suitable content type.

Thanks,
Anand

Re: How to customize output based on content-type in header.

Posted by Anand Hemmige <an...@gmail.com>.
Thank you Glen,
I will try that ..

On Wed, Feb 22, 2012 at 12:47 PM, Glen Mazza <gm...@talend.com> wrote:

> I recently converted Jersey's jacksonjsonprovider sample to run on CXF,
> it's available here:
> https://github.com/gmazza/**jersey-samples-on-cxf/tree/**
> master/jacksonjsonprovider<https://github.com/gmazza/jersey-samples-on-cxf/tree/master/jacksonjsonprovider>
>
> The README.html for this sample shows how the client can use open-source
> cURL to provide the desired content type as a header (extra parameter)
> instead of within the URL; also the sample itself has root resources
> providing content in various formats: XML, JSON, and JSONP.
>
> HTH,
> Glen
>
>
> On 02/22/2012 03:17 PM, anand sridhar wrote:
>
>> Hi,
>> I am developing REST services using CXF and am exposing each service to
>> provide output in multiple content types  viz , application./xml,
>> application/json, text/html etc...
>> To determine what content type every request should request for, I managed
>> to work out that I can use cxf extensions to provide the content type as
>> extension.
>>
>> like /api/service.xml, /api/service.json  and so on.
>>
>> However, I would like to know if it is possible to provide the content
>> type
>> through request header and how in CXF I can read and provide output in
>> suitable content type.
>>
>> Thanks,
>> Anand
>>
>>
>
> --
> Glen Mazza
> Talend Community Coders
> coders.talend.com
> blog: www.jroller.com/gmazza
>
>

Re: How to customize output based on content-type in header.

Posted by Glen Mazza <gm...@talend.com>.
I recently converted Jersey's jacksonjsonprovider sample to run on CXF, 
it's available here:
https://github.com/gmazza/jersey-samples-on-cxf/tree/master/jacksonjsonprovider

The README.html for this sample shows how the client can use open-source 
cURL to provide the desired content type as a header (extra parameter) 
instead of within the URL; also the sample itself has root resources 
providing content in various formats: XML, JSON, and JSONP.

HTH,
Glen

On 02/22/2012 03:17 PM, anand sridhar wrote:
> Hi,
> I am developing REST services using CXF and am exposing each service to
> provide output in multiple content types  viz , application./xml,
> application/json, text/html etc...
> To determine what content type every request should request for, I managed
> to work out that I can use cxf extensions to provide the content type as
> extension.
>
> like /api/service.xml, /api/service.json  and so on.
>
> However, I would like to know if it is possible to provide the content type
> through request header and how in CXF I can read and provide output in
> suitable content type.
>
> Thanks,
> Anand
>


-- 
Glen Mazza
Talend Community Coders
coders.talend.com
blog: www.jroller.com/gmazza