camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Seiji Sogabe (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (CAMEL-7457) [camel-cxf] cxfrs: SimpleConsumer does not honur Accept header
Date Thu, 22 May 2014 14:31:02 GMT

     [ https://issues.apache.org/jira/browse/CAMEL-7457?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Seiji Sogabe updated CAMEL-7457:
--------------------------------

    Description: 
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}

A) 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 got a reponse as a JSON format. It's OK!*

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

{noformat}
$ 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>
{noformat}

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

C) replace SimpleConsumer with Default style.
( (2) in spring.xml)

{noformat}
 $ 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
< Content-Type: application/json
< Date: Thu, 22 May 2014 14:27:19 GMT
< 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}

*It's OK without bindingStyle option.*

  was:
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}

A) 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 got a reponse as a JSON format. It's OK!

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

{noformat}
$ 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>
{noformat}

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

C) replace SimpleConsumer with Default style.
( (2) in spring.xml)

{noformat}
 $ 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
< Content-Type: application/json
< Date: Thu, 22 May 2014 14:27:19 GMT
< 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}

 It's OK without bindingtyle option.


> [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}
> A) 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 got a reponse as a JSON format. It's OK!*
> B) But if "Content-Type: application/xml"  specified,
> {noformat}
> $ 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>
> {noformat}
> *I got a response as a xml format. It should be JSON format.*
> C) replace SimpleConsumer with Default style.
> ( (2) in spring.xml)
> {noformat}
>  $ 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
> < Content-Type: application/json
> < Date: Thu, 22 May 2014 14:27:19 GMT
> < 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}
> *It's OK without bindingStyle option.*



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

Mime
View raw message