apache-camel apache-cxf IllegalStateException: Could not register object under bean name 'cxf': there is already object bound - spring

Camel Version: 2.12.2,
CXF Version: 2.7,
Apache Tomcat: 7
I have the following camel-cxf.xml :
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:s0="http://www.huawei.com/bme/cbsinterface/cbs/businessmgr"
xmlns:s1="http://www.huawei.com/bme/cbsinterface/cbs/accountmgr"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" />
<bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
<cxf:cxfEndpoint id="oneEndpoint"
address="${endpoint.address}"
serviceName="s1:WebService"
serviceClass="WebserviceClass"
endpointName="s1:WebSericePort_http"
wsdlURL="classpath:wsdl/WebService.wsdl">
<cxf:inInterceptors>
<ref bean="loggingInInterceptor" />
<ref bean="setSoapVersionInterceptor"/>
</cxf:inInterceptors>
<cxf:inFaultInterceptors>
<ref bean="loggingInInterceptor" />
<ref bean="setSoapVersionInterceptor"/>
</cxf:inFaultInterceptors>
<cxf:outInterceptors>
<ref bean="loggingOutInterceptor" />
</cxf:outInterceptors>
<cxf:outFaultInterceptors>
<ref bean="loggingOutInterceptor" />
</cxf:outFaultInterceptors>
</cxf:cxfEndpoint>
<http-conf:conduit name="*.http-conduit">
<http-conf:client
Connection="Keep-Alive"
ConnectionTimeout="60000"
ReceiveTimeout="90000"/>
</http-conf:conduit>
</beans>
In my camel-context I have two processors that use the cxf endpoint to invoke two different operations. To do that I use a producerTemplate which uses "cxf:bean:oneEndpoint" as a uri.
The project is a web application deployed in Tomcat 7.
The processors consume from two different queues. After deployment both queues are propagated with a message. The problem is that one of the processors will throw an exception upon invoking the send method on the producer template. The other will work fine. The exception is:
org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint:
cxf://bean:oneEndpoint due to: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oneEndpoint': Initialization of bean failed;
nested exception is java.lang.IllegalStateException: Could not register object [org.apache.cxf.bus.spring.SpringBus#4b0af74c] under bean name 'cxf':
there is already object [org.apache.cxf.bus.spring.SpringBus#24c0fe59] bound
Full stacktrace can be found here: http://pastebin.com/cDsQZ9r3
The second time the queues receive a message at the same time, everything works fine.
Any ideas?
PS. My web.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/META-INF/spring/*.xml</param-value>
</context-param>
</web-app>
Routes & Processors:
<route id="route1" errorHandlerRef="eh1">
<from uri="{{queue1}}" />
<setHeader headerName="operationName">
<constant>Operation_1</constant>
</setHeader>
<process ref="FirstProcessor" />
<choice>
<when>
<simple>${in.headers.STATUS} == 'OK'</simple>
<inOnly uri="{{result_queue}}" />
</when>
<otherwise>
<inOnly uri="{{nok_result_queue}}" />
</otherwise>
</choice>
</route>
<route id="route2" errorHandlerRef="eh2">
<from uri="{{queue2}}" />
<setHeader headerName="operationName">
<constant>Operation_2</constant>
</setHeader>
<process ref="SecondProcessor" />
<choice>
<when>
<simple>${in.headers.STATUS} == 'OK'</simple>
<inOnly uri="{{result_queue}}" />
</when>
<otherwise>
<inOnly uri="{{nok_result_queue}}" />
</otherwise>
</choice>
</route>
<property name="producerTemplate" ref="firstProcessorTemplate" />
<property name="producerTemplateUri"
value="cxf:bean:oneEndpoint?headerFilterStrategy=#headerFilterStrategy" />
<property name="producerTemplate" ref="secondProcessorTemplate" />
<property name="producerTemplateUri"
value="cxf:bean:oneEndpoint?headerFilterStrategy=#headerFilterStrategy" />

The problem is that both queues are getting a message at the same time so both of them are trying to initialise the SpringBus at the same time.
The problem is that in BusWiringBeanFactoryPostProcessor it this code:
if (!context.containsBean(name) && (create || Bus.DEFAULT_BUS_ID.equals(name))) {
SpringBus b = new SpringBus();
ConfigurableApplicationContext cctx = (ConfigurableApplicationContext)context;
cctx.getBeanFactory().registerSingleton(name, b);
b.setApplicationContext(context);
}
So when two beans both try and initialise the SpringBus in two different threads, they can both enter the if statement at the same time leading to the exception.
The solution is to define a SpringBus in the application context so neither bean will try create a new SpringBus as one already exists.

Please share the routes definition which consumes messages from two different queues. Also you can look for option of using multicasting to have parallel processing in consuming messages from both queues and proceed with further opertion.<route>
<from uri="cxf:bean:oneEndpoint"></from>
<recipientList>
<simple>direct:${header.operationName}</simple>
<log message="Got ${header.operationName}" />
</recipientList>
</route>
Your routes (route1 and route) can be renamed as same as webservice operation name. Our code is also something similar to yours. We haven't faced problem with this approach.

Related

camel sql-stored ends in "java.sql.SQLException: Non supported SQL92 token at position" with Oracle datasource

When I run the following simple route with a stored-procdure, it results in an exception: "java.sql.SQLException: Non supported SQL92 token at position"
The same route with embedded Derby datasources works as expected.
Question
Any ideas? Is something wrong with my "implementation" or is it a problem of the underlying jar files?
Stack:
camel 2.23.2
ojdbc7.jar
Spring XML
Route:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<!-- In Memory Database
<jdbc:embedded-database id="myDataSource" type="DERBY">
<jdbc:script location="classpath:/sql/createAndPopulateDatabase.sql"/>
</jdbc:embedded-database>
-->
<bean id="oracleDataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:#..."/>
<property name="username" value="xx"/>
<property name="password" value="yy"/>
</bean>
<bean id="sql-stored" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="oracleDataSource"/>
</bean>
<camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start"/>
<setHeader headerName="in1">
<constant>1</constant>
</setHeader>
<setHeader headerName="in2">
<constant>1</constant>
</setHeader>
<to uri="sql-stored:INOUTDEMO(INTEGER ${headers.in1},INOUT INTEGER ${headers.in2} out1,OUT INTEGER out2)"/>
<log message="Result: ${body}" loggingLevel="INFO" />
</route>
</camelContext>
</beans>
Stored-Procedure:
I know that the procedure would not work in an oracle db, but the exception is thrown "long" before the involved classes / methods would recognize, that the procedure doesn't work / even exist.
CREATE PROCEDURE INOUTDEMO(IN1 INTEGER, INOUT IN2 INTEGER, OUT OUT1 INTEGER)
PARAMETER STYLE JAVA
LANGUAGE JAVA
EXTERNAL NAME
'org.apache.camel.component.sql.stored.TestStoredProcedure.inoutdemo';
Stacktrace:
Caused by: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException; SQL state [99999]; error code [17034]; Nicht unterstütztes SQL92-Token in Position: 20; nested exception is java.sql.SQLException: Nicht unterstütztes SQL92-Token in Position: 20
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1414)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:632)
at org.apache.camel.component.sql.SqlProducer.process(SqlProducer.java:116)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:138)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:101)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:76)
at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:186)
at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:86)
at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:541)
at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:506)
at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:369)
at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:506)
at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:229)
at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:144)
at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:161)
... 30 more
Caused by: java.sql.SQLException: Nicht unterstütztes SQL92-Token in Position: 20
at oracle.jdbc.driver.OracleSql.handleODBC(OracleSql.java:1306)
at oracle.jdbc.driver.OracleSql.parse(OracleSql.java:1192)
at oracle.jdbc.driver.OracleSql.getSql(OracleSql.java:326)
at oracle.jdbc.driver.OracleParameterMetaData.getParameterMetaData(OracleParameterMetaData.java:46)
at oracle.jdbc.driver.OraclePreparedStatement.getParameterMetaData(OraclePreparedStatement.java:11621)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.getParameterMetaData(OraclePreparedStatementWrapper.java:1552)
at org.apache.commons.dbcp2.DelegatingPreparedStatement.getParameterMetaData(DelegatingPreparedStatement.java:162)
at org.apache.commons.dbcp2.DelegatingPreparedStatement.getParameterMetaData(DelegatingPreparedStatement.java:162)
at org.apache.camel.component.sql.SqlProducer$2.doInPreparedStatement(SqlProducer.java:120)
at org.apache.camel.component.sql.SqlProducer$2.doInPreparedStatement(SqlProducer.java:1)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)
... 48 more
For oracle procedure/function parameters it should be variable name followed by in/out followed by data type.
E.g "out1 out integer"
The only way I made it "work" was like that:
<to uri="sql-stored: CALL HELLOWORLD(:#testValue,:#result)"/-->
With that - no IN, INOUT, OUT or type argument and "CALL" - it is at least possible to execute the stored procedure in the oracle db.
Unfortunately, I am still struggeling to map the return value op the stored procedure back to camel header oder body variable.

JMS Selector for messages having an underscore in one header with Camel and Blueprint

I need to cleanup some messages in a JMS queue (ActiveMQ) where some of the message header contains an underscore.
Some example
Message 1:
header MyObject=urn:sap:order:ID1234
body = <some xml>
Message 2:
header MyObject=urn:sap:order:ID9834_ABC
body = <some xml>
My goal is to move the only messages looking like Message 2 (and all similar containing an underscore) and not messages without underscores (like Message 1) from the original queue MY_ORDERS.
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
<cm:property-placeholder persistent-id="com.mycompany.order-temp" update-strategy="reload">
<cm:default-properties>
<cm:property name="amq.url" value="tcp://localhost:61616" />
<cm:property name="queue.to.dump" value="activemq:queue:MY_ORDERS?selector=MyObject+LIKE+'urn:order:%_%'" />
</cm:default-properties>
</cm:property-placeholder>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<onException useOriginalMessage="true">
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<to uri="activemq:queue:MY_ORDERS_DLQ?preserveMessageQos=true" />
</onException>
<route id="route-orders-to-temp">
<from uri="{{queue.to.dump}}" />
<to uri="activemq:queue:MY_ORDERS_TEMP" />
</route>
</camelContext>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="${amq.url}" />
</bean>
</blueprint>
By using the following posts and because the official ActiveMQ Documentation about selectors says it uses SQL 92 syntax:
https://stackoverflow.com/a/17102616/628006
https://stackoverflow.com/a/5822/628006
I tried all the following combinations:
selector=MyObject+LIKE+'urn:sap:order:%_%'
selector=MyObject+LIKE+'urn:sap:order:%_%'
selector=MyObject+LIKE+'urn:sap:order:%\_%'
selector=MyObject+LIKE+'urn:sap:order:%[_]%'
selector=MyObject+LIKE+'urn:sap:order:[a-Z0-9]*_[a-Z0-9]*'
But none of them seems to work. Any thoughts?
Finally I found the solution of my problem: there is a special syntax to define the escaping character which does not seems to be set by default.
By looking on Internet I finally found the following post which clearly shows the underscore must be escaped by e.g. \ then defining the escape character with ESCAPE '\'
If I apply to my cases the following lines:
selector=MyObject+LIKE+'urn:sap:order:%_%' ESCAPE '\'
selector=MyObject+LIKE+'urn:sap:order:%\_%' ESCAPE '\'
will just work fine with the additional ESCAPE '\' at the end of the selector.

EhCache Jgroups Replication

In my sping based project (spring version 4.1.5.FINAL), I'm using ehcache-core version 2.6.10, ehcache-jgroupsreplication versione 1.7 and jgroups 3.1.0.FINAL
This is my XML ehcache configuration:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" name="webCache" >
<diskStore path="java.io.tmpdir/webCache"/>
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory" properties="udp.xml"/>
<cache name="it.test.cache.CustomCache"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="600"
timeToLiveSeconds="6000"
overflowToDisk="true">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory" properties="replicateAsynchronously=true,replicatePuts=true,replicateUpdates=true,replicateUpdatesViaCopy=false,replicateRemovals=true" />
</cache>
</ehcache>
This is my upd.xml configuration:
<config xmlns="urn:org:jgroups"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
<UDP
mcast_port="${jgroups.udp.mcast_port:45588}"
tos="8"
ucast_recv_buf_size="200K"
ucast_send_buf_size="200K"
mcast_recv_buf_size="200K"
mcast_send_buf_size="200K"
max_bundle_size="64K"
max_bundle_timeout="30"
ip_ttl="${jgroups.udp.ip_ttl:2}"
enable_diagnostics="true"
thread_naming_pattern="cl"
timer_type="new"
timer.min_threads="4"
timer.max_threads="10"
timer.keep_alive_time="3000"
timer.queue_max_size="500"
thread_pool.enabled="true"
thread_pool.min_threads="2"
thread_pool.max_threads="8"
thread_pool.keep_alive_time="5000"
thread_pool.queue_enabled="true"
thread_pool.queue_max_size="10000"
thread_pool.rejection_policy="discard"
oob_thread_pool.enabled="true"
oob_thread_pool.min_threads="1"
oob_thread_pool.max_threads="8"
oob_thread_pool.keep_alive_time="5000"
oob_thread_pool.queue_enabled="false"
oob_thread_pool.queue_max_size="100"
oob_thread_pool.rejection_policy="Run"/>
<PING />
<MERGE3 max_interval="30000"
min_interval="10000"/>
<FD_SOCK/>
<FD_ALL/>
<VERIFY_SUSPECT timeout="1500" />
<BARRIER />
<pbcast.NAKACK use_mcast_xmit="true"
retransmit_timeout="300,600,1200"
discard_delivered_msgs="true"/>
<UNICAST/>
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
max_bytes="4M"/>
<pbcast.GMS print_local_addr="true" join_timeout="3000"
view_bundling="true"/>
<UFC max_credits="2M"
min_threshold="0.4"/>
<MFC max_credits="2M"
min_threshold="0.4"/>
<FRAG2 frag_size="60K" />
<pbcast.STATE_TRANSFER />
</config>
In my spring xml context I have the following (I'll put just a fragment of my spring context file):
<bean id="settaSystemProps" name="settaSystemProps" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="java.lang.System" />
<property name="targetMethod" value="getProperties" />
</bean>
</property>
<property
name="targetMethod" value="putAll" />
<property
name="arguments">
<util:properties>
<prop key="jgroups.logging.log_factory_class">it.test.cache.replication.jgroups.log.logback.impl.LogbackLogImpl</prop>
<prop key="java.net.preferIPv4Stack">true</prop>
</util:properties>
</property>
</bean>
<bean id="webCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" depends-on="settaSystemProps">
<property name="configLocation" value="classpath:webCoMiEhCacheCfg.xml"/>
</bean>
Sadly, by using this configuration, I'm not able in sending/receiving messages in the cluster
When I start my tomcat I see the following print (and it's not using my custom log):
feb 27, 2015 10:31:18 AM org.jgroups.logging.JDKLogImpl error Grave:
failed sending message to cluster (65 bytes): java.lang.Exception:
dest=/228.8.8.8:45588 (68 bytes), cause: java.io.IOException: Invalid
argument
feb 27, 2015 10:31:19 AM org.jgroups.logging.JDKLogImpl error
Grave: failed sending message to cluster (65 bytes):
java.lang.Exception: dest=/228.8.8.8:45588 (68 bytes), cause:
java.io.IOException: Invalid argument
feb 27, 2015 10:31:28 AM
org.jgroups.logging.JDKLogImpl error Grave: failed sending message to
cluster (65 bytes): java.lang.Exception: dest=/228.8.8.8:45588 (68
bytes), cause: java.io.IOException: Invalid argument feb 27, 2015
10:31:28 AM org.jgroups.logging.JDKLogImpl error Grave: failed sending
message to cluster (65 bytes): java.lang.Exception:
dest=/228.8.8.8:45588 (68 bytes), cause: java.io.IOException: Invalid
argument
Can anybody tell me where I'm wrong? What I need is to synchronize EhCache on a cluster formed by 2 nodes
Can anybody provide to me a working configuration sample?
thank you
Angelo
What's the output when you start an instance ? I think you might still be using IPv6. Can you use -Djava.net.preferIPv4Stack=true instead of defining this in the XML ?

Transforming HL7 v2 to XML using apache camel routes

I am new to HL7 .I have to convert the HL7v2 to XML using apache camel routes.I am extracting the HL7 message from file.
Can any one help me how to convert HL7 to XML
There is an HL7 component for unmarshalling the file into a HAPI message. The HAPI api also includes an XMLParser that will convert the message into xml. So you should be able to combine the two into a simple camel route like the following:
<bean id="hl7XmlConverter" class="example.Hl7XmlConverter" />
<bean id="hl7FileFilter"
class="org.apache.camel.component.file.AntPathMatcherGenericFileFilter">
<property name="includes" value="*.hl7" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="hl7FileRoute">
<from
uri="file:///tmp/test/?delete=true&moveFailed=.error&filter=#hl7FileFilter" />
<convertBodyTo type="java.lang.String" />
<log message="HL7 Request: ${body}" />
<unmarshal>
<hl7 validate="true" />
</unmarshal>
<bean ref="hl7XmlConverter"/>
<log message="HL7 Response: ${body}" />
</route>
</camelContext>
Where the bean is just a simple method:
public String convertMessage(Message message) throws HL7Exception{
XMLParser parser = new DefaultXMLParser();
return parser.encode(message);
}
Depending on your desired xml format, you could also add an xslt after the bean.

Having trouble with content based routing in Camel with a CXFRS endpoint and xPath

I am trying to create a route that is determined by the content in the REST payload using xPath. I have been successful in using routing based on the message header:
<when>
<simple>${headers.operationName} == 'createContainerOutput'</simple>
<bean ref="containerOutputProcessor"/>
</when>
which properly invokes the containerOutputProcessor...
but for this xPath route:
<when>
<xpath>/*[local-name()='order-request']/#type='TrayOutput'</xpath>
<bean ref="containerOutputProcessor"/>
</when>
I get the the exception:
org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.w3c.dom.Document with value [com.mmi.ws.ContainerOutputOrderRequest#6290dc]
for this payload
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order-request type="TrayOutput">
<parameter name="orderName">Example Tray Output Order</parameter>
<parameter name="enableScan">true</parameter>
<parameter name="autoStart">false</parameter>
<parameter name="priority">3</parameter>
<item barcode="23990001"/>
<item barcode="23990002"/>
</order-request>
Is this type of routing a good idea? Is there a better way to route based on what type of order-request is being submitted?
Thanks for any help/guidance you may have for me!
Here is the complete context
<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<!-- enable Spring #Component scan -->
<context:component-scan base-package="com.mmi.ws"/>
<!-- web service beans -->
<bean id="containerOutputWS" class="com.mmi.ws.service.impl.ContainerOutputWSImpl" />
<bean id="containerTypesWS" class="com.mmi.ws.service.impl.ContainerTypesWSImpl" />
<!-- processor beans -->
<bean id="containerOutputProcessor" class="com.mmi.ws.service.ContainerOutputProcessor" />
<bean id="containerTypesProcessor" class="com.mmi.ws.service.ContainerTypesProcessor" />
<bean id="unsupportedPathProcessor" class="com.mmi.ws.service.UnsupportedPathProcessor" />
<!-- Define the real JAXRS back end service -->
<jaxrs:server id="restService"
address="http://localhost:9998/sc"
staticSubresourceResolution="true">
<jaxrs:serviceBeans>
<ref bean="containerOutputWS"/>
<ref bean="containerTypesWS"/>
</jaxrs:serviceBeans>
</jaxrs:server>
<!-- define the restful server and client endpoints -->
<cxf:rsServer id="rsServer" address="http://localhost:9999/sc" loggingFeatureEnabled="true" loggingSizeLimit="20">
<cxf:serviceBeans >
<ref bean="containerOutputWS"/>
<ref bean="containerTypesWS"/>
</cxf:serviceBeans>
</cxf:rsServer>
<cxf:rsServer id="rsClient" address="http://localhost:9998/sc" loggingFeatureEnabled="true" loggingSizeLimit="20">
<cxf:serviceBeans >
<ref bean="containerOutputWS"/>
<ref bean="containerTypesWS"/>
</cxf:serviceBeans>
</cxf:rsServer>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<!--
any classes in the below 'packageScan'packages that extends RouteBuilder
will be added as a camel route. At least one route is required to start the cxf web service
-->
<packageScan>
<package>com.mmi.ws</package>
</packageScan>
<dataFormats>
<xstream id="xstream-utf8" encoding="UTF-8"/>
<xstream id="xstream-default"/>
</dataFormats>
<!-- route starts from the cxf webservice -->
<route streamCache="true">
<from uri="cxfrs://bean://rsServer"/>
<log message="XML payload to send to REST WS:${body}" />
<setHeader headerName="CamelCxfRsUsingHttpAPI"><constant>True</constant> </setHeader>
<choice>
<when>
<simple>${headers.operationName} == 'getContainers'</simple>
<bean ref="containerTypesProcessor"/>
</when>
<when>
<xpath>/*[local-name()='order-request']/#type='TrayOutput'</xpath>
<bean ref="containerOutputProcessor"/>
</when>
<otherwise>
<bean ref="unsupportedPathProcessor"/>
<to uri="cxfrs://bean://rsClient"/>
</otherwise>
</choice>
</route>
</camelContext>
</beans>
and the web service class:
#Path("/container/output/")
public class ContainerOutputWSImpl
{
#POST
#Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
#Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ContainerOutputView createContainerOutput(ContainerOutputOrderRequest containerOutput) {
// TODO Auto-generated method stub
return new ContainerOutputView();
}
}
and finally, the xml payload and error stack:
Address: http://localhost:9999/sc/container/output/
Encoding: ISO-8859-1
Http-Method: POST
Content-Type: application/xml
Headers: {accept-encoding=[gzip,deflate], connection=[keep-alive], Content-Length=[384], content-type=[application/xml], Host=[localhost:9999], User-Agent=[Apache-HttpClient/4.1.1 (java 1.5)]}
Payload: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order-request type="TrayOutput">
<parameter name="orderName">Example Tray Output Order</parameter>
<parameter name="enableScan">true</parameter>
<parameter name="autoStart">false</parameter>
<parameter name="priority">3</parameter>
<item barcode="23990001"/>
<item barcode="23990002"/>
</order-request>
--------------------------------------
[ERROR] 2013-02-07 17:53:37.059 [qtp27633254-28: DefaultErrorHandler] Failed delivery for (MessageId: ID-PWY-EHANSEN-3070-1360288389778-0-2 on ExchangeId: ID-PWY-EHANSEN-3070-1360288389778-0-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.RuntimeCamelException: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.w3c.dom.Document with value [com.mmi.ws.ContainerOutputOrderRequest#9fbbe5]
org.apache.camel.RuntimeCamelException: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.w3c.dom.Document with value [com.mmi.ws.ContainerOutputOrderRequest#9fbbe5]
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1271)
at org.apache.camel.builder.xml.XPathBuilder.getDocument(XPathBuilder.java:1027)
at org.apache.camel.builder.xml.XPathBuilder.doInEvaluateAs(XPathBuilder.java:850)
at org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:757)
at org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:145)
at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:66)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:73)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:334)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:220)
at org.apache.camel.processor.interceptor.StreamCachingInterceptor.process(StreamCachingInterceptor.java:52)
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:303)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:73)
at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.asyncInvoke(CxfRsInvoker.java:87)
at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.performInvocation(CxfRsInvoker.java:57)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:201)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:102)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:365)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:722)
Before the content based router, you can convert the message to take out the payload from the internal CXF list. There is a trick with the simple language to grab the first index from the list:
<transform>
<simple>${body[0]}</simple>
</transform>
<choice>
...
Do you have camel-jaxb on the classpath. If so it may work out of the box without that trick. Not sure though, as CXF is a bit special. Also dependes on what version of Camel / CXF you use. You should really mention this when you ask questions!

Resources