Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-12541

camel-cxfrs - rsClient does not work programmatically, only with XML

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.21.1
    • 2.20.4, 2.21.2, 2.22.0
    • camel-cxfrs
    • None
    • Unknown

    Description

      As described in the documentation you can use camel-cxfrs as producer. You have some approaches like using a proxy created from a interface which maps all the services available in the targeted REST web service (sample here). As I'm using Spring Boot and Apache Camel I may create a bean through XML or programmatically.

      Creating the test sample

      I'm testing with the following:

      https://gist.github.com/willianantunes/58979bfb91ee30c7ff4e235940e60880

      You can find a copy of JarbasAPI here.

      When rsClient producer works as expected

      When I do using the first approach using the configuration below everything works fine:

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:cxf="http://camel.apache.org/schema/cxf"
             xmlns:jaxrs="http://cxf.apache.org/jaxrs"
             xmlns:util="http://www.springframework.org/schema/util"
             xsi:schemaLocation="
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
             http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
             http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
             http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
             http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
      
          <cxf:rsClient id="serviceEndpointViaXML"
                        address="https://jarbas.serenata.ai" 
                        serviceClass="br.com.willianantunes.serenata.JarbasAPI"/>
      </beans>
      

      When rsClient producer does not work as expected

      XML works fine, but when I do the same thing programmatically it doesn't.

          @Bean("serviceEndpoint")
          public SpringJAXRSClientFactoryBean serviceEndpoint() {
      
              SpringJAXRSClientFactoryBean clientFactoryBean = new SpringJAXRSClientFactoryBean();
              clientFactoryBean.setAddress("https://jarbas.serenata.ai");
              clientFactoryBean.setServiceClass(JarbasAPI.class);
      
              return clientFactoryBean;
          }
      

      Although it has no difference compared to XML, it does not work.

      When does it fail?

      Debugging you can see the following:

      • The bean is correctly got here is CxfRsComponent.
      • When a message is sent and there is a to command with the URI cxfrs:bean:serviceEndpoint, I see the message arriving here in CxfRsProducer.
      • The method invokeProxyClient is called.
      • The SpringJAXRSClientFactoryBean which I provided as bean is ignored. A new one is created here and when it arrives to the next line the method invoked is from CxfRsSpringEndpoint which uses configurer.ConfigureBean that only works with XML.

      Versions used

      • Spring Boot: 1.5.12.RELEASE
      • Apache Camel: 2.21.1

      Proposal to make it works

      The idea obviously is to make both approaches work, maybe merging the configuration or as long as the user is providing a custom SpringJAXRSClientFactoryBean then making it the standard instead of creating a new one for each request as it is available in the CxfRsSpringEndpoint from the start.


      If you want to understand more, read from here until the end of conversation on Gitter.

      Attachments

        Activity

          People

            Willian Antunes Willian Antunes
            Willian Antunes Willian Antunes
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: