I have an object called realorder and I would like to clone that object Using .
<to uri="bean:DozerBeanMapper?method=map(Order.class,${header.realOrder.order})" />
<setHeader headerName="realOrder.CloneOrder">
<spel>#{new org.dozer.DozerBeanMapper().map(com.gap.gid.oms.v1.complete.domain.order.Order.class,request.headers['realOrder.order'])}</spel>
</setHeader>
When I tried this, I am getting below Exception.
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 42 in XML document from class path resource [com/services/routeContext-realOrder.xml] is invalid; nested exception is org.xml.sax.SAXParseException;
lineNumber: 42; columnNumber: 19; cvc-complex-type.2.3: Element 'setHeader'
cannot have character [children], because the type's content type is element-only.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
Related
I'm trying to set a custom processStrategy in Camel 2.23.2. I've tried several ways to reference it from the processStrategy uri parameter, but I always get this exception:
Caused by: java.lang.IllegalArgumentException: Could not find a suitable setter for property: processStrategy as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.camel.component.file.GenericFileProcessStrategy with value #genericFileNoOpProcessStrategy"
Route definition
<bean id="genericFileNoOpProcessStrategy" class="org.apache.camel.component.file.strategy.GenericFileNoOpProcessStrategy"/>
<routeContext id="routes" xmlns="http://camel.apache.org/schema/spring">
<route id="route">
<from uri="seda:someEvent"/>
<pollEnrich>
<constant>file:/folder?fileName=file.csv&processStrategy=#genericFileNoOpProcessStrategy"</constant>
</pollEnrich>
What's the right way to reference it?
This would've been working if it weren't a user error (notice the quote "):
<constant>file:/folder?fileName=file.csv&processStrategy=#genericFileNoOpProcessStrategy"</constant>
Fixed with:
<constant>file:/folder?fileName=file.csv&processStrategy=#genericFileNoOpProcessStrategy"</constant>
I have a simple route which looks like this:
<route handleFault="true" streamCache="true" id="routeA">
<from uri="cxfrs://bean://simpleCxf" />
<log message="The message body contains ${body}"/>
<to uri="direct-vm:RouteB" />
</route>
<route handleFault="true" streamCache="true" id="routeB">
<from uri="direct-vm:RouteB" />
<bean ref="requestValidator" method="validateRequest" />
<log message="The input message ${body}" />
<bean ref="dbClient" method="queryDatabase" />
</route>
the cxf configuration is also pretty simple:
<cxf:rsServer id="simpleCxf" address="/test"
loggingFeatureEnabled="true"
serviceClass="com.gogol.test.TestResource">
</cxf:rsServer>
This simple route fails with the below exception
No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.test.resource.SimpleObject#773736ca]
This is the message history which suggests that it is failing at the point <bean ref="requestValidator" method="validateRequest" />
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[routeA] [routeA] [direct-vm://routeA ] [6]
[routeB] [log12 ] [log ] [2]
[routeB] [to9 ] [direct-vm:routeA ] [4]
[routeA] [bean26] [bean[ref:requestValidator method: validateRequest]] [2]
I think the issue is that Camel is trying to convert the body generated by cxf to an Exchange object. Because the requestValidator class has a method which has a signature of:
public void validateRequest(Exchange exchange) thows SomeException.
But ideally the message generated by cxf should be set as a body inside Exchange. Am I correct, if not then what could be the reason of the above exception?
EDIT:
I am using CXF version 3.0.4.redhat-621084
and CAMEL version 2.15.1.redhat-621084
{Caused by: org.apache.camel.InvalidPayloadException: No body available of type: org.apache.camel.Exchange but has value: [com.gogol.schema.TestResourcec#6b651b67] of type: org.apache.cxf.message.MessageContentsList on: Message: [com.gogol.schema.TestResourcec#6b651b67]. Caused by: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.schema.TestResourcec#6b651b67]. Exchange[Message: [com.gogol.schema.TestResourcec#6b651b67]]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.schema.TestResourcec#6b651b67]]
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.builder.ExpressionBuilder$42.evaluate(ExpressionBuilder.java:1037)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
... 68 more
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.cxf.message.MessageContentsList to the required type: org.apache.camel.Exchange with value [com.gogol.schema.TestResourcec#6b651b67]
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:177)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
at org.apache.camel.core.osgi.OsgiTypeConverter.mandatoryConvertTo(OsgiTypeConverter.java:122)[203:org.apache.camel.camel-spring:2.15.1.redhat-621084]
at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)[198:org.apache.camel.camel-core:2.15.1.redhat-621084]
... 69 more}
I am not positive on the camel xml dsl how to format this properly, but you can always explicitly tell camel to do a type conversion. You could test your theory by using a convertBodyTo call to force a type conversion.
from("myEndpoint")
.log("This is my previous object")
.convertBodyTo(TestResource.class)
.log("This is my object after a camel type conversion");
I have a Camel route exposed as a CXF web service. This is a bottom up web service and has an operation like so:
List<Book> getBooks();
The CXF endpoint is defined as:
<cxf:cxfEndpoint id="bookService"
address="http://localhost:9045/bookservice"
serviceClass="org.test.cxfws.service.BookDBService">
</cxf:cxfEndpoint>
The operation queries a list of books and returns it to the caller. The Camel route looks like this:
<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="cxf:bean:bookService"/>
<choice>
<when>
<simple>${header.operationName} == 'getBooks'</simple>
<to uri="bean:wsImplBean?method=getBooks"/>
</when>
<to uri="log:outboundSoapResponse"/>
<choice>
</route>
</camel:camelContext>
After running the route, I am getting the following exception:
org.apache.cxf.interceptor.Fault: org.test.cxfws.service.Book cannot be cast to java.util.List
at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:117)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
...
Caused by: java.lang.ClassCastException: org.test.cxfws.service.Book cannot be cast to java.util.List
at org.test.cxfws.service.GetBooksResponse_WrapperTypeHelper1.createWrapperObject(Unknown Source)
at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:101)
I can see that the getBooks method from the bean wsImpBean is executed and the result being returned at the end of the choice block inside the route:
[ qtp1653072092-14] outboundSoapResponse INFO Exchange[ExchangePattern: InOut, BodyType: java.util.ArrayList, Body: [org.test.cxfws.service.Book#63f1858b, org.test.cxfws.service.Book#5769bf0, org.test.cxfws.service.Book#2df7ac5d, org.test.cxfws.service.Book#5f55253e, org.test.cxfws.service.Book#4f003a57]]
Can someone help me to understand why the ClassCastException.
Thanks.
As camel-cxf use list to hold the response for handling the InOut parameters. When you set the response result into the message body, you need to wrap the result into a List just like this
List<Book> books ...
List<Object> resultList = new ArrayList<Object>();
resultList.add(books);
exchange.getOut().setBody(resultList);
I have the following route in Camel:
<route>
<from uri="servlet:///user?matchOnUriPrefix=true"/>
<setHeader headerName="cachename">
<simple>${header.CamelHttpPath.split("/")[1]}</simple>
</setHeader>
<setHeader headerName="key1">
<simple>${header.CamelHttpPath.split("/")[2]}</simple>
</setHeader>
<to uri="direct:put"/>
</route>
<route>
<from uri="direct:put" />
<!-- If using version 2.8 and above set headerName to "CamelHazelcastOperationType" -->
<setHeader headerName="CamelHazelcastOperationType">
<constant>put</constant>
</setHeader>
<setHeader headerName="CamelHazelcastObjectId">
<simple>${header.key1}</simple>
</setHeader>
<process ref="requestTimeProc"/>
<to uri="hazelcast:map:default" />
</route>
And i am trying to put a string as value into the cache.
My HazelCast Configuration is :
<map name="default">
<in-memory-format>OBJECT</in-memory-format>
<backup-count>1</backup-count>
<async-backup-count>0</async-backup-count>
<time-to-live-seconds>0</time-to-live-seconds>
<max-idle-seconds>0</max-idle-seconds>
<eviction-policy>NONE</eviction-policy>
<max-size policy="PER_NODE">0</max-size>
<eviction-percentage>25</eviction-percentage>
<merge-policy>com.hazelcast.map.merge.PassThroughMergePolicy</merge-policy>
</map>
<serialization>
<portable-version>0</portable-version>
</serialization>
And i Am gettign the following exception:
2013-12-10 22:47:08,288 [tp-1763826860-0] ERROR DefaultErrorHandler - Failed delivery for (MessageId: ID-DJD7W4R1-54721-1386740808850-0-1 on ExchangeId: ID-DJD7W4R1-54721-1386740808850-0-2). Exhausted after delivery attempt: 1 caught: com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable serializer for class org.apache.camel.converter.stream.InputStreamCache
com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable serializer for class org.apache.camel.converter.stream.InputStreamCache
at com.hazelcast.nio.serialization.SerializationServiceImpl.toData(SerializationServiceImpl.java:172)[hazelcast-3.1.2.jar:3.1.2]
at com.hazelcast.nio.serialization.SerializationServiceImpl.toData(SerializationServiceImpl.java:157)[hazelcast-3.1.2.jar:3.1.2]
at com.hazelcast.map.MapService.toData(MapService.java:666)[hazelcast-3.1.2.jar:3.1.2]
at com.hazelcast.map.proxy.MapProxyImpl.put(MapProxyImpl.java:72)[hazelcast-3.1.2.jar:3.1.2]
at com.hazelcast.map.proxy.MapProxyImpl.put(MapProxyImpl.java:60)[hazelcast-3.1.2.jar:3.1.2]
at org.apache.camel.component.hazelcast.map.HazelcastMapProducer.put(HazelcastMapProducer.java:136)[camel-hazelcast-2.11.2.jar:2.11.2]
at org.apache.camel.component.hazelcast.map.HazelcastMapProducer.process(HazelcastMapProducer.java:71)[camel-hazelcast-2.11.2.jar:2.11.2]
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[camel-core-2.11.2.jar:2.11.2]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[camel-core-2.11.2.jar:2.11.2]
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122)[camel-core-2.11.2.jar:2.11.2]
Please let me know if i am missing anythign inthe configuration . I am using the default Hazelcast configuration provided int he Hazelcast jar. Any help will be highly appreciated
A few comments:
I would not change the 'default' map. This means that any map in the system, which doesn't have an explicit configuration, will now use this configuration. So figure out which map is used and configure explicitly for that map.
<map name="explicitName">
<in-memory-format>OBJECT</in-memory-format>
....
</map>
About the exception:
com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable serializer for class org.apache.camel.converter.stream.InputStreamCache
It means that the InputStreamCache is put in the map, but Hazelcast doesn't know how to conver it to a stream of bytes. You can plug in a serializer for this class, see the following blogpost how to do so:
http://blog.hazelcast.com/blog/2013/10/16/kryo-serializer/
The big question for me is: why are you trynig to put an InputStreamCache in a map? My gut feeling says that this class is not something you want to put in a distribured Hazelcast map at all.
Spring context:
<bean id="customRouteA" class="com.xxx.CustomRouteABean" />
<camelContext id="solr" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:topic:agent" />
<to uri="bean:customRouteA"/>
</route>
</camelContext>
Java code:
public class CustomRouteABean {
#EndpointInject(uri = "http4://localhost/camel-route-test.php")
ProducerTemplate producer;
public void processMessage(#Body String message) {
...
}
}
Keeps getting error:
2085 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customRouteA' defined in ServletContext resource [/WEB-INF/application-context.xml]: Initialization of bean failed; nested exception is org.apache.camel.spring.GenericBeansException: Error post processing bean: customRouteA; nested exception is org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: http4://localhost/camel-route-test.php?bridgeEndpoint=true due to: null
I have another bean has the same setup works just fine, what am I missing here?
And you have camel-http4 and its dependent JARs on the classpath?