2016-10-08 3 views
0

InterceptFrom機能を使用してApache Camel Routesにキャッシングアスペクトを適用するには、ルート内のすべての着信交換を傍受します。InterceptFromを使用してキャメルルートにキャッシングアスペクトを適用する

現在、RestDefinitionsとRouteDefinitionsを別々のXMLファイルから正常に読み込むことができます。

同様の方法で、別のXMLファイルからインターセプト定義を読み込みたいとします。

私は現在、以下のようにInterceptFrom定義を読み込むために使用するxml(Intercept.xml)ファイルに次のコンテンツを持っています。私は今の時点でしかログに記録しません。キャッシュのヒット/ミスを最終的にチェックするロジックを追加します。

<interceptFrom> 
     <log message="Intercepted Route" /> 
    </interceptFrom> 

私はまた、ルートにそれらを設定し、以下の方法を使用して

List<InterceptFromDefinition> intDefns=getInterceptDefinitions("Intercept.xml"); 

それらをロードしています。

routes.setInterceptFroms(intDefns); 

私は以下のようにエラーを取得し、

2016-10-08 22:13:19.711 ERROR 6004 --- [   main] com.demo.composite.util.CamelUtil  : Exception reading configuration files:javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"interceptFrom"). Expected elements are <{http://camel.apache.org/schema/spring}aggregate>,<{http://camel.apache.org/schema/spring}aop>,<{http://camel.apache.org/schema/spring}avro>,<{http://camel.apache.org/schema/spring}barcode>,<{http://camel.apache.org/schema/spring}base64>,<{http://camel.apache.org/schema/spring}batch-config>,<{http://camel.apache.org/schema/spring}bean>,<{http://camel.apache.org/schema/spring}beanio>,<{http://camel.apache.org/schema/spring}bindy>,<{http://camel.apache.org/schema/spring}boon>,<{http://camel.apache.org/schema/spring}castor>,<{http://camel.apache.org/schema/spring}choice>,<{http://camel.apache.org/schema/spring}circuitBreaker>,<{http://camel.apache.org/schema/spring}constant>,<{http://camel.apache.org/schema/spring}contextScan>,<{http://camel.apache.org/schema/spring}convertBodyTo>,<{http://camel.apache.org/schema/spring}crypto>,<{http://camel.apache.org/schema/spring}csv>,<{http://camel.apache.org/schema/spring}customDataFormat>,<{http://camel.apache.org/schema/spring}customLoadBalancer>,<{http://camel.apache.org/schema/spring}dataFormats>,<{http://camel.apache.org/schema/spring}delay>,<{http://camel.apache.org/schema/spring}delete>,<{http://camel.apache.org/schema/spring}description>,<{http://camel.apache.org/schema/spring}doCatch>,<{http://camel.apache.org/schema/spring}doFinally>,<{http://camel.apache.org/schema/spring}doTry>,<{http://camel.apache.org/schema/spring}dynamicRouter>,<{http://camel.apache.org/schema/spring}el>,<{http://camel.apache.org/schema/spring}enrich>,<{http://camel.apache.org/schema/spring}exchangeProperty>,<{http://camel.apache.org/schema/spring}expression>,<{http://camel.apache.org/schema/spring}expressionDefinition>,<{http://camel.apache.org/schema/spring}failover>,<{http://camel.apache.org/schema/spring}filter>,<{http://camel.apache.org/schema/spring}flatpack>,<{http://camel.apache.org/schema/spring}from>,<{http://camel.apache.org/schema/spring}get>,<{http://camel.apache.org/schema/spring}groovy>,<{http://camel.apache.org/schema/spring}gzip>,<{http://camel.apache.org/schema/spring}head>,<{http://camel.apache.org/schema/spring}header>,<{http://camel.apache.org/schema/spring}hessian>,<{http://camel.apache.org/schema/spring}hl7>,<{http://camel.apache.org/schema/spring}ical>,<{http://camel.apache.org/schema/spring}idempotentConsumer>,<{http://camel.apache.org/schema/spring}inOnly>,<{http://camel.apache.org/schema/spring}inOut>,<{http://camel.apache.org/schema/spring}intercept>,<{http://camel.apache.org/schema/spring}interceptFrom>,<{http://camel.apache.org/schema/spring}interceptSendToEndpoint>,<{http://camel.apache.org/schema/spring}jacksonxml>,<{http://camel.apache.org/schema/spring}javaScript>,<{http://camel.apache.org/schema/spring}jaxb>,<{http://camel.apache.org/schema/spring}jibx>,<{http://camel.apache.org/schema/spring}json>,<{http://camel.apache.org/schema/spring}jsonpath>,<{http://camel.apache.org/schema/spring}jxpath>,<{http://camel.apache.org/schema/spring}language>,<{http://camel.apache.org/schema/spring}loadBalance>,<{http://camel.apache.org/schema/spring}log>,<{http://camel.apache.org/schema/spring}loop>,<{http://camel.apache.org/schema/spring}lzf>,<{http://camel.apache.org/schema/spring}marshal>,<{http://camel.apache.org/schema/spring}method>,<{http://camel.apache.org/schema/spring}mime-multipart>,<{http://camel.apache.org/schema/spring}multicast>,<{http://camel.apache.org/schema/spring}mvel>,<{http://camel.apache.org/schema/spring}ognl>,<{http://camel.apache.org/schema/spring}onCompletion>,<{http://camel.apache.org/schema/spring}onException>,<{http://camel.apache.org/schema/spring}optimisticLockRetryPolicy>,<{http://camel.apache.org/schema/spring}options>,<{http://camel.apache.org/schema/spring}otherwise>,<{http://camel.apache.org/schema/spring}packageScan>,<{http://camel.apache.org/schema/spring}param>,<{http://camel.apache.org/schema/spring}patch>,<{http://camel.apache.org/schema/spring}pgp>,<{http://camel.apache.org/schema/spring}php>,<{http://camel.apache.org/schema/spring}pipeline>,<{http://camel.apache.org/schema/spring}policy>,<{http://camel.apache.org/schema/spring}pollEnrich>,<{http://camel.apache.org/schema/spring}post>,<{http://camel.apache.org/schema/spring}process>,<{http://camel.apache.org/schema/spring}properties>,<{http://camel.apache.org/schema/spring}property>,<{http://camel.apache.org/schema/spring}protobuf>,<{http://camel.apache.org/schema/spring}put>,<{http://camel.apache.org/schema/spring}python>,<{http://camel.apache.org/schema/spring}random>,<{http://camel.apache.org/schema/spring}recipientList>,<{http://camel.apache.org/schema/spring}redeliveryPolicy>,<{http://camel.apache.org/schema/spring}ref>,<{http://camel.apache.org/schema/spring}removeHeader>,<{http://camel.apache.org/schema/spring}removeHeaders>,<{http://camel.apache.org/schema/spring}removeProperties>,<{http://camel.apache.org/schema/spring}removeProperty>,<{http://camel.apache.org/schema/spring}resequence>,<{http://camel.apache.org/schema/spring}responseHeader>,<{http://camel.apache.org/schema/spring}responseMessage>,<{http://camel.apache.org/schema/spring}rest>,<{http://camel.apache.org/schema/spring}restBinding>,<{http://camel.apache.org/schema/spring}restConfiguration>,<{http://camel.apache.org/schema/spring}restContextRef>,<{http://camel.apache.org/schema/spring}restProperty>,<{http://camel.apache.org/schema/spring}rests>,<{http://camel.apache.org/schema/spring}rollback>,<{http://camel.apache.org/schema/spring}roundRobin>,<{http://camel.apache.org/schema/spring}route>,<{http://camel.apache.org/schema/spring}routeBuilder>,<{http://camel.apache.org/schema/spring}routeContextRef>,<{http://camel.apache.org/schema/spring}routes>,<{http://camel.apache.org/schema/spring}routingSlip>,<{http://camel.apache.org/schema/spring}rss>,<{http://camel.apache.org/schema/spring}ruby>,<{http://camel.apache.org/schema/spring}sample>,<{http://camel.apache.org/schema/spring}script>,<{http://camel.apache.org/schema/spring}secureXML>,<{http://camel.apache.org/schema/spring}serialization>,<{http://camel.apache.org/schema/spring}setBody>,<{http://camel.apache.org/schema/spring}setExchangePattern>,<{http://camel.apache.org/schema/spring}setFaultBody>,<{http://camel.apache.org/schema/spring}setHeader>,<{http://camel.apache.org/schema/spring}setOutHeader>,<{http://camel.apache.org/schema/spring}setProperty>,<{http://camel.apache.org/schema/spring}simple>,<{http://camel.apache.org/schema/spring}soapjaxb>,<{http://camel.apache.org/schema/spring}sort>,<{http://camel.apache.org/schema/spring}spel>,<{http://camel.apache.org/schema/spring}split>,<{http://camel.apache.org/schema/spring}sql>,<{http://camel.apache.org/schema/spring}sticky>,<{http://camel.apache.org/schema/spring}stop>,<{http://camel.apache.org/schema/spring}stream-config>,<{http://camel.apache.org/schema/spring}string>,<{http://camel.apache.org/schema/spring}syslog>,<{http://camel.apache.org/schema/spring}tarfile>,<{http://camel.apache.org/schema/spring}terser>,<{http://camel.apache.org/schema/spring}threadPoolProfile>,<{http://camel.apache.org/schema/spring}threads>,<{http://camel.apache.org/schema/spring}throttle>,<{http://camel.apache.org/schema/spring}throwException>,<{http://camel.apache.org/schema/spring}tidyMarkup>,<{http://camel.apache.org/schema/spring}to>,<{http://camel.apache.org/schema/spring}toD>,<{http://camel.apache.org/schema/spring}tokenize>,<{http://camel.apache.org/schema/spring}topic>,<{http://camel.apache.org/schema/spring}transacted>,<{http://camel.apache.org/schema/spring}transform>,<{http://camel.apache.org/schema/spring}univocity-csv>,<{http://camel.apache.org/schema/spring}univocity-fixed>,<{http://camel.apache.org/schema/spring}univocity-header>,<{http://camel.apache.org/schema/spring}univocity-tsv>,<{http://camel.apache.org/schema/spring}unmarshal>,<{http://camel.apache.org/schema/spring}validate>,<{http://camel.apache.org/schema/spring}verb>,<{http://camel.apache.org/schema/spring}vtdxml>,<{http://camel.apache.org/schema/spring}weighted>,<{http://camel.apache.org/schema/spring}when>,<{http://camel.apache.org/schema/spring}wireTap>,<{http://camel.apache.org/schema/spring}xmlBeans>,<{http://camel.apache.org/schema/spring}xmljson>,<{http://camel.apache.org/schema/spring}xmlrpc>,<{http://camel.apache.org/schema/spring}xpath>,<{http://camel.apache.org/schema/spring}xquery>,<{http://camel.apache.org/schema/spring}xstream>,<{http://camel.apache.org/schema/spring}xtokenize>,<{http://camel.apache.org/schema/spring}yaml>,<{http://camel.apache.org/schema/spring}zip>,<{http://camel.apache.org/schema/spring}zipFile> 
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"interceptFrom"). Expected elements are <{http://camel.apache.org/schema/spring}aggregate>,<{http://camel.apache.org/schema/spring}aop>,<{http://camel.apache.org/schema/spring}avro>,<{http://camel.apache.org/schema/spring}barcode>,<{http://camel.apache.org/schema/spring}base64>,<{http://camel.apache.org/schema/spring}batch-config>,<{http://camel.apache.org/schema/spring}bean>,<{http://camel.apache.org/schema/spring}beanio>,<{http://camel.apache.org/schema/spring}bindy>,<{http://camel.apache.org/schema/spring}boon>,<{http://camel.apache.org/schema/spring}castor>,<{http://camel.apache.org/schema/spring}choice>,<{http://camel.apache.org/schema/spring}circuitBreaker>,<{http://camel.apache.org/schema/spring}constant>,<{http://camel.apache.org/schema/spring}contextScan>,<{http://camel.apache.org/schema/spring}convertBodyTo>,<{http://camel.apache.org/schema/spring}crypto>,<{http://camel.apache.org/schema/spring}csv>,<{http://camel.apache.org/schema/spring}customDataFormat>,<{http://camel.apache.org/schema/spring}customLoadBalancer>,<{http://camel.apache.org/schema/spring}dataFormats>,<{http://camel.apache.org/schema/spring}delay>,<{http://camel.apache.org/schema/spring}delete>,<{http://camel.apache.org/schema/spring}description>,<{http://camel.apache.org/schema/spring}doCatch>,<{http://camel.apache.org/schema/spring}doFinally>,<{http://camel.apache.org/schema/spring}doTry>,<{http://camel.apache.org/schema/spring}dynamicRouter>,<{http://camel.apache.org/schema/spring}el>,<{http://camel.apache.org/schema/spring}enrich>,<{http://camel.apache.org/schema/spring}exchangeProperty>,<{http://camel.apache.org/schema/spring}expression>,<{http://camel.apache.org/schema/spring}expressionDefinition>,<{http://camel.apache.org/schema/spring}failover>,<{http://camel.apache.org/schema/spring}filter>,<{http://camel.apache.org/schema/spring}flatpack>,<{http://camel.apache.org/schema/spring}from>,<{http://camel.apache.org/schema/spring}get>,<{http://camel.apache.org/schema/spring}groovy>,<{http://camel.apache.org/schema/spring}gzip>,<{http://camel.apache.org/schema/spring}head>,<{http://camel.apache.org/schema/spring}header>,<{http://camel.apache.org/schema/spring}hessian>,<{http://camel.apache.org/schema/spring}hl7>,<{http://camel.apache.org/schema/spring}ical>,<{http://camel.apache.org/schema/spring}idempotentConsumer>,<{http://camel.apache.org/schema/spring}inOnly>,<{http://camel.apache.org/schema/spring}inOut>,<{http://camel.apache.org/schema/spring}intercept>,<{http://camel.apache.org/schema/spring}interceptFrom>,<{http://camel.apache.org/schema/spring}interceptSendToEndpoint>,<{http://camel.apache.org/schema/spring}jacksonxml>,<{http://camel.apache.org/schema/spring}javaScript>,<{http://camel.apache.org/schema/spring}jaxb>,<{http://camel.apache.org/schema/spring}jibx>,<{http://camel.apache.org/schema/spring}json>,<{http://camel.apache.org/schema/spring}jsonpath>,<{http://camel.apache.org/schema/spring}jxpath>,<{http://camel.apache.org/schema/spring}language>,<{http://camel.apache.org/schema/spring}loadBalance>,<{http://camel.apache.org/schema/spring}log>,<{http://camel.apache.org/schema/spring}loop>,<{http://camel.apache.org/schema/spring}lzf>,<{http://camel.apache.org/schema/spring}marshal>,<{http://camel.apache.org/schema/spring}method>,<{http://camel.apache.org/schema/spring}mime-multipart>,<{http://camel.apache.org/schema/spring}multicast>,<{http://camel.apache.org/schema/spring}mvel>,<{http://camel.apache.org/schema/spring}ognl>,<{http://camel.apache.org/schema/spring}onCompletion>,<{http://camel.apache.org/schema/spring}onException>,<{http://camel.apache.org/schema/spring}optimisticLockRetryPolicy>,<{http://camel.apache.org/schema/spring}options>,<{http://camel.apache.org/schema/spring}otherwise>,<{http://camel.apache.org/schema/spring}packageScan>,<{http://camel.apache.org/schema/spring}param>,<{http://camel.apache.org/schema/spring}patch>,<{http://camel.apache.org/schema/spring}pgp>,<{http://camel.apache.org/schema/spring}php>,<{http://camel.apache.org/schema/spring}pipeline>,<{http://camel.apache.org/schema/spring}policy>,<{http://camel.apache.org/schema/spring}pollEnrich>,<{http://camel.apache.org/schema/spring}post>,<{http://camel.apache.org/schema/spring}process>,<{http://camel.apache.org/schema/spring}properties>,<{http://camel.apache.org/schema/spring}property>,<{http://camel.apache.org/schema/spring}protobuf>,<{http://camel.apache.org/schema/spring}put>,<{http://camel.apache.org/schema/spring}python>,<{http://camel.apache.org/schema/spring}random>,<{http://camel.apache.org/schema/spring}recipientList>,<{http://camel.apache.org/schema/spring}redeliveryPolicy>,<{http://camel.apache.org/schema/spring}ref>,<{http://camel.apache.org/schema/spring}removeHeader>,<{http://camel.apache.org/schema/spring}removeHeaders>,<{http://camel.apache.org/schema/spring}removeProperties>,<{http://camel.apache.org/schema/spring}removeProperty>,<{http://camel.apache.org/schema/spring}resequence>,<{http://camel.apache.org/schema/spring}responseHeader>,<{http://camel.apache.org/schema/spring}responseMessage>,<{http://camel.apache.org/schema/spring}rest>,<{http://camel.apache.org/schema/spring}restBinding>,<{http://camel.apache.org/schema/spring}restConfiguration>,<{http://camel.apache.org/schema/spring}restContextRef>,<{http://camel.apache.org/schema/spring}restProperty>,<{http://camel.apache.org/schema/spring}rests>,<{http://camel.apache.org/schema/spring}rollback>,<{http://camel.apache.org/schema/spring}roundRobin>,<{http://camel.apache.org/schema/spring}route>,<{http://camel.apache.org/schema/spring}routeBuilder>,<{http://camel.apache.org/schema/spring}routeContextRef>,<{http://camel.apache.org/schema/spring}routes>,<{http://camel.apache.org/schema/spring}routingSlip>,<{http://camel.apache.org/schema/spring}rss>,<{http://camel.apache.org/schema/spring}ruby>,<{http://camel.apache.org/schema/spring}sample>,<{http://camel.apache.org/schema/spring}script>,<{http://camel.apache.org/schema/spring}secureXML>,<{http://camel.apache.org/schema/spring}serialization>,<{http://camel.apache.org/schema/spring}setBody>,<{http://camel.apache.org/schema/spring}setExchangePattern>,<{http://camel.apache.org/schema/spring}setFaultBody>,<{http://camel.apache.org/schema/spring}setHeader>,<{http://camel.apache.org/schema/spring}setOutHeader>,<{http://camel.apache.org/schema/spring}setProperty>,<{http://camel.apache.org/schema/spring}simple>,<{http://camel.apache.org/schema/spring}soapjaxb>,<{http://camel.apache.org/schema/spring}sort>,<{http://camel.apache.org/schema/spring}spel>,<{http://camel.apache.org/schema/spring}split>,<{http://camel.apache.org/schema/spring}sql>,<{http://camel.apache.org/schema/spring}sticky>,<{http://camel.apache.org/schema/spring}stop>,<{http://camel.apache.org/schema/spring}stream-config>,<{http://camel.apache.org/schema/spring}string>,<{http://camel.apache.org/schema/spring}syslog>,<{http://camel.apache.org/schema/spring}tarfile>,<{http://camel.apache.org/schema/spring}terser>,<{http://camel.apache.org/schema/spring}threadPoolProfile>,<{http://camel.apache.org/schema/spring}threads>,<{http://camel.apache.org/schema/spring}throttle>,<{http://camel.apache.org/schema/spring}throwException>,<{http://camel.apache.org/schema/spring}tidyMarkup>,<{http://camel.apache.org/schema/spring}to>,<{http://camel.apache.org/schema/spring}toD>,<{http://camel.apache.org/schema/spring}tokenize>,<{http://camel.apache.org/schema/spring}topic>,<{http://camel.apache.org/schema/spring}transacted>,<{http://camel.apache.org/schema/spring}transform>,<{http://camel.apache.org/schema/spring}univocity-csv>,<{http://camel.apache.org/schema/spring}univocity-fixed>,<{http://camel.apache.org/schema/spring}univocity-header>,<{http://camel.apache.org/schema/spring}univocity-tsv>,<{http://camel.apache.org/schema/spring}unmarshal>,<{http://camel.apache.org/schema/spring}validate>,<{http://camel.apache.org/schema/spring}verb>,<{http://camel.apache.org/schema/spring}vtdxml>,<{http://camel.apache.org/schema/spring}weighted>,<{http://camel.apache.org/schema/spring}when>,<{http://camel.apache.org/schema/spring}wireTap>,<{http://camel.apache.org/schema/spring}xmlBeans>,<{http://camel.apache.org/schema/spring}xmljson>,<{http://camel.apache.org/schema/spring}xmlrpc>,<{http://camel.apache.org/schema/spring}xpath>,<{http://camel.apache.org/schema/spring}xquery>,<{http://camel.apache.org/schema/spring}xstream>,<{http://camel.apache.org/schema/spring}xtokenize>,<{http://camel.apache.org/schema/spring}yaml>,<{http://camel.apache.org/schema/spring}zip>,<{http://camel.apache.org/schema/spring}zipFile> 
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:740) 
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:262) 

