Camel overriding type converter
lewis.watson Sep 16, 2014 8:52 AMHello All,
I'm having problems with a type converted in my Switchyard project.
Inside my DocumentConverter class I have a type converter for converting an ArrayList (from an SQL binding) into an array of Document Objects
@Converter
public class DocumentConverter {
...
@Converter
public static Document[] fromAllDocuments(ArrayList<Map<String, Object>> objects) {
Document[] docs = null;
if (objects != null && !objects.isEmpty()) {
docs = new Document[objects.size()];
for (int i = 0; i < objects.size(); i++) {
System.out.println("ArrayList");
docs[i] = generateDocumentFromMap(objects.get(i));
}
}
return docs;
}
...
}
The Document object is a simple POJO
public class Document {
private String id;
private String details;
public Document(String id, String details){
this.id = id;
this.details = details;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Document [id=" + id + ", details=" + details + "]";
}
}
When I perform a GET request on a document in debug mode I put a break point inside fromAllDocuments and see that it is called correctly and the results are fine too. I can then do another GET on a different document ID and see that fromAllDocuments is correctly called again. However, at some point after process exits fromAllDocuments I get the following warning
WARN [org.apache.camel.impl.converter.DefaultTypeConverter] (http-localhost/127.0.0.1:8080-7) Overriding type converter from: StaticMethodTypeConverter: public static com.blah.data.Document[] com.blah.lookup.CaseConverter.fromCase(java.util.List) to: org.apache.camel.impl.converter.ArrayTypeConverter@6530d3aa
Subsequent GET requests all fail with an error 500 and the following warning
12:55:18,008 WARN [org.jboss.resteasy.core.SynchronousDispatcher] (http-localhost/127.0.0.1:8080-7) failed to execute: javax.ws.rs.WebApplicationException: java.lang.reflect.UndeclaredThrowableException
at org.switchyard.component.resteasy.composer.RESTEasyMessageComposer.decompose(RESTEasyMessageComposer.java:75) [switchyard-component-resteasy-1.1.1-p5-redhat-1.jar:1.1.1-p5-redhat-1]
...
Caused by: org.switchyard.HandlerException: org.apache.camel.TypeConversionException: Error during type conversion from type: java.util.ArrayList to the required type: com.blah.data.Document[] with value [{id=1, details=Hello World, case_id=1}] due null
...
Caused by: org.apache.camel.TypeConversionException: Error during type conversion from type: java.util.ArrayList to the required type:
...
Caused by: java.lang.ArrayStoreException
...
I'm at a loss to think why its overriding my conversion method during runtime. Any suggestions will be appreciated!
Switchyard version: 1.1.1
Regards
Lewis