How to set exchange headers from xslt - apache-camel

I am using camel 2.10 version.
I would like to set exchange headers while calling XSLT component.
I am able to Get Parameters into the XSLT, but I need to do vice-versa.
Can you please tell how can I achieve it?

You can use xpath to grab something from an XML body and then store that as a header. http://camel.apache.org/xpath
.setHeader("foo", xpath("/foo/bar"))
The trick is to write the xpath expression so it works. As your XML message uses namespaces you need to use them in the xpath expression also. See that link for more details.

Related

Apache Camel - Mybatis select with parameters and useIterator

I'm trying to use Apache Camel (version 2.20.0) with mybatis component.
More specifically, I have to export a large set or record from database to file.
I'd like to prevent memory issues so I want to use the option consumer.useIterator. My route is:
from("mybatis:selectItemsByDate?statementType=SelectList&consumer.useIterator=true")
.split()
.body()
.process(doSomething)
to(file:my-path-file);
but my query has in input a parameter (the starting date to get data). How should I set this parameter?
In many example on internet I saw the parameter in the body or in the header of the Exchange message but I think is possibile only if the mybatis endpoint is in a "to" method. But the option "consumer.useIterator" is working only when the enpdoint is in a "from" method.
Please help me to understand how I can set the input for my query or if this is not supported yet (in this case if you can give some hint how to implement would be great)
thank you.
Then you need to start your route from something else, like a timer or direct endpoint, and then call the mybatis endpoint in a to, where you have set that information in the message body/header you use in the mybatis query so its dynamic.
Also you should set the splitter to be in streaming mode so it walks the iterator it gets from mybatis on-demand.

Regex to extract data in cell and pass to subsequent request where it is needed in Jmeter

I am using this regex to extract data in cell and pass to subsequent request where it is needed in JMeter.
Using Reg-ex to extract the data in cell:
"cell":\["","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","(.*?)","","(.*?)","(.*?)","(.*?)"]}]}
Can someone help to enhance it using beanshell or store it in array and then pass it to subsequent request?
It seems you are trying to extract something from JSON response. Using regular expressions for this is not very recommended.
Be aware that starting from JMeter 3.0 there is a JSON Extractor which can be used for fetching data from JSON responses using JsonPath language.
The relevant JsonPath expression to get the content of cell element will be as simple as:
$..cell
Going forward please try to include at least essential parts of the response into your question.

Camel Restlet - Binding query parameters to message headers

Looking through Camel docs I couldn't find any way that allow me to bind the query parameters within the headers. For example :
Let's say I have an endpoint like that
http://localhost:8080/services/resource?filter=xxx
End I want to get that parameter from the header
exchange.getIn.().getHeaders().get('filter')
The query parameter 'filter' is not returned in the header. Anyone of you knows if this feature is coming by default in camel? I know I can build the binding by myself, but i am just looking for choose among camel-servlet (apparently that binding is implemented by default) and camel-restlet.
If you choose camel-restlet you can use the
restletBinding=#refName
to convert the query string parameters to headers.
The #refName is the bean ID of a RestletBinding object in the Camel Registry.

Intercepting Camel Endpoint Dynamically

I am trying to intercept an endpoint where the value of the URI matches some information in the exchange header.
Let say I have a field in the header called DatabaseName. I want to enforce that a specific route is only writing to the database specified in the header.
Can I do something like this?
interceptSendToEndpoint("mock:${in.header.DatabaseName}")
I tried that but it does not seem to work. What are my options?
I was also thinking of doing something like:
interceptSendToEndpoint("mock:*").when(...)?
But in this case, I am not sure if I can reference the URI of the intercepted node in the when expression.
Thanks
You can intercept using a wildcard and combine that with when to do what you want, see details at: http://camel.apache.org/intercept
The is a header on the Message with the key Exchange.INTERCEPTED_ENDPOINT (CamelInterceptedEndpoint) that has the endpoint uri that was intercepted. You can use that in the when to match the predicate. Something a like:
interceptSendToEndpoint("mock:*")
.when(simple("${header.CamelInterceptedEndpoint} == ${in.header.DatabaseName}"))
...
Use the recipientList instruction for this: http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html

Is there an easy way to parse SolrInputDocument xml back into object form in camel context?

I use org.apache.solr.client.solrj.util.ClientUtils to convert an SolrInputDocument into a XML string and send to a queue. Now I need to manipulate that xml in a consumer, Ideally I want to have the xml convert back to SolrInputDocument, So I can add/drop couple fields with its methods. Is there an easy way to achieve that? Or any suggestions?
you can generally use something like xstream/marshall API for this...that said, the XML that is output from the ClientUtils.toXML() call doesn't work with this approach.
per this post..."this is best done programmatically"
The other way of doing this is to parse your xml then convert it to java class. You can use SaxParser for this. See this link.
XML parsing using SaxParser with complete code

Resources