1

2つのCamelサーブレットベースのAPI(2つのOSGiバンドル)を作成しようとしています。私はthis exampleのようにブループリントXMLを使用しています。Apache CamelブループリントベースのOSGiバンドルでDuplicate ServletNameが検出されました

これらの2つの青写真XMLS、

<?xml version="1.0" encoding="UTF-8"?> 
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation=" 
      http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> 
    <reference id="httpService" interface="org.osgi.service.http.HttpService"/> 

    <bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer" 
     init-method="register" 
     destroy-method="unregister"> 
    <property name="alias" value="/digital"/> 
    <property name="httpService" ref="httpService"/> 
    <property name="servlet" ref="teamCamelServlet"/> 
    </bean> 

    <bean id="teamCamelServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/> 

    <bean id="teamService" class="com.test.TeamService"/> 

    <camelContext xmlns="http://camel.apache.org/schema/blueprint"> 

    <restConfiguration component="servlet" bindingMode="json" contextPath="/digital" 
         port="8181"> 
     <dataFormatProperty key="prettyPrint" value="true"/> 
    </restConfiguration> 

    <rest path="/team" consumes="application/json" produces="application/json"> 
    ..content omitted 
    </rest> 

    </camelContext> 

</blueprint> 

blueprint.xmlです:

<?xml version="1.0" encoding="UTF-8"?> 
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation=" 
      http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> 

    <reference id="httpService" interface="org.osgi.service.http.HttpService"/> 

    <bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer" 
     init-method="register" 
     destroy-method="unregister"> 
    <property name="alias" value="/api"/> 
    <property name="httpService" ref="httpService"/> 
    <property name="servlet" ref="camelServlet"/> 
    </bean> 

    <bean id="camelServlet" class="org.apache.camel.component.servlet.CamelHttpTransportServlet"/> 

    <bean id="helloService" class="com.test.HelloService"/> 

    <camelContext xmlns="http://camel.apache.org/schema/blueprint"> 

    <restConfiguration component="servlet" bindingMode="json" contextPath="/api" 
         port="8181"> 
     <dataFormatProperty key="prettyPrint" value="true"/> 
    </restConfiguration> 

    <!-- defines the rest services using the context-path /user --> 
    <rest path="/hello" consumes="application/json" produces="application/json"> 
    ..content omitted 
    </rest> 

    </camelContext> 

</blueprint> 

しかし、私は、このエラーメッセージが表示されます:私はここで間違って何を

javax.servlet.ServletException: Duplicate ServletName detected: CamelServlet. Existing: CamelHttpTransportServlet[name=CamelServlet] This: CamelHttpTransportServlet[name=CamelServlet]. Its advised to use unique ServletName per Camel application. 

をやっていますか?私はこれら2つのOSGiバンドルをApache ServiceMixで実行しようとしています。そのうちの1つが展開されていれば、正常に動作しています。両方が展開されている場合、最初のものだけが動作しています。私はApache Camelを初めて使用しています。私はServiceMixを再起動しようとしましたが、運はありません。また、バンドルキャッシュをクリアして試しました。

+0

両方のバンドルに完全なblueprint.xmlを追加できますか? – stringy05

+0

私はあなたが両方のサーブレット定義でポートを宣言したかもしれないと思います。 pax webサーブレットを使用する方が良いです(cxfservletでポートを削除するだけですが、残りの構成コンポーネントでこれを行う方法がわかりません) – stringy05

+0

@ stringy05ありがとうございます。ところで、ポートバインディングの問題については不平を言っていません。他のサーブレットコンポーネントと何が起こるか –

答えて

0

OsgiServletRegistererは、CamelHttpTransportServletを登録しているときに、デフォルトのサーブレット名として "CamelServlet"を使用します。

両方のバンドルで、デフォルト名で登録しようとしています。それがあなたにエラーを起こしている理由です。

<property name="servletName" value="helloCamelServlet"/> 

EDITを次のようにOsgiServletRegisterer豆に異なるservletNameを設定してみてください:のようないくつかのことを試してみてください。この

<bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer" 
     init-method="register" 
     destroy-method="unregister"> 
    <property name="alias" value="/digital"/> 
    <property name="httpService" ref="httpService"/> 
    <property name="servlet" ref="teamCamelServlet"/> 
    <property name="servletName" value="teamCamelServlet"/> 
    </bean> 
+0

helloServlet'が、私はこの問題 'org.osgi.service.blueprint.container.ComponentDefinitionExceptionだ'として私はnameプロパティを使用:どのクラスorg.apache.camel.component.servlet.osgi.OsgiServletRegisterer'にプロパティ記述子helloServletを見つけることができませんなぜなら[OsgiServletRegistererのソース]の明らかなようである(https://github.com/apache/camel/blob/master/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/osgi /OsgiServletRegisterer.java)。どんなアイデアが起こっているの? –

+0

OsgiServletRegistere rの「helloServlet」と呼ばれる何のプロパティ/変数がありません。 – ravthiru

+0

ああ、私はあなたの意見を持って、私はこれで試してみます。ありがとう。 –

2
CamelHttpTransportServletが同じ名前で登録する2つのサーブレットを設立すると、それが例外をスローし

」重複したServletNameが検出されました... "。

例では、OsgiServletRegistererのプロパティ "servletName"は設定されていないため、登録者クラスはデフォルト値 "CamelServlet"を使用します。

さらに、何かがあります。ラクダの休憩設定では、使用するサーブレットに関する情報をcamelに提供するために、追加のエンドポイントプロパティを宣言する必要があります(デフォルトでは "CamelServlet"が使用されます)。

だから、あなたのcoufigurationは次のようにあるべき二つの別々のサーブレットを起動します。

登録元のBean構成:

<bean class="org.apache.camel.component.servlet.osgi.OsgiServletRegisterer" 
     init-method="register" 
     destroy-method="unregister"> 
    <property name="alias" value="/digital"/> 
    <property name="httpService" ref="httpService"/> 
    <property name="servlet" ref="teamCamelServlet"/> 
    <property name="servletName" value="teamCamelServlet"/> 
</bean> 

キャメルの残りの設定:

<restConfiguration component="servlet" bindingMode="json" contextPath="/digital" port="8181"> 
    <endpointProperty key="servletName" value="teamCamelServlet"/> 
    <dataFormatProperty key="prettyPrint" value="true"/> 
</restConfiguration> 

このソリューションは、ラクダ2.14のために働く必要があります.1以上

バージョン2.14.0には、バグのため、解決策は動作しません。 https://issues.apache.org/jira/browse/CAMEL-7971

+0

答えをありがとう、私はあなたのソリューションを試してみます。 –

関連する問題