You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Seiji Sogabe (JIRA)" <ji...@apache.org> on 2014/05/22 16:23:03 UTC

[jira] [Created] (CAMEL-7457) [camel-cxf] cxfrs: SimpleConsumer does not honur Accept header

Seiji Sogabe created CAMEL-7457:
-----------------------------------

             Summary: [camel-cxf] cxfrs: SimpleConsumer does not honur Accept header
                 Key: CAMEL-7457
                 URL: https://issues.apache.org/jira/browse/CAMEL-7457
             Project: Camel
          Issue Type: Bug
          Components: camel-cxf
    Affects Versions: 2.12.3
            Reporter: Seiji Sogabe


I create service class and spring xml as follows.

{code:title=CustomerService.java}
@Path("/customer")
public class CustomerService {
    
    @GET
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Customers getCustomers() {
        return null;
    }
}
{code}

{code:xml}
    <cxf:rsServer xmlns:cxf="http://camel.apache.org/schema/cxf"
                  id="rsServer"
                  address="http://localhost:9999/rsServer"
                  loggingFeatureEnabled="true"
                  loggingSizeLimit="200"> 
        <cxf:serviceBeans>
            <ref bean="CustomerService" />
        </cxf:serviceBeans>
        <cxf:providers>
            <ref bean="jettisonProvider" />
        </cxf:providers>
    </cxf:rsServer>

        
    <!-- provider -->
    <bean id="jettisonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider" />
            
    <!-- interface -->    
    <bean id="CustomerService" class="com.buildria.camel.cxf.negotiation.CustomerService" />
    <!-- Concrete class -->
    <bean id="CustomerServiceImpl" class="com.buildria.camel.cxf.negotiation.CustomerServiceImpl" />
    
    <camelContext xmlns="http://camel.apache.org/schema/spring">
 
        <route> 
            <!-- (1) SimpleConsumer BindingStyle -->
            <from uri="cxfrs://bean://rsServer?bindingStyle=SimpleConsumer" />
            <!-- (2) Default BindingStyle -->
            <!-- <from uri="cxfrs://bean://rsServer" />-->
            
            <choice>
                <when>
                    <simple>$simple{headers.operationName} == 'getCustomers'</simple>
                    <bean ref="CustomerServiceImpl" method="getCustomers" />
                </when>
                <otherwise>
                    <setHeader headerName="CamelHttpResponseCode">
                        <constant>404</constant>
                    </setHeader>
                </otherwise>
            </choice>
        </route>
    </camelContext>
{code}

I tested it with curl command like this.

{noformat}
$ curl  -H "Accept: application/json"  http://localhost:9999/rsServer/customer/ 
{"customers":{"customers":{"address":"Japan","name":"Ken"}}}sogabe@emilia ~/src/camel/camel-rest-cxfrs [2.10.6] 2014/05/22 午後 23:15:56 
$ LANG=C curl  -H "Accept: application/json"  http://localhost:9999/rsServer/customer/ -v
* Hostname was NOT found in DNS cache
*   Trying ::1...
* connect to ::1 port 9999 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9999 (#0)
> GET /rsServer/customer/ HTTP/1.1
> User-Agent: curl/7.36.0
> Host: localhost:9999
> Accept: application/json
> 
< HTTP/1.1 200 OK
< Accept: application/json
< breadcrumbId: ID-emilia-46343-1400768103395-0-7
< Content-Type: application/json
< Date: Thu, 22 May 2014 14:16:12 GMT
< Host: localhost:9999
< User-Agent: curl/7.36.0
< Transfer-Encoding: chunked
* Server Jetty(8.1.14.v20131031) is not blacklisted
< Server: Jetty(8.1.14.v20131031)
< 
* Connection #0 to host localhost left intact
{"customers":{"customers":{"address":"Japan","name":"Ken"}}}
{noformat}

I get a reponse as a JSON format. It's OK!

But if "Content-Type: application/xml"  specified,

{norformat}
$ LANG=C curl  -H "Accept: application/json"  -H "Content-Type: application/xml" http://localhost:9999/rsServer/customer/ -v
* Hostname was NOT found in DNS cache
*   Trying ::1...
* connect to ::1 port 9999 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9999 (#0)
> GET /rsServer/customer/ HTTP/1.1
> User-Agent: curl/7.36.0
> Host: localhost:9999
> Accept: application/json
> Content-Type: application/xml
> 
< HTTP/1.1 200 OK
< Accept: application/json
< breadcrumbId: ID-emilia-46343-1400768103395-0-9
< Content-Type: application/xml
< Date: Thu, 22 May 2014 14:19:17 GMT
< Host: localhost:9999
< User-Agent: curl/7.36.0
< Transfer-Encoding: chunked
* Server Jetty(8.1.14.v20131031) is not blacklisted
< Server: Jetty(8.1.14.v20131031)
< 
* Connection #0 to host localhost left intact
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><customers><customers><address>Japan</address><name>Ken</name></customers></customers>
{norformat}

I got a response as a xml format. It should be JSON format.

 



--
This message was sent by Atlassian JIRA
(v6.2#6252)