4

我有想要作为 REST Web 服务公开的骆驼路线。应用程序部署在 Web 容器(Jetty/Tomcat)上,Spring 也用于 DI 和其他“基础设施”事物。

我查看了camel-restletcamel-cxfrs组件,虽然它们都支持将路由公开为 REST 服务,但我无法找到如何避免启动单独的服务器。我真正想要的是能够以类似于为 Spring-WS 入站端点定义路由的方式定义 Camel 路由,例如

from("restlet://application/user/{id}").to(...)

Web 应用程序的配置应该负责接受请求并将它们传输到适当的端点。

不得不承认,我很惊讶我无法找到有关该主题的足够信息,而且我认为我的要求并不是很奇特。

4

2 回答 2

5

请参阅此示例 http://camel.apache.org/cxf-tomcat-example.html

对于 Apache CXF,您可以使用 servlet 传输,它允许您利用 Tomcat/Jetty 作为主机容器。

如果您使用 OSGi,请查看以下内容: http ://camel.apache.org/cxf-example-osgi.html 它显示了如何将 CXF 与 OSGi HTTP 服务一起使用,这对于 CXFRS 应该也适用。

于 2011-04-14T15:54:01.297 回答
3

这是一个迟到的答案,但可能对其他人有所帮助。

Apache Camel 现在似乎支持使用主机容器(例如 Tomcat/Jetty)公开 Restlet Web 服务

==============8<snip snip =========================

在 webapp 中使用 Restlet servlet

从 Camel 2.8 开始可用 在 servlet 容器中配置 Restlet 应用程序有三种可能的方法,使用子类 SpringServerServlet 可以通过注入 Restlet 组件在 Camel 中进行配置。在 servlet 容器中使用 Restlet servlet 可以使用 URI 中的相对路径配置路由(消除硬编码的绝对 URI 的限制),并允许托管 servlet 容器处理传入请求(而不是必须生成单独的服务器进程在新端口上)。要进行配置,请将以下内容添加到您的 camel-context.xml;

<camelContext>
  <route id="RS_RestletDemo">
    <from uri="restlet:/demo/{id}" />
    <transform>
      <simple>Request type : ${header.CamelHttpMethod} and ID : ${header.id}</simple>
    </transform>
  </route> 
</camelContext>



<bean id="RestletComponent" class="org.restlet.Component" />

<bean id="RestletComponentService" class="org.apache.camel.component.restlet.RestletComponent">
  <constructor-arg index="0">
    <ref bean="RestletComponent" />
  </constructor-arg>
</bean>
And add this to your web.xml;
<!-- Restlet Servlet -->
<servlet>
  <servlet-name>RestletServlet</servlet-name>
  <servlet-class>org.restlet.ext.spring.SpringServerServlet</servlet-class>
  <init-param>
    <param-name>org.restlet.component</param-name>
    <param-value>RestletComponent</param-value>
  </init-param>
</servlet>

<servlet-mapping>
  <servlet-name>RestletServlet</servlet-name>
  <url-pattern>/rs/*</url-pattern>
</servlet-mapping>

然后,您将能够访问已部署的路线

http://localhost:8080/mywebapp/rs/demo/1234

where localhost:8080 is the server and port of your servlet container

============== 剪断 >8 =========================

此信息于2014 年 1 月 16 日在http://camel.apache.org/restlet.html的底部找到

于 2014-01-16T19:28:45.553 回答