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

cxf:rsServer requires class instead of interface in the serviceClass attribute

    XMLWordPrintableJSON

Details

    Description

      Here are part of the conversation from the mailing list:

      1.

      Hi there,

      I'm using apache-servicemix-4.3.1-fuse-01-09 and I need to consume RESTful requests.
      Here is the documentation I have used: http://camel.apache.org/cxfrs.html
      Here is my configuration file

      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:jaxrs="http://cxf.apache.org/jaxrs"
      xmlns:cxf="http://camel.apache.org/schema/cxf"
      xsi:schemaLocation="
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
      http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
      http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
      ">
      <import resource="classpath:META-INF/cxf/cxf.xml" />
      <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
      <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
      <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />

      <cxf:rsServer id="myServer" address="/" serviceClass="org.test.MyService" />

      <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
      <route>
      <from uri="cxfrs://bean:myServer?exchangePattern=InOut"/>
      <transform>
      <constant>Hello World!!!</constant>
      </transform>
      </route>
      </camelContext>
      </beans>

      Here is implementation of org.test.MyService

      @Path("/service")
      @Produces("application/json")
      public class MyService {

      @POST
      @Path("/resource")
      public Response add(@QueryParam("res") String res)

      { return Response.ok(new Status("The Resource has been processed")).build(); }

      }

      I'm wondering why we have to specify the serviceClass attribute and why this attribute should point at the real class. I'm asking because the response of such a service will always be "Hello World!!!" and implementation of MyService.add method does not matter in that case.

      2.

      Hi Ben,

      You are right, the serviceClass is just used to build up the JAXRS service module. And Camel CXF RS Consumer doesn't all serviceClass instance at the end, it just route the request to the camel route.

      3.

      Hi Willem, Ben

      Thanks for the information.
      I tried to use the interface instead of class in the serviceClass attribute and I didn't succeed because of an exception that told that the class is required.
      Here is the exception:

      Caused by: java.lang.RuntimeException: Resource class interface org.test.MyService has no valid constructor
      at org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider.<init>(PerRequestResourceProvider.java:45)
      at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:338)
      at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:119)
      ... 26 more

      I think that using an interface would be better in that case.

      Attachments

        Activity

          People

            njiang Willem Jiang
            szhemzhitsky Sergey Zhemzhitsky
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: