You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by John McDonnell <mc...@gmail.com> on 2013/07/09 10:27:18 UTC

Routing CSV file to Jax WS method with multiple parameters

Hi all,

Firstly I would like to point out that I am new to Camel(<24 hours), and I
am working on a code assessment for a Job interview, which requires Camel
to be used, so if this constitutes a "Help me with my homework" type post,
please feel free to ignore.

The purpose of the assessment is to poll a directory for a CSV file and
when a CSV file is found route the contents of the CSV file to a (Jax-WS)
Web Service that is running in Apache CXF.

I have nearly all of this completed, but I am struggling with how to route
the CSV file to the Web Service.  Let me explain:  The CSV file has 4
fields, date, to, from, and value.  The WebService takes in 4 parameters,
but the types are XMLGregorianCalendar, String, String, BigDecimal.  This
has already been defined via WSDL file that came with the assessment, and
the WS was created from the WSDL file using the WSDL2Java process from
Apache CXF.

My current route is defined as so:

from(FILE PATH)
.unmarshal()
.csv()
.split().body(List.class)
.to(cxf://
http://localhost:8090/soap/Payments?serviceClass=PaymentsWebService");

When I use this route, I get a IllegalArgumentException from the WS:
*IllegalArgumentException: Part {
http://www.prototype.com/soap/examples/Payments.wsdl}date should be of type
javax.xml.datatype.XMLGregorianCalendar, not java.lang.String*

Which is fair enough as in the previous route, I would of only been using
Strings, and not the other Types of each parameter.

This lead me to the the TypeConverters, so what I did was I created a POJO
for the entries in the CSV file, and then created a TypeConverter for this,
and I updated my route as so:
from(FILE PATH)
.unmarshal()
.csv()
.split().body(List.class).convertBodyTo(Payment.class)
.to(cxf://
http://localhost:8090/soap/Payments?serviceClass=PaymentsWebService");

But now when the web service is called, I am only sending one parameter to
it, and I receive an exception:
*IllegalArgumentException: Get the wrong parameter size to invoke the out
service, Expect size 4, Parameter size 1. Please check if the message body
matches the CXFEndpoint POJO Dataformat request.*

Can someone point me in the right direction?  I am constrained in that I
cannot change the WS, so I need a way to route the contents of the CSV
file, to the WS,and converting the properties that need converting from a
string along the way.

Regards

John

Re: Routing CSV file to Jax WS method with multiple parameters

Posted by Gilles Dupont Tagne <ta...@hotmail.com>.
Hi John,

The input parameter of the
*cxf://http://localhost:8090/soap/Payments?serviceClass=PaymentsWebService*-Endpoint
have to be an instance of Object[] or
org.apache.cxf.message.MessageContentsList.

Your route have to look like this

from(FILE PATH) 
.unmarshal() 
.csv() 
.split().body(List.class)

.convertBodyTo(Object[].class) or
convertBodyTo(org.apache.cxf.message.MessageContentsList.class) 
or
.process(new ProcessListToArrayObject()) oder process(new
ProcessListToMessageContentsList())

.to(cxf:// 
http://localhost:8090/soap/Payments?serviceClass=PaymentsWebService"); 

you need either a Processor or a Converter to achieve the transformation

Regards

Gilles Tagne



--
View this message in context: http://camel.465427.n5.nabble.com/Routing-CSV-file-to-Jax-WS-method-with-multiple-parameters-tp5735343p5735391.html
Sent from the Camel - Users mailing list archive at Nabble.com.