は、おそらく私は休息とRouteDefinitionsを包ん方法に類似の要素を使用してinterceptFromをラップする必要があります。しかし、どのように確認していない。 私は正しい方法でそれをやっているかどうかはわかりません。 何とかこれで私を助けることができます。

また、CamelContextに設定できるInterceptStrategyがあります。

InterceptFromの代わりにキャッシュの問題を適用することで、私のルートのためのプロセス処理のようなAOPを行う方法がありますか?

また、私のCamelアプリケーションはSpring Bootに基づいているため、Spring Bootにはルートコールを傍受するための機能があります。

XMLファイルを使用して、このレポにルートとアピロードをロードするために作成したサンプルプロジェクトを追加しました。同様に、私はインターセプタを使ってキャッシングのクロスカッティング問題を適用し、ルートロジックと混同しないようにしたいと考えています。私はinterceptFrom camel機能を使用する方法を探しています。そのため、すべてのメッセージをルートに傍受し、それに応じて処理することができます。私は、インターセプタをロードする方法、またはそれらをルートにリンクさせる方法がわかりません。

https://github.com/sri420/compositerepo/tree/master/CompositeApplication

私は現在、私が原因で、名前空間のエラーのインターセプタをロードするために追加したコードを削除しました。一度、私は解決策の正しいアプローチを得て、それに応じて同じものを追加します。

