Apache Camel + Spring (war) + Tomcat + REST

做~自己de王妃 提交于 2019-12-02 13:08:43

It may be too late, but to consume HTTP requests, one may use Apache Camel Servlet component

http://camel.apache.org/servlet.html

You need to setup the resourceClass option on the cxfrs endpoint. Here is an example

from("cxfrs://http://localhost:1234/sample?resourceClasses=my.pachage.SampleResource")

You can find some example in camel-cxfrs component page.

If you want to export a CXF service through servlet transport, you need to do some work as it said.

If you want to change the address dynamically, you can take look at the camel properties component.

If you are looking to start a camel route by a consuming cxf rest service which uses the servlet transport then you need to :

  1. Clean up your pom.xml and remove any references to jetty.
  2. Add the CXF servlet to your web.xml

    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <!-- all our webservices are mapped under this URI pattern -->
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
    
  3. Add the servlet-transport dependency:

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf-version}</version>
     </dependency>
    
  4. In your spring/camel configuration

    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
    
    <cxf:rsServer id="rsServer" address="/restService"
     serviceClass="com.something.test.SimpleServiceImpl"
     loggingFeatureEnabled="true" loggingSizeLimit="20" />
    
  5. Build a route from this consumer endpoint as:

    from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer")
        .to("log:TEST?showAll=true")
    
  6. You can now view/(invoke with a method) the endpoint using : http://host:port/context/services/restService?_wadl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!