|
From: Jean-Paul D. <jpd...@ci...> - 2010-04-06 08:56:07
|
Hello,
I'm trying to use the StreamingOutput facility to send a server-side
generated Pdf to a client.
When I'm decoding the client-sided InputStream I have a
"ChunkedInputStream - Error parsing trailer headers" Exception
What am I missing ?
Help would be *very* appreciated,
JeP
SERVER SIDE
===========
@POST
@Path("/map2pdf")
@Consumes("application/xml")
@Produces("application/pdf")
public StreamingOutput Map2PdfRestfulStreamingImpl(GetMap2Pdf msg) throws
NamingException, IOException {
return new Map2PdfStreamingOutput(msg);
}
/*
* an inner class that implements the StreamingOutput interface
*/
private class Map2PdfStreamingOutput implements StreamingOutput {
GetMap2Pdf msg;
public Map2PdfStreamingOutput(GetMap2Pdf msg) {
this.msg = msg;
}
public void write(OutputStream output) throws IOException,
WebApplicationException {
...............
// -- response processing
try {
createPdfFacade.generatePDF(request, pdfSize0);
ByteArrayOutputStream os = createPdfFacade.getOutputStream();
os.writeTo(output);
os.close();
} catch (BusinessInputFault bif) {
throw new WebApplicationException(bif,
Response.Status.INTERNAL_SERVER_ERROR);
}
}
}
CLIENT SIDE
===========
// ==== RESTful HTTP call
ClientExecutor clientExecutor = new ApacheHttpClientExecutor(new
HttpClient(
new MultiThreadedHttpConnectionManager()));
ClientRequestFactory clientRequestFactory = new
ClientRequestFactory(clientExecutor, new URI(map2PdfServer));
ClientRequest request = clientRequestFactory.createRequest(map2PdfUrl);
// RESTful content negotiation
request.accept("application/pdf");
request.body(MediaType.APPLICATION_XML, getMap2Pdf);
// -- sends request
ClientResponse<InputStream> response = request.post(InputStream.class);
Integer status = response.getStatus();
System.out.println("status: " + status);
// gets HTTP headers
MultivaluedMap<String, String> map = response.getHeaders();
Set<String> keys = map.keySet();
for (String key : keys)
System.out.println("key: " + key + "\t value: " + map.get(key));
// gets HTTP body content
InputStream is = response.getEntity();
// -- writes Pdf file
String ext = curMedia.substring(curMedia.indexOf("/") + 1);
writeToFile(is, ext + "_" + extension);
Console
=======
status: 200
key: Content-Type value: [application/pdf]
key: X-Powered-By value: [Servlet 2.5; JBoss-5.0/JBossWeb-2.1]
key: Transfer-Encoding value: [chunked]
key: Server value: [Apache-Coyote/1.1]
key: Date value: [Fri, 02 Apr 2010 12:03:25 GMT]
Exception
=========
64422 [main] ERROR org.apache.commons.httpclient.ChunkedInputStream - Error
parsing trailer headers
org.apache.commons.httpclient.ProtocolException: Unable to parse header:
?u"???
?q???t????m??TH??
at
org.apache.commons.httpclient.HttpParser.parseHeaders(HttpParser.java:202)
at
org.apache.commons.httpclient.ChunkedInputStream.parseTrailerHeaders(ChunkedInputStream.java:322)
|