Apache CAMEL exception - apache-camel

Getting current exception, not sure how to resolve it. Any ideas? Thanks a lot!
org.apache.camel.RuntimeCamelException: org.quartz.SchedulerException: Trigger's related Job's name cannot be null
<camel:endpoint id="pollPipilineStarUpScheduler"
uri="quartz://timedPipilineStarUp?stateful=true&cron=0+0+0+1/1+*+?+2099;job.name=startup;" />
<camel:route>
<camel:from ref="pollPipilineStarUpScheduler" />
<camel:bean ref="executionManager" method="startPipeline" />
</camel:route>
</camel:camelContext>

Your definition worked for Camel 2.12.2 (which version do you use?), however
I changed your cron expression to 0/5+*+*+*+*+?+*, because I didn't want to wait so long for the first job execution... More information about Quartz's cron expression can be found here.
Options should not be separated by ; but by &. In XML & becomes &. In your URI the &amp was lost and it should therefore be quartz://timedPipilineStarUp?stateful=true&cron=0+0+0+1/1+*+?+2099&job.name=startup;. However, I don't understand that your URI with ; worked for me...
Instead of setting the job.name option, you could have been using the following format quartz://groupName/timerName?cron=expression.

Related

How to set file name without extension in camel Header using Java DSL?

I need to set the file name without extension in header. While searching I got the below blueprint/spring code snippet. I want to achieve the same through Java DSL. can any one help me?
<camel:route>
<camel:from uri="file://input/orders" />
<camel:setHeader headerName="FileNameWithoutExtension">
<camel:simple>${file:onlyname.noext}</camel:simple>
</camel:setHeader>
I found out. We have to follow the below syntax
.setHeader("FileNameWithoutExtension",simple("${file:onlyname.noext}"))

Camel ActiveMQ: Consuming messages based on the JMSTimestamp

I have defined a Route which consumes messages from a queue without any problems, and right now I am trying to consume the messages that have been in the queue for 12 hours, I got the idea to use a selector, but no idea how to use it with JMSTimestamp to meet the 12 hours criteria.
This is the Route:
<route id="INBOUND.RECEIVE.IN">
<from
uri="activemq:queue:QXL.INBOUND.RECEIVE.IN?selector=JMSTimestamp%3D${date.time}&concurrentConsumers=10&destination.consumer.prefetchSize=0&deliveryPersistent=true&username=admin01&password=001!admin01001!" />
<pipeline>
<bean method="inboundReceive" ref="logipalServices"/>
</pipeline>
</route>
And this is the date bean
<bean id="date" class="java.util.Date" scope="prototype"/>
Based on your explanation, I think something is wrong with your selector.
JMSTimestamp%3D${date.time} means JMSTimestamp = ${date.time}
It means you're looking for all messages with the exact JMSTimestamp. Since Date.getTime() returns time in milliseconds, it's very unlikely, you will retrieve any message from the queue.
I think you should try something like :
JMSTimestamp > current date - 12 hours (pseudo code for selector)
I hope this will help you.

Camel - Why the setProperty changes the header as well?

I've imagined, that setProperty change the header as well, and I don't know why.
<setProperty propertyName="A"><constant>AAA</constant></setProperty>
<log message="HA: ${headers.A}" />
<log message="PA: ${exchangeProperty[A]}" />
Both logs print AAA. Camel version 2.17.3, Spring version 4.3.2.RELEASE.
How should I use the setProperty?
As answered by Claus Ibsen:
This is working as Camel was designed with the header/property
expressions in the DSL.
A header lookup will fallback as property.
Source: Simple message header.XXX and exchange property.XXX the same?

How to call setter method on ${body} in a Camel route?

I have tried to set a property on the body of a Java bean constituting the message in transit through a Camel route. I have tried various approaches e.g.
<route>
...
..
<transform>
<simple>${body.label} = ${property.label}</simple>
</transform>
...
..
</route>
in this particular case the ${body} is a Java bean with a setLabel(String label) method and the ${property.label} is set by other means in another route. In this example the result is not the desired (and I understand why), i.e. after the transform the body of the message is replaced with the ${body.label} = ${property.label} string.
My current work-around is to manually code a transformer as a Spring bean and set the label property of the Java bean in code but I like to find out if there is a simpler/smarter way to achieve this, preferably in XML DSL which is what I use?
Regards, Ola
I'm not sure if it's possible with simple, but you could do it using groovy:
<setBody>
<groovy>request.body.label = exchange.getProperty('label')
return request.body
</groovy>
</setBody>
Maybe it can help someone in the future:
As I know You can use standard Java approach with settters anf getters in body:
.split(body())
.setBody(simple("${body.setLogin('TEST')}"))
.end()
It works inside <split></split>. Maybe inside another blocks.

Camel route using spring-ws client occasionally throws javax.xml.transform.stax.StAXSource exception

I have a camel 'seda' route that contains code roughly:
JaxbDataFormat jaxb = new JaxbDataFormat(false);
jaxb.setContextPath("com.example.data.api");
from("seda:validate")
.marshal(jaxb)
.to("spring-ws:" + getDataServiceURL())
.unmarshal(jaxb)
I send an object from com.example.data.api, the JaxbDataFormat formatter sets it up as a SOAP request and passes it along wo spring-ws to actually send to my service. This works like a charm most of the time.
I say "most" because every now and then, spring-ws throws an exception like so:
org.springframework.ws.client.WebServiceTransformerException: Transformation error: Can't transform a Source of type javax.xml.transform.stax.StAXSource; nested exception is javax.xml.transform.TransformerException: Can't transform a Source of type javax.xml.transform.stax.StAXSource
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:608)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:492)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:479)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceive(WebServiceTemplate.java:470)
at org.apache.camel.component.spring.ws.SpringWebserviceProducer.process(SpringWebserviceProducer.java:81)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
The core of that is this error message: "Can't transform a Source of type javax.xml.transform.stax.StAXSource".
None of that makes sense. The Jaxb marshalling will have already made sure that the object in question is an XML string (according to any debug logging I do). Furthermore, this exact code works most of the time and only occasionally will fail. It appears random.
For instance, I ran a test just a few minutes ago where I sent a message into my route and got this error. I then restarted my service and resend the exact same message... and it worked like a charm. Same code; same environment; same test -- two different results.
It's this randomness that makes this so maddening. Any ideas what I should be looking for to making sure this never happens?
The issue is not with Camel but Spring-WS. Modifying the transformerFactoryClass in WS template config would work
<bean id="baseCamelMarshallerWSTemplate" class="org.springframework.ws.client.core.WebServiceTemplate" scope="prototype">
<constructor-arg ref="messageFactory" />
<property name="messageSender">
<ref bean="httpSender"/>
</property>
<property name="checkConnectionForError" value="true"/>
**<property name="transformerFactoryClass" value="com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"/>**
</bean>
If you still face the issue, please share spring WS config and a test case

Resources