Camel
  1. Camel
  2. CAMEL-4014

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

    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.

        Activity

        Sergey Zhemzhitsky created issue -
        Willem Jiang made changes -
        Field Original Value New Value
        Assignee Willem Jiang [ njiang ]
        Hide
        Claus Ibsen added a comment -

        Any update on this?

        Show
        Claus Ibsen added a comment - Any update on this?
        Hide
        Willem Jiang added a comment -

        @Claus, I will work on this issue next week.

        Show
        Willem Jiang added a comment - @Claus, I will work on this issue next week.
        Willem Ning Jiang <ningjiang@apache.org> committed 2eef4d7fb94825a66439d8d56687cc54d9b074a5 (2 files)
        Reviews: none

        Merged revisions 1360041 via svnmerge from https://svn.apache.org/repos/asf/camel/branches/camel-2.10.x
        ................
          r1360041 | ningjiang | 2012-07-11 15:44:09 +0800 (Wed, 11 Jul 2012) | 9 lines
          
          Merged revisions 1360031 via svnmerge from
          https://svn.apache.org/repos/asf/camel/trunk
          
          ........
            r1360031 | ningjiang | 2012-07-11 14:31:35 +0800 (Wed, 11 Jul 2012) | 1 line
            
            CAMEL-4014 supports to use Interface as the service class
          ........
        ................


        git-svn-id: https://svn.apache.org/repos/asf/camel/branches/camel-2.9.x@1360057 13f79535-47bb-0310-9956-ffa450edef68

        ningjiang committed 1360057 (4 files)
        Reviews: none

        Merged revisions 1360041 via svnmerge from
        https://svn.apache.org/repos/asf/camel/branches/camel-2.10.x

        ................
          r1360041 | ningjiang | 2012-07-11 15:44:09 +0800 (Wed, 11 Jul 2012) | 9 lines
          
          Merged revisions 1360031 via svnmerge from
          https://svn.apache.org/repos/asf/camel/trunk
          
          ........
            r1360031 | ningjiang | 2012-07-11 14:31:35 +0800 (Wed, 11 Jul 2012) | 1 line
            
            CAMEL-4014 supports to use Interface as the service class
          ........
        ................

        Willem Ning Jiang <ningjiang@apache.org> committed f0b7fe8195deb1c76bf867651ddc230bba048cd9 (1 file)
        Reviews: none

        CAMEL-4014 remove the System.out.println from SubResourceClassInvocationHandler
        git-svn-id: https://svn.apache.org/repos/asf/camel/trunk@1360719 13f79535-47bb-0310-9956-ffa450edef68

        ningjiang committed 1360719 (1 file)
        Willem Ning Jiang <ningjiang@apache.org> committed 8c09ae77b2523d0c0c2993adf5b21ef8d21de958 (1 file)
        Reviews: none

        Merged revisions 1360719 via svnmerge from https://svn.apache.org/repos/asf/camel/trunk
        ........
          r1360719 | ningjiang | 2012-07-12 23:18:24 +0800 (Thu, 12 Jul 2012) | 1 line
          
          CAMEL-4014 remove the System.out.println from SubResourceClassInvocationHandler
        ........


        git-svn-id: https://svn.apache.org/repos/asf/camel/branches/camel-2.10.x@1360727 13f79535-47bb-0310-9956-ffa450edef68

        ningjiang committed 1360727 (2 files)
        Reviews: none

        Merged revisions 1360719 via svnmerge from
        https://svn.apache.org/repos/asf/camel/trunk

        ........
          r1360719 | ningjiang | 2012-07-12 23:18:24 +0800 (Thu, 12 Jul 2012) | 1 line
          
          CAMEL-4014 remove the System.out.println from SubResourceClassInvocationHandler
        ........

        Willem Ning Jiang <ningjiang@apache.org> committed 791fa4bbbaee57eaeb34a9b1fc9dd3d39463fa16 (1 file)
        Reviews: none

        Merged revisions 1360727 via svnmerge from https://svn.apache.org/repos/asf/camel/branches/camel-2.10.x
        ................
          r1360727 | ningjiang | 2012-07-12 23:27:24 +0800 (Thu, 12 Jul 2012) | 9 lines
          
          Merged revisions 1360719 via svnmerge from
          https://svn.apache.org/repos/asf/camel/trunk
          
          ........
            r1360719 | ningjiang | 2012-07-12 23:18:24 +0800 (Thu, 12 Jul 2012) | 1 line
            
            CAMEL-4014 remove the System.out.println from SubResourceClassInvocationHandler
          ........
        ................


        git-svn-id: https://svn.apache.org/repos/asf/camel/branches/camel-2.9.x@1360741 13f79535-47bb-0310-9956-ffa450edef68

        ningjiang committed 1360741 (2 files)
        Reviews: none

        Merged revisions 1360727 via svnmerge from
        https://svn.apache.org/repos/asf/camel/branches/camel-2.10.x

        ................
          r1360727 | ningjiang | 2012-07-12 23:27:24 +0800 (Thu, 12 Jul 2012) | 9 lines
          
          Merged revisions 1360719 via svnmerge from
          https://svn.apache.org/repos/asf/camel/trunk
          
          ........
            r1360719 | ningjiang | 2012-07-12 23:18:24 +0800 (Thu, 12 Jul 2012) | 1 line
            
            CAMEL-4014 remove the System.out.println from SubResourceClassInvocationHandler
          ........
        ................

        Hide
        Willem Jiang added a comment -

        Applied the patch into trunk, 2.10.x and 2.9.x branches.

        Show
        Willem Jiang added a comment - Applied the patch into trunk, 2.10.x and 2.9.x branches.
        Willem Jiang made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.9.3 [ 12320750 ]
        Fix Version/s 2.10.1 [ 12321259 ]
        Fix Version/s 2.11 [ 12321695 ]
        Resolution Fixed [ 1 ]
        Hide
        Jason Chaffee added a comment -

        I just tried this on 2.10.3 and I still get the "Resource class interface org.test.MyService has no valid constructor" error.

        Show
        Jason Chaffee added a comment - I just tried this on 2.10.3 and I still get the "Resource class interface org.test.MyService has no valid constructor" error.
        Hide
        François Fornaciari added a comment -

        I also tried with the 2.10.3 version and the issue is still there. Any update on this?

        Show
        François Fornaciari added a comment - I also tried with the 2.10.3 version and the issue is still there. Any update on this?
        Hide
        Jason Chaffee added a comment -

        I am wondering if a new issue needs to be created as there has been no response from anyone on this.

        Show
        Jason Chaffee added a comment - I am wondering if a new issue needs to be created as there has been no response from anyone on this.
        Hide
        Jason Chaffee added a comment -

        Created a new Issue that references this one. Hopefully, someone will either reopen this and mark that as a dup, or just start work on that one.

        See Issue CAMEL-6014

        Show
        Jason Chaffee added a comment - Created a new Issue that references this one. Hopefully, someone will either reopen this and mark that as a dup, or just start work on that one. See Issue CAMEL-6014
        Hide
        Willem Jiang added a comment -

        Can you submit a simple test case for it?

        Show
        Willem Jiang added a comment - Can you submit a simple test case for it?
        Hide
        Jason Chaffee added a comment -

        I get this error:

        Resource class interface org.test.MyService has no valid constructor.

        Show
        Jason Chaffee added a comment - I get this error: Resource class interface org.test.MyService has no valid constructor.
        Hide
        Willem Jiang added a comment -

        Hi Jason,

        Please check out the unit test[1] in the camel-cxf trunk, the CustomerServiceResource is an interface.

        [1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java

        Show
        Willem Jiang added a comment - Hi Jason, Please check out the unit test [1] in the camel-cxf trunk, the CustomerServiceResource is an interface. [1] https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
        Hide
        François Fornaciari added a comment -

        The CxfRsConsumerTest uses the CXF Endpoint URI "cxfrs://http://host:port/path?resourceClasses=Interface" which is actually working for interfaces.
        But the error occurs when declaring a "cxf:rsServer" as described is this issue.

        The logic behind these two declarations is probably different.

        Show
        François Fornaciari added a comment - The CxfRsConsumerTest uses the CXF Endpoint URI "cxfrs:// http://host:port/path?resourceClasses=Interface " which is actually working for interfaces. But the error occurs when declaring a "cxf:rsServer" as described is this issue. The logic behind these two declarations is probably different.

          People

          • Assignee:
            Willem Jiang
            Reporter:
            Sergey Zhemzhitsky
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development