apache camel routing queues issue - spring

I'm trying to create an application that gets information from a browser and drops it in a queue. That data is then picked up from the queue and sent through an application for security. The security app should drop it in a different queue when it is done to be picked up by a separate action application.
Could anyone help me along with the routing? Basically, the route I'm looking for is:
Browser/UI -> Qnonsecure -> security app -> QSecure -> action app
What I understand now is the following:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="jms:queue:QnonSecure"/>
<to uri="jms:queue:QSecure"/>
</route>
</camelContext>
How Can I change this to route to and from applications.
How do I send the input from the browser into QnonSecure? Also, where in my code do I call the security app between the QnonSecure and QSecure?

There is more than one possible solution. Take the following route as a starting point:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="restlet:http://localhost:8081/myApp?restletMethod=post"/>
<to uri="jms:queue:QnonSecure" pattern="InOut" />
<enrich uri="direct:securityApp"/>
<choice>
<when>
<simple>${header.myHeader} == "SECURE"</simple>
<to uri="jms:queue:QSecure" pattern="InOut" />
<to uri="direct:actionApp" />
</when>
<otherwise>
<!-- handle non valid requests -->
</otherwise>
</choice>
</route>
</camelContext>
Steps:
The browser sends a POST request to the Camel restlet component. This could be done via JavaScript, a link and/or just a ordinary submit button.
The body is sent to jms:queue:QnonSecure. As we use the InOut pattern, this is done in a synchronous manner and the response is fetched.
The response of jms:queue:QnonSecure is sent to direct:securityApp where the credentials are tested. If they are correct, the header myHeader is set to SECURE (or any other value).
In the choice statement, myHeader is tested. In the secure case, jms:queue:QSecure and finally direct:actionApp is invoked.

Related

How can I request to camel-context endpoints from postman?

I have a spring project using apache camel.
I want to try the services provided in camel-context.xml using a postman request.
How can I infer the path variables and endpoint?
The method I want to use is specified like below on camel-context.xml and I have parameters providing the contains conditions.
<route>
<from uri="netty:udp://{{camel.netty.server}}:{{camel.netty.udp.port}}?sync=false&allowDefaultCodec=true;" />
<convertBodyTo type="java.lang.String" charset="ISO-8859-9" />
<choice>
<when>
<simple trim="true">${bodyAs(String)} contains '"ISN":"90"'</simple>
<bean ref="Feaser" method="run" cache="false"></bean>
<to uri="mock:result" />
</when>
...
Postman doesn't support sending on UDP.

Sending parallel requests routed to a single endpoint using Apache Camel

I get suggestions of Multicast,where a single request is routed to multiple endpoints as the snippet below.But the requirement is sending multiple requests in parallel to a single endpoint.
<route>
  <from uri="direct:start"/>
  <multicast>
<to uri="mock:first"/>
    <to uri="mock:second"/>
    <to uri="mock:third"/>
  </multicast>
</route>
You can use parallelProcessing option.
<route>
<from uri="direct:start"/>
<multicast parallelProcessing="true">
<to uri="mock:first"/>
<to uri="mock:second"/>
<to uri="mock:third"/>
</multicast>
</route>

How to do nested request response jms calls with camel

I'm trying to do a request response call inside a route which is actually called from the outside in an request response way. Now it seems this is not working, it looks like the outer replyTo/correlation id is lost.
Following situation:
Client
jmsRequest to myFirstQueue with replyTo=temp://xyz
Route
<route id="foo">
<from uri="jms:myFirstQueue"/>
<to uri="debugProcessor1"/>
<to uri="jms:myNestedIn?replyTo=myNestedOut" pattern="InOut"/>
<to uri="debugProcessor2"/>
</route>
<route id="myNestedFoo">
<from uri="jms:myNestedIn"/>
<to uri="someDummyProcessor"/>
<to uri="jms:myNestedOut" pattern="InOnly"/>
</route>
In debugProcessor1 I still see JMSReplyTo correctly set to temp://xyz, unfortunately in debugProcessor2 this is lost and therefore the client does not get back the response.
Figured it out, my debug processors actually destroyed it, without them it works!

Camel - CXF Endpoint - JMS Request-Reply model

I have CXF endpoint. I have dedicated route defined for each operation and routing the request to appropriate routes using header.operation name with reciepient list.
For couple operations(routes), I have post request to JMS endpoint which gets processed by another application and response is recieved in another queue. I have to read response message and transform the message. My requesting thread(webservice call) would be waiting for the transformed message.
Currently after posting request, currently I have written my own processor which use spring jms template to read message. I came across few examples such as split routes but not sure how it will work for overall synchronous communication which has in between JMS communication.
You can find a JMX Request/Reply example here:
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
<bean id="setResponseProcessor" class="org.apache.camel.itest.jetty.SetResponseProcessor"/>
<camelContext xmlns="http://camel.apache.org/schema/spring" trace="true">
<route>
<from uri="cxf://serverBean"/>
<to uri="jms:responseQueue"/>
</route>
<route>
<from uri="jms:responseQueue"/>
<process ref="setResponseProcessor"/>
</route>
</camelContext>

Camel SMPP consumer route not working properly with dynamic creation

I am trying to receive DELIVER_SM from the smsc. The first snippet of code where the smpp route is created statically, works just fine. But later, I wanted to listen to more than one smpp routes which are dynamically created with credentials returned from a SQL query so I wrote the second snippet which I thought it would run fine but instead, the route doesn't get to the printPdus method where i can see the DELIVER_SM. The snippet doesn't work because it is not starting with smpp as a consumer from a "from uri="smpp://...""? How could I make something like this but with dynamically created smpp routes using spring.
<route id="Report-route">
<from uri="smpp://${pdus.systemid}#${pdus.address}:${pdus.port}?password=${pdus.password}" />
<to uri="bean:SmsReceiver?method=printPdus" />
</route>
<route id="Report-route">
<from uri="sql:{{sql.selectReceivingRoutes}}" />
<to uri="bean:SmsReceiver?method=createReceivingRoutes" />
<recipientList>
<header>receiverRoutes</header>
</recipientList>
<to uri="bean:SmsReceiver?method=printPdus" />
</route>

Resources