Representing a route list from xml in camel DSL - java

How can I represent this route in Camel's DSL:
<camel:camelContext id="camel-context">
<camel:route id="conductor-event" trace="true">
<camel:from uri="direct:conductor/event"/>
<camel:log message="handling conductor-event: id=${exchangeId}"/>
<!-- execute each filter in sorted order -->
<camel:bean ref="beaner.BProcessors"/>
<camel:log message="after: [bprocessors]: id=${exchangeId}"/>
<!-- map the event to a route -->
<camel:recipientList parallelProcessing="false">
<camel:method ref="beaner.Mappings" />
</camel:recipientList>
<camel:log message="after event mapping: id=${exchangeId}"/>
</camel:route>
</camel:camelContext>
I have this so far, but I get a "Caused by: java.net.URISyntaxException: Illegal character in scheme name at index 0: %7BCamelToEndpoint=...":
RouteDefinition routeDef = from("direct:conductor/event")
.log( "handling conductor-event: id=${exchangeId}" )
.beanRef( "beaner.BProcessors" )
.log( "after: [bprocessors]: id=${exchangeId}" );
ExpressionClause<RecipientListDefinition<RouteDefinition>> recipientList = routeDef.recipientList();
recipientList.properties().setParallelProcessing( false );
recipientList.method( "beaner.EventMappings" );
routeDef.log( "after event mapping: id=${exchangeId}" );

here is the route in JavaDSL...note that the recipientList parallelProcessing is false by default...
from("direct:conductor/event")
.log("handling conductor-event: id=${exchangeId}")
.beanRef("beaner.BProcessors")
.log("after: [bprocessors]: id=${exchangeId}")
.recipientList(bean("beaner.Mappings"))
.log("after event mapping: id=${exchangeId}");

You should use a RouteBuilder class in Java DSL to access the DSL.
Then inside the configure method you can build the routes almost identical as in XML DSL.
See the getting started guide here: http://camel.apache.org/walk-through-an-example.html

Related

How to configure apache camel to see the reason of the shutdown?

Preconditions:
Camel 2.17
I had defined some routes, that routes contain entries like:
.to ("log:org.apache.camel?level=DEBUG")
My logback config contains:
<logger name="org.apache.camel" level="TRACE" />
Context definition begins with:
<camel:camelContext id="someContext" ... trace="true">
When I am starting Camel, then I see Camel is proceeding and finally without ANY error report just shutting down. This looks like:
2016-10-04 13:40:56,146 [localhost-startStop-1] TRACE org.apache.camel.model.ProcessorDefinitionHelper - There are 6 properties on: From[direct:process]
2016-10-04 13:40:58,042 [localhost-startStop-1] DEBUG org.apache.camel.spring.SpringCamelContext - onApplicationEvent: org.springframework.context.event.ContextClosedEvent[source=Root WebApplicationContext: startup date [Tue Oct 04 13:37:25 CEST 2016]; root of context hierarchy]
2016-10-04 13:40:58,066 [localhost-startStop-1] INFO org.apache.camel.spring.SpringCamelContext - Apache Camel 2.17.3 (CamelContext: someContext) is shutting down
I have as well:
onException( java.lang.Exception.class )
.handled( false )
.to( "log:GeneralError?level=ERROR" );
But this is more related to the exchange processing and not to startup.
Is there any generic way to check what is going on out there?
For example:
Is there any class missing and class loader fails?
Or is any exception thrown?
Or some connection fails?
Complete route definition:
final RouteDefinition kafkaRouteDefinition = from( "kafka:{{kafka.broker.endpoints}}" +
"?topic={{kafka.topic.name}}" +
"&groupId=my_group" +
"&autoOffsetReset=earliest" +
"&consumersCount={{kafka.consumer.count}}" );
LOG.info( "Kafka route definition: " + kafkaRouteDefinition.toString() );
kafkaRouteDefinition
.routeId( Constants.ROUTE_ID_PROCESS_KAFKA_MESSAGES )
.to( "log:org.apache.camel?level=DEBUG" )
.process( new RawMessageProcessor() ).id( RawMessageProcessor.class.getSimpleName() )
.to( "log:org.apache.camel?level=DEBUG" )
.unmarshal( inputMessageFormat ).id( "ConvertRawMessageToLogline" )
.to( "log:org.apache.camel?level=DEBUG" )
.process( new LoglineMessageProcessor() ).id( LoglineMessageProcessor.class.getSimpleName() )
.to( "log:org.apache.camel?level=DEBUG" )
.to( Constants.CAMEL_PROCESS_ENDPOINT )
.to( "log:org.apache.camel?level=DEBUG" )
.multicast().stopOnException()
.to( "log:org.apache.camel?level=DEBUG" )
.to( Constants.CAMEL_STORE_ENDPOINT
, Constants.CAMEL_INDEX_ENDPOINT
)
.to( "log:org.apache.camel?level=DEBUG" )
.end();
I had Similar issue [But I was using Spring]
This happens when main method which loads camel Context exits before camel context is fully loaded
Add below code in your test case & it should run
org.apache.camel.spring.Main main = new Main();
main.setApplicationContextUri("camel-context.xml");
main.start();
Thread.sleep(1000);
More over you can also make autostart stop & start camel context later whenever needed
<camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring" autoStartup="false">
<route>
<from uri="direct:start"/>
<to uri="mock:result"/>
</route>
</camelContext>
then in some java file
ApplicationContext ac = ...
SpringCamelContext camel = (SpringCamelContext) ac.getBean("myCamel");
// now start Camel manually
camel.start();

