0

我正在尝试使用 apache camel 开发休息服务。我的项目是部署在tomcat上的spring mvc war。

我不想使用 apache cxf (cxf servlet)。

        public class SampleRouter extends RouteBuilder {

            @override
            public void configure() throws Exception {
                from("cxfrs://http://localhost:1234/sample")
                .process (new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("test");
                    }
                })).setBody(constant("SUCCESS"));
            }
        }


        @Path("/sample")
        public class SampleResource {

            @GET
            public void test() {

            }
        }

web.xml 有 dispatcherservlet、contextloaderlistener。

dispatcher-servlet.xml 有 mvc:annotation-drivem, context:component-scan,

        <camelContext id="server" trace="true" xmlns="http://camel.apache.org/schema/spring">
            <contextScan />
        </camelContext>

pom.xml 有camel-core、camel-cxf、camel-stream、cxf-rt-transports-http-jetty、cxf-rs-frontend-jaxrs、camel-spring、spring-webmvc、spring-web、spring-context。

Tomcat 运行在 8080 上,服务器启动时似乎也不例外。但是,我尝试点击 url ( http://localhost:1234/sample),似乎没有发生任何事情。

我错过了什么?我最终会将其扩展到带有身份验证、过滤器和拦截器的 REST 到 Spring DSL 或 REST 到 Java DSL。

我还尝试了 cxf:rsServer 并在路由器类中引用了它。

另外,将来我是否必须使用 https 而不是 http?或者我如何让 url 没有硬编码?

4

3 回答 3

1

可能为时已晚,但要消费 HTTP 请求,可以使用 Apache Camel Servlet 组件

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

于 2015-01-11T08:39:31.190 回答
0

如果您希望通过使用 servlet 传输的消费 cxf 休息服务来启动骆驼路线,那么您需要:

  1. 清理你的 pom.xml 并删除对码头的任何引用。
  2. 将 CXF servlet 添加到您的 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. 添加 servlet-transport 依赖项:

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf-version}</version>
     </dependency>
    
  4. 在你的 spring/camel 配置中

    <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. 从此消费者端点构建路由:

    from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer")
        .to("log:TEST?showAll=true")
    
  6. 您现在可以使用以下命令查看/(使用方法调用)端点:http://host:port/context/services/restService?_wadl

于 2014-03-22T15:37:33.673 回答
0

您需要在 cxfrs 端点上设置 resourceClass 选项。这是一个例子

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

您可以在camel-cxfrs 组件页面中找到一些示例。

如果你想通过servlet传输导出一个CXF服务,你需要按照说的做一些工作。

如果要动态更改地址,可以查看骆驼属性组件。

于 2014-03-05T06:30:16.303 回答