Hi,
One way is to register a message body writer for List which will check if it contains String. It is somewhat primitive but very
simple solution which will also scale (as far as handling lists with various types is concerned) quite well.
A more type safe way is to register a writer for List<String> and then wrap
your list into a GenericEntity :
List<String> results = this.getX2dbiResults(fileContent);
return Response.ok(
new GenericEntity<List<String>>(results)).build();
cheers, Sergey
----- Original Message -----
From: "Raphael F." <[email protected]>
To: <[email protected]>
Sent: Monday, April 20, 2009 6:26 PM
Subject: Error : No message body writer found for response class : ArrayList. -
A String is OK...
Hello everibody;
In my program, i send a file @ /postXML from a client class using
HttpClient and PostMethod objects. At server side, I have 2 String
objects to return (one with data queried, the second with debug data,
both are necessary) in a List<String> object to the client but I have
a problem... Here is the server side code :
[...]
@POST
@Path("/postXML")
public Response postXML(InputStream fileContent) {
List<String> results = this.getX2dbiResults(fileContent);
Response resp = Response.ok(results).build();
return resp;
}
[...]
At client side, the code is :
[...]
RequestEntity entity = new FileRequestEntity(input, "text/xml");
PostMethod post = new PostMethod("http://localhost:9000/postXML");
post.addRequestHeader("Accept", "text/xml");
post.setRequestEntity(entity);
HttpClient httpclient = new HttpClient();
try {
int result = httpclient.executeMethod(post);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());
}
finally {
post.releaseConnection();
}
[...]
When i execute client class, I get this message :
Response status code: 500
Response body:
.No message body writer found for response class : ArrayList.
At server side, I have this information :
20 avr. 2009 18:37:16
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor
writeResponseErrorMessage
.No message body writer found for response class : ArrayList.
When I use a String for the result in Response.ok(results).build(),
there is no error, so how is it possible to return another entity than
String (i.e. an ArrayList) into Response.ok().build() ?
Thanks for all.
--
Raphaël F.
L'avenir de nos Libertés Fondamentales passe par la défense de nos
Libertés Numériques !
Promouvoir et défendre le logiciel libre : http://www.april.org/
Les projets numériques liberticides du gouvernement français et de
l'Europe : http://www.laquadrature.net/
OpenOffice.org en images : http://www.csdm.qc.ca/sitsat-mtl/openoffice/index.htm
"Ce qu'il y a de scandaleux dans le scandale, c'est qu'on s'y
habitue." Méditez-y...