Passing parameters to custom esb actions
cjunge Apr 24, 2007 11:44 AMHi, I need to pass several parameters of different types to actions so I am using an Object array.
Before I send a message to an action (through TwoWayCourrier) I this:
// 1: in sender (it's an esb aware ws actually), params is an object array Message requestMessage = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML); requestMessage.getBody().setContents(toBytes(params));
When the action receives the message it casts the result of decoding the message to an Object array and accesses it's values normally.
// 2: in action Object [] params = (Object []) toObject(message.getBody().getContents());
When I set the esb message content I use this toBytes function.
public static byte[] toBytes(Object object) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(object); return baos.toByteArray(); }
In the esb action I am decoding the message content using this toObject function:
public static Object toObject(byte[] bytes) throws Exception { Object object = null; object = new ObjectInputStream( new ByteArrayInputStream(bytes)).readObject(); return object; }
This worked ok with esb 4.0 but now I'm using the 4.2MR1 version and I get the following exception when the action tries to obtain the object array from the message content.
org.jboss.soa.esb.actions.ActionProcessingException: Unexpected invocation target exception from processor at org.jboss.soa.esb.listeners.message.ActionProcessorMethodInfo.processMethods(ActionProcessorMethodInfo.java:123) at org.jboss.soa.esb.listeners.message.OverriddenActionLifecycleProcessor.process(OverriddenActionLifecycleProcessor.java:74) at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.process(ActionProcessingPipeline.java:206) at org.jboss.soa.esb.listeners.message.MessageAwareListener$1.run(MessageAwareListener.java:300) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675) at java.lang.Thread.run(Thread.java:595) Caused by: java.lang.ClassCastException: java.lang.String at cl.falabella.met.VentasAction.GetVentas(VentasAction.java:57) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.jboss.soa.esb.listeners.message.ActionProcessorMethodInfo.processMethods(ActionProcessorMethodInfo.java:102) ... 6 more
The line the cast exception reports is the code labeled 2.
I'm not sure if this could be related to some change introduced in the 4.2 version or if I am making some mistake. I would appreciate any comments on this issue.
Thanks,
Cristian