+0

インターセプトをロードするためのxmlファイルがある特別な理由はありますか?なぜあなたのcamelcontext構文の残りの部分と一緒に入れてみませんか? –

+0

インターセプタロジックをアプリケーションのすべてのルートで共通にしたいと考えています。だから、すべてのルートの一部にするのではなく、可能な限り、それを切り離したいと思っています。私がルートと私のアプリケーションの残りのAPIルートを分けたように、私はインターセプタの共通の関心事を分けて、ルートロジックと混同しないようにしたいと思っていました。 – Shan

+0

CamelContextはxsdの親要素であるため、CamelContextの一部でなければなりません。 –

答えて

0

完全なIntercept.xmlを提供できますか? Intercept.xml xmlファイルの名前空間が正しくないと思われます。

<camelContext xmlns="http://camel.apache.org/schema/spring"> 
    <!-- intercept incoming messages and route them to the mock:middle1 endpoint 
     before we proceed and continue routing from the point of interceptions, that 
     is mock:end will be the next target --> 
    <interceptFrom> 
     <to uri="mock:middle1"/> 
    </interceptFrom> 

    <!-- here we have a very simple route --> 
    <route> 
     <from uri="direct:start"/> 
     <to uri="mock:end"/> 
    </route> 
</camelContext> 
+0

お返事ありがとうございます。私は現在、intercept.xmlに名前空間がありません。 interceptFromのために追加する必要がある名前空間を教えてください。 interceptFrom要素をintercept.xmlにcamelContextタグで囲んでみましたが、同じエラーが表示されます。 – Shan

+0

@Shan上記の私の答えでXMLコンテンツを参照することができます。 –

+0

あなたが提供したXMLコンテンツを使用しようとしましたが、それでも私は同じエラーがあります。 – Shan

関連する問題