NPE while trying to render a View in Spring Webflow

When trying to use a webflow, I keep getting the following error:
{
"failure":"true",
"exception.message":"org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing org.springframework.webflow.action.ViewFactoryActionAdapter#200a5beb in state 'accountCannotLogInView' of flow 'login' -- action execution attributes were 'map[[empty]]'",
"exception.stacktrace":"org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing org.springframework.webflow.action.ViewFactoryActionAdapter#200a5beb in state 'accountCannotLogInView' of flow 'login' -- action execution attributes were 'map[[empty]]'
...
Caused by: java.lang.IllegalStateException: Exception occurred rendering view null
at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:191)
at org.springframework.webflow.action.ViewFactoryActionAdapter.doExecute(ViewFactoryActionAdapter.java:40)
at org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:188)
at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51)
... 66 more
Caused by: java.lang.NullPointerException
at org.springframework.webflow.mvc.servlet.ServletMvcView.doRender(ServletMvcView.java:50)
at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:187)
... 69 more
"
}
Does anybody have any idea what the cause of this might be?
From my login-webflow.xml:
<action-state id="checkAccountType">
<evaluate expression="lookupAccountTypeAction.lookup(flowScope.principal)" />
<transition on="EMAIL" to="accountCannotLogInView" />
<transition on="Login" to="checkAccountStatus" />
<transition on="CONTACT" to="accountCannotLogInView" />
</action-state>
<end-state id="accountCannotLogInView" view="myAccountCannotLogInView"/>
From default_views.properties:
myAccountCannotLogInView.(class)=org.springframework.web.servlet.view.JstlView
myAccountCannotLogInView.url=/WEB-INF/view/jsp/default/ui/myAccountCannotLogInView.jsp
From my log file:
2013-09-09 08:29:25,645 DEBUG [org.springframework.webflow.engine.EndState] - Entering state 'accountCannotLogInView' of flow 'login'
2013-09-09 08:29:25,645 DEBUG [org.springframework.webflow.execution.ActionExecutor] - Executing org.springframework.webflow.action.ViewFactoryActionAdapter#359d136a
2013-09-09 08:29:25,645 DEBUG [org.springframework.webflow.mvc.view.AbstractMvcView] - Rendering MVC [null] with model map [{flowRequestContext=[RequestControlContextImpl#55bf756b externalContext = org.springframework.webflow.mvc.servlet.MvcExternalContext#2bb4d74, currentEvent = EMAIL, requestScope = map['ticketGrantingTicketId' -> 'TGT-1-GxALVR7PEtbagbnRlStOTbHoRHlb61YVm1m2hvWx3pgWCEXgPb-cas01.example.org'], attributes = map[[empty]], messageContext = [DefaultMessageContext#cb5efc8 sourceMessages = map[[null] -> list[[empty]]]], flowExecution = [FlowExecutionImpl#3f5c0d33 flow = 'login', flowSessions = list[[FlowSessionImpl#419d87bc flow = 'login', state = 'accountCannotLogInView', scope = map['principal' -> sso_test_user, 'userInfoBean' -> com.mycompany.authentication.UserInfoBean#54394557[username=<null>,firstName=<null>,lastName=<null>,emailAddress=<null>,streetAddress=<null>,city=<null>,state=<null>,zip=<null>,country=<null>], 'changePasswordBean' -> com.mycompany.authentication.ChangePasswordBean(username=null, newPassword=null, confirmNewPassword=null), 'service' -> https://my.server.com:443/casauth/facade/norenew?idp=https://my.server.com/idp/externalAuthnCallback, 'credentials' -> [username: sso_test_user], 'warnCookieValue' -> false, 'ticketGrantingTicketId' -> 'TGT-1-GxALVR7PEtbagbnRlStOTbHoRHlb61YVm1m2hvWx3pgWCEXgPb-cas01.example.org']]]]], flashScope=map[[empty]], principal=sso_test_user, currentUser=null, userInfoBean=com.mycompany.authentication.UserInfoBean#54394557[username=<null>,firstName=<null>,lastName=<null>,emailAddress=<null>,streetAddress=<null>,city=<null>,state=<null>,zip=<null>,country=<null>], changePasswordBean=com.mycompany.authentication.ChangePasswordBean(username=null, newPassword=null, confirmNewPassword=null), service=https://my.server.com:443/casauth/facade/norenew?idp=https://my.server.com/idp/externalAuthnCallback, credentials=[username: sso_test_user], flowExecutionKey=e1s1, warnCookieValue=false, flowExecutionUrl=/authentication/login?username=%5BLjava.lang.String%3B%405b65afa5&submit=%5BLjava.lang.String%3B%4070eea883&_eventId=%5BLjava.lang.String%3B%4044796a61&service=%5BLjava.lang.String%3B%407f372965&lt=%5BLjava.lang.String%3B%407e7ee722&password=%5BLjava.lang.String%3B%403d78aa0f&execution=%5BLjava.lang.String%3B%403ce4de50, ticketGrantingTicketId=TGT-1-GxALVR7PEtbagbnRlStOTbHoRHlb61YVm1m2hvWx3pgWCEXgPb-cas01.example.org}]
2013-09-09 08:29:25,645 DEBUG [org.springframework.webflow.engine.impl.FlowExecutionImpl] - Attempting to handle [org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing org.springframework.webflow.action.ViewFactoryActionAdapter#359d136a in state 'accountCannotLogInView' of flow 'login' -- action execution attributes were 'map[[empty]]'] with root cause [java.lang.NullPointerException]
2013-09-09 08:29:25,645 DEBUG [org.springframework.webflow.engine.impl.FlowExecutionImpl] - Rethrowing unhandled flow execution exception
And yes, the file does exist in that location. I've been banging on this for a few days, so if anybody has any insight, I'd really appreciate it.
And the correct answer is "user error". I'm building CAS via maven. I created profiles to hold logging, and then incorrectly configured it so that the default_views.properties file wasn't in the profiles. As a result, when CAS did its overlay as part of the maven build, it included the baseline default_views.properties instead of my copy.
it seems like your property is not parsed to your flow.xml.
defining your view hardcoded should work.
see here: Specifying view identifiers
The reason for this issue is: The JSP view is not found.
In cas-servlet.xml, mention the properties file which has the basename of the custom JSP view inside the "viewResolver" bean as below:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.ResourceBundleViewResolver"
p:order="0">
<property name="basenames">
<util:list>
<value>${cas.viewResolver.basename}</value>
<value>custom_view</value>
<value>protocol_views</value>
</util:list>
</property>
</bean>
And in the custom_view.properties, mention the following:
casRegisterView.(class)=org.springframework.web.servlet.view.JstlView
casRegisterView.url=/WEB-INF/view/jsp/default/ui/casRegisterView.jsp
Here the JSP view is "casRegisterView.jsp".
Place custom_view.properties in /src/main/resources.

Activiti from Camel Receive Task throws error "ActivitiIllegalArgumentException: Business key is null"

Please share any links to configure activiti with camel. All examples I could get were showing SERVICETASK->CAMELROUTE->FILE and then FILE->RECIEVETASK(Activiti)
This involves some BUSINESS_KEY, which I couldn't figure out what exactly is
I need an example showing SERVICE TASK -> CAMEL ROUTE-> RECEIEVTASK(Signal the Activiti). I dont know why but this example gives me error
file: activiti-flow.bpmn20.xml:
<process id="camelprocess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<serviceTask id="servicetask1" name="Service Task" activiti:async="true" activiti:delegateExpression="${camel}"></serviceTask>
<receiveTask id="receivetask1" name="Receive Task"></receiveTask>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="receivetask1"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="receivetask1" targetRef="endevent1"></sequenceFlow>
activiti-camel-spring.xml
<bean id="camel" class="org.activiti.camel.CamelBehaviour">
<constructor-arg index="0">
<list>
<bean class="org.activiti.camel.SimpleContextProvider">
<constructor-arg index="0" value="camelprocess" />
<constructor-arg index="1" ref="camelContext" />
</bean>
</list>
</constructor-arg>
</bean>
<camel:camelContext id="camelContext">
<camel:route>
<camel:from uri="activiti:camelprocess:servicetask1"/>
<camel:to uri="bean:serviceActivator?method=doSomething(${body})"/>
<camel:to uri="activiti:camelprocess:receivetask1"/>
</camel:route>
</camel:camelContext>
Error is:
1|ERROR|org.slf4j.helpers.MarkerIgnoringBase:161||||>> Failed delivery for (MessageId: ID-viscx73-PC-49557-1376961951564-0-1 on ExchangeId: ID-viscx73-PC-49557-1376961951564-0-2). Exhausted after delivery attempt: 1 caught: org.activiti.engine.ActivitiIllegalArgumentException: Business key is null
at org.activiti.engine.impl.ProcessInstanceQueryImpl.processInstanceBusinessKey(ProcessInstanceQueryImpl.java:87)
at org.activiti.camel.ActivitiProducer.findProcessInstanceId(ActivitiProducer.java:78)
at org.activiti.camel.ActivitiProducer.signal(ActivitiProducer.java:58)
at org.activiti.camel.ActivitiProducer.process(ActivitiProducer.java:49)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process (AsyncProcessorConverterHelper.java:61)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
All forums/links that has ACTIVITI->CAMELROUTE(FILE) then
in other route CAMEL_FILE->RECIEVETASK
And they suggest to add some key like PROCESS_KEY_PROPERTY or PROCESS_ID_PROPERTY
I don't get where these properties fit into
I am trying to work it from example at link
http://bpmn20inaction.blogspot.in/2013/03/using-camel-routes-in-activiti-made.html
I am not sure whether process after giving service task to camel, is not moving at all to receive task and waiting up there or CAMEL is unable to find receive task
Please share some suggestion on this
Thanks
It worked by adding inbuilt camel queues as shown in the example. I thought they were just shown as example for various routes. But by passing to queue actually the ServiceTask was made asynchronous in camel and later from queue they were read and invoked the receive task in activiti
<camel:to uri="seda:tempQueue"/>
<camel:from uri="seda:tempQueue"/>
Thanks
I don't know whether you'd solved the problem or not, but actually I faced the same problem.
And finally, I found a solution of the problem.
In fact, it is correct that PROCESS_ID_PROPERTY property must be provided otherwise the activiti engine doesn't know to execute which process instance. So, I just set PROCESS_ID_PROPERTY value in the header when sending the JMS to activemq, and when the message back, just set the propertiy from header. Something likes:
from("activiti:process:simpleCall").setHeader("PROCESS_ID_PROPERTY", simple("${property.PROCESS_ID_PROPERTY}")).to("activemq:queue:request");
from("activemq:queue:reply").setProperty("PROCESS_ID_PROPERTY", simple("${header.PROCESS_ID_PROPERTY}")).to("activiti:process:simpleReceive");
Hope it will help you.

In mule3, how to set a custom expression for choice-when router?

I am new to Mule, I want to validate the timestamp and nonce parameter from URI for preventing the replay attack. I use choice-when router, when the timestamp and nonce is valid(the validation process is complex), forward the request to backend rest service, otherwise return error code and message. I found a lot of MEL usage for choice-when, but can I define a custom expression use java? and there is a example available?
URI example:
http://muledemo.org/ci2/ni/del?id=0xe413&timestamp=1376022133&nonce=a03ed9c
code snippets:
<choice doc:name="Choice">
<when expression="???how to call a java validator???">
</when>
<otherwise>
<processor-chain doc:name="Processor Chain">
<echo-component doc:name="Echo" />
<http:outbound-endpoint exchange-pattern="request-response" method="POST"
address="http://localhost:8081#[message.inboundProperties['http.request']]" doc:name="HTTP" />
</processor-chain>
</otherwise>
</choice>
EDIT:
XML config:
<spring:beans>
<spring:bean id="replayAttackCheck" class="org.jamee.demo.mule.ReplayAttackCheck"/>
</spring:beans>
... ...
<when expression="#[replayAttackCheck.validate(payload)]">
<expression-component doc:name="Check Required Params"><![CDATA[payload="{\"code\":\"PA002\", \"message\":\"timestamp or nonce is illegal\"}"]]>
</expression-component>
</when>
Error log:
ERROR 2013-08-09 14:32:39,090 [[demo.router].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Execution of the expression "replayAttackCheck.validate(payload)" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: HashMap
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. [Error: unresolvable property or identifier: replayAttackCheck]
[Near : {... replayAttackCheck.validate(pay ....}]
Correct MEL syntax:
<when expression="#[app.registry.replayAttackCheck.validate(payload)]">
You just use the fully qualified path
#[com.mulesoft.foo(payload, someFooVar)]
Alternatively you can define it globally for your app in your configuration and the use the "foo" function in your MEL expressions
<configuration doc:name="Config">
<expression-language autoResolveVariables="false">
<global-functions>
def foo(fooVar){
return com.mulesoft.foo(payload, fooVar);
}
</global-functions>
</expression-language>
</configuration>

How to configure 2.6 spring: Failed to create route route2 at:

I'm trying to upgrade from Camel 2.0 to 2.6
I have this in my applicationContext-camel.xml file...
<camel:route >
<camel:from uri="transactionSaleBuffer" />
<camel:policy ref="routeTransactionPolicy"/>
<camel:transacted ref="transactionManagerETL" />
<camel:to uri="detailFactProcessor" />
</camel:route>
by adding in the two lines in the middle (policy and transacted) I get the exception...
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route2 at: >>> From[transactionSaleBuffer] <<< in route: Route[[From[transactionSaleBuffer]] -> [Tr
ansacted[ref:trans... because of Route route2 has no output processors. You need to add outputs to the route such as to("log:foo").
I can see this is because the Camel class RouteDefinition.java makes a call to ProcessorDefinitionHelper.hasOutputs(outputs, true).
This passes in an array of one Object ([Transacted[ref:transactionManagerETL]])
This one object has one two children
[Transacted[ref:transactionManagerETL]]
CHILD-[Policy[ref:routeTransactionPolicy],
CHILD-To[detailFactProcessor]
The Policy child has no outputs, so the exception is thrown.
Yet I don't know how to add a child, my XML above matches the schema.
Maybe I'm missing something else?
My setup matches the example...Apache Camel: Book in One Page (See section: Camel 1.x - JMS Sample)
Can anyone please help me out.
Thanks!
Jeff Porter
Try as follows
<camel:route>
<camel:from uri="transactionSaleBuffer" />
<camel:transacted ref="transactionManagerETL" />
<camel:policy ref="routeTransactionPolicy">
<camel:to uri="detailFactProcessor" />
</camel:policy>
</camel:route>

Categories