【问题标题】:Multiple JAXRS Bean with one Jetty Endpoint具有一个 Jetty 端点的多个 JAXRS Bean
【发布时间】:2013-07-26 00:15:51
【问题描述】:

谁能帮助我配置两个具有相同基本 URI 和 Apache FUSE ESB 的 JAX-RS 服务?我正在使用带有 karaf 容器、Apache Camel 和 CXF (JAX-RS) 的 JBoss FUSE 6.0 版本。配置是使用蓝图完成的。当我只配置一个 JAX-RS 服务时,一切正常。

我正在尝试使用基本 URI http://localhost:9001/rs 提供两个 JAX-RS Bean。第一个bean为http://localhost:9001/rs/rest1,第二个为http://locahost:9001/rs/rest2

我已经用码头端点定义了两个骆驼上下文。我想我需要两个只使用一个配置的实例,但无法弄清楚如何做到这一点。

这是我的骆驼语境:

<camel:camelContext id="context1">
    <camel:endpoint id="ep1" uri="jetty:http://localhost:9001/rs/?matchOnUriPrefix=true"/>
    <camel:route autoStartup="true">
        <camel:from uri="ep1"/>
        <camel:to uri="cxfbean:restBean1"/>
        <camel:log message="Message received after REST Processor. "/>
        <camel:convertBodyTo type="java.lang.String"/>
        <camel:to uri="log:loggingCategory?level=INFO"/>
    </camel:route>
</camel:camelContext>

<camel:camelContext id="context2">
    <camel:endpoint id="ep2" uri="jetty:http://localhost:9001/rs/?matchOnUriPrefix=true"/>
    <camel:route autoStartup="true">
        <camel:from uri="ep2"/>
        <camel:to uri="cxfbean:restBean2"/>
        <camel:log message="Message received after REST Processor. "/>
        <camel:convertBodyTo type="java.lang.String"/>
        <camel:to uri="log:loggingCategory?level=INFO"/>
    </camel:route>
</camel:camelContext>

两个 Bean 都作为服务引用注入,当我评论其中一条路由时,一切正常。

有什么建议可以在骆驼中配置吗?

干杯, 奥利弗

【问题讨论】:

    标签: jetty jax-rs apache-camel blueprint-osgi


    【解决方案1】:

    这两个码头端点应该是唯一的,例如你有两个 /rs/ 应该是

     <camel:endpoint id="ep1" uri="jetty:http://localhost:9001/rs/rest1/?matchOnUriPrefix=true"/>
    
     <camel:endpoint id="ep2" uri="jetty:http://localhost:9001/rs/rest2/?matchOnUriPrefix=true"/>
    

    【讨论】:

    • 嗨。我认为使这项工作的解决方法将是两个端点,其中包含 bean 的路径并将 Bean 路径设置为“/”。这适用于我的设置。
    【解决方案2】:

    我用两个端点解决了这个问题

    <camel:endpoint id="ep1" uri="jetty:http://localhost:9001/rs/rest1/?matchOnUriPrefix=true"/>
    <camel:endpoint id="ep2" uri="jetty:http://localhost:9001/rs/rest2/?matchOnUriPrefix=true"/>
    

    REST Beans 现在使用@Path("/")。 现在所有 REST Bean 都有正确的路径。

    接下来我需要测试的是如何将我的两个端点与我的 Web 应用程序包放在同一个 URL 上。

    谢谢!

    【讨论】:

      猜你喜欢
      • 2016-07-11
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多