January 22, 2015
These 2 Transports Don't Play Nice Together
How 2 standard services - JMS and SMTP - may fail when they get connected.
Everyone knows JMS proxies. They are simple - just specify the URL and the proxy will read the messages from a queue.
Everyone also knows SMTP Biz services. They are, too, very simple - just provide the email text and a few required SMTP headers, and the email is sent.
There is barely any space to make a mistake, right?
Now connect them together, like this:
… and you may get this:
com.bea.wli.sb.transports.TransportException: java.lang.Integer cannot be cast to java.lang.String at com.bea.wli.sb.transports.email.util.Envelope.send(Envelope.java:153) at com.bea.wli.sb.transports.email.util.EmailUtil.sendMessage(EmailUtil.java:326) at com.bea.wli.sb.transports.email.util.EmailUtil.send(EmailUtil.java:284) at com.bea.wli.sb.transports.email.EmailOutboundMessageContext.send(EmailOutboundMessageContext.java:69) at com.bea.wli.sb.transports.email.EmailTransportProvider.sendMessageAsync(EmailTransportProvider.java:152) at sun.reflect.GeneratedMethodAccessor521.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ...
What is that?
Is it the payload? No. Is it SMTP server responding with some unexpected status? Nope.
The issue is in SMTP transport. It assumes that all headers are strings.
It is true for SMTP protocol, where headers are untyped.
However, it is not true for JMS protocol!
The queue may add its own control headers to a message, such as JMSXDeliveryCount. The values of these headers may not be strings.
In fact, the JMSXDeliveryCount is of type java.lang.Integer.
JMS proxy reads those headers OK, but it doesn’t convert them into strings, they are still integers when the message is in processing.
The last step in JMS proxy is a routing block. If the routing block has a Transport Header step which has “pass all headers” option enabled, we get the problem above. An integer header is sent to SMTP Biz where SMTP transport tries to assign its value to a variable of type java.lang.String, which causes a Java type error.
- Do not read all headers in JMS proxy. Read only those that you explicitly need.
- Or, do not pass all headers to SMTP Biz. Pass only those that you need.
I'm building SOA enterprise systems for clients large and small for almost 20 years. Most of that time I've been working with BEA (later Oracle) Weblogic platform, including OSB and other SOA systems.
Feel free to contact me if you have a SOA project to design and implement. See my profile on LinkedIn.
I live in Toronto, Ontario, Canada. Email me at email@example.com