JMSTimestamp Vs Other Date storing headers on a JMS message - apache-camel

I'm using AMQs REST API to send a message to a Queue with a header set in the queryString.
I'm setting a date header myDateHeader with the millisecond value of a UNIX timestamp.
&myDateHeader=1583781133771
The JMSTimestamp header is being set automatically for me, and also seems to be set as a long....
I then consume this message with camel, albeit in Talend, and can 'parse' the JMSTimestamp to a formatted date.
However when I try to do the same with myDateHeader I get null back.
Both JMSTimestamp and myDateHeader show values if I 'parse' to String and Long so something is (not) happening as part of the date parsing.
Talend code shows
row5.Event_Timestamp = org.apache.camel.builder.SimpleBuilder
.simple("${in.header.myDateHeader}")
.evaluate(routerExchange, java.util.Date.class);
showing the correct resultType as per the SimpleBuilder class. The code is the same as that generated for parsing the JMSTimestamp.
Also when I try
simple("${date:in.header.myDateHeader:yyyyMMdd}")
I get
java.lang.IllegalArgumentException: Cannot find java.util.Date object at command: in.header.myDateHeader
I'm guessing:
1) that when the message is created, the header needs to be set with a correct type of Date to be able to do this date parsing as part of consumption?
2) And that the REST API sets all headers with type String and I can't change this through my REST call?
Excuse my guesses but am hoping if someone can confirm the above, and therefore that I can't treat myDateHeader the same as the JMSTimestamp header when consuming these messages?
thanks

Your second assumption is correct. Custom headers are parsed with type String. In Talend, as well as in Apache Camel, which is a Talend ESB's underlying integration framework, the predefined JMS headers including JMSTimestamp are converted to Java types according to the "Message format when receiving" reference table.

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.

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.

A Confusion about Raw query parameter

I am writing a simple migration tool in which I have to migrate gmail mailboxes to some other email provider. I am confused about raw string returned from gmail api.
In Google document, it says:
"raw": Returns the entire email message content in the raw field as a URL-safe base64 encoded string and the payload field is not used. This includes the identifiers, labels, metadata, MIME structure, and small body parts (typically less than 2KB).
So this means "raw" returns only small body parts less than 2kb and if the body parts are more than 2KB, there will be a problem. I have checked with some dummy emails containing email body(including inline attachments) more than 2KB, and it still works. It still returns the complete body without any problem. Sorry,if I missed something, please clear my confusion. If "raw" is working fine for all email body sizes , I will be using this approach in my project instead of "full" query parameter.
best regards,
messages.get(format=RAW) returns the entire email always. That document: https://developers.google.com/gmail/api/v1/reference/users/messages/get is incorrect and needs to be fixed.

Forward message using the Gmail API without using JavaMail

Is there a way to use the Gmail API based Message object to forward a message without using the JavaMail library (Javax)?
Thanks.
Looking for a way to bounce the Message object to another recipient WITHOUT using any JAVAMAIL classes (MimeMessage for instance)
So far no luck cause I'm pretty sure that the message's Raw will have to be re-encoded somehow.
Will love some help.
EDIT:
Found one solution which is equivalent to bouncing an message to another recipient. Thanks to Eric for the pointing me in the right direction. use the Gmail API get method for the specific email with "raw" format. decode the raw string from the parsed message->replace "To:" with new recipient address and re-encode the raw (base62url). Create a new message with newly encoded raw and send
Depends on what you mean by "Forward" I imagine. If you mean it in the "bounce message" of old mailers of yore (resend the exact same content to a new recipient without changing body or headers) then yeah should be trivial.
If, instead, you mean what more current mailers do when you forward it (set new From, To, Subject headers, include original To+Cc+From headers somewhere in the body below something like "Forwarded message" and your own user-added content) then you probably need to deal with something like javax.mail for those changes. If you're sure the emails are simple (e.g. just a text/plain part) you could attempt it without javax.mail and use the parsed Message object (format=FULL) to create a new email. But javax.mail is probably best.

Using PreAnalyzedField in Solr 4

I am trying to index fields using Solr, in which I already have a TokenStream. I dont want Solr to have any analysis - Its already made. As I understood, I could get this exact functionality using Solr's PreAnalyzedField.
The problem is that I cannot find any good resource to help me understand the flow:
I needto define the field in the schema.xml file as PreAnalyzedField, and the tokenstream should be parsed using the parse method of the parser implementation - but how to I actually feed the field with my tokeStream? how \ when exactly is it sent to the toFormattedString method???
I think PreAnalyzedField is a bleeding edge of Solr as of 4.0/4.1. The main documentation is on the Wiki and basically explains the two parser types. The default is JSON, I am not sure how to get the other type to work.
Once you have that type defined, you just supply fully-tokenized content in the JSON format as described as that field's value. When that hits the parser, it will convert it to the Token stream. The same way a number gets parsed from a string representation into a real numeric representation. Try feeding an unparsable value and you will see the full call stack in the exception stacktrace.
The problem is how to query it. My own discussion on the mailing list did not get very far.

Resources