Is it a possible to declare Interceptor per Endpoint, not per CamelContext? In my case I've lots of CamelContexts and I want to extract common code with endpoints declarations and interceptors to one file: camel-common-context.xml. There is absolutely no problem with extracting endpoints, but how to extract interceptors? Is it a possible or they just should be inside every CamelContext where I want to use an endpoint? In my case they're not visible in related camel contexts after modification which I posted below:
my camel-common-context.xml:
<camelContext id="esb" xmlns="http://camel.apache.org/schema/spring">
<endpoint id="externalSystem" uri="${external.system.url}?throwExceptionOnFailure=false" />
<interceptFrom>
<convertBodyTo type="java.lang.String" />
<when>
<xpath>not(/soapenv:Envelope)</xpath>
<process ref="soapFaultProcessor" />
</when>
<otherwise>
<convertBodyTo type="java.lang.String" />
</otherwise>
</interceptFrom>
<interceptSendToEndpoint uri="ref:externalSystem">
<setHeader headerName="SYSTEM">
<constant>EXTERNAL</constant>
</setHeader>
<convertBodyTo type="java.lang.String" />
<to uri="log:wSSProcessor_external_system_request?level=DEBUG" />
</interceptSendToEndpoint>
</camelContext>
Other camel contexts (I'm only importing resource):
<import resource="camel-common-context.xml" />
I've no problems when I'm declaring each endpoint with interceptor in every camel-context, but it's a wrong pattern with lots of copy-paste.
In this question I see that there is an information that " I dont think this is possible using InterceptorStrategy since that expects it is running in the same camel context". What's more I think that using multiple contexts with one application is a bad pattern
UPDATE
I was trying to change my architecture to one Camel Context with more Route Contexts follow up @Lukasz N answer, but I hit a snag CamelBugWithRouteContexts. It looks quite impossible to resolve my problem but it should works well on versions of camel higher than 2.8.