setOutputStream closes the stream after processing. [message #362712] |
Wed, 21 May 2008 22:54 |
Eclipse User |
|
|
|
Originally posted by: user.example.net
Greetings
I'm using the Birt engine to embed the contents of a report in a
servlet. I pass the response outputstream directly to the engine, but I
find that the stream has been closed when the report is complete.
Is there a way to disable this? As a workaround I could create a stream
and convert it to a string, but I'm not sure if this sound.
Thank you, Achile B.
shortened code:
doGet(request, response)
ServletOutputStream stream = response.getOutputStream();
stream.write("Text before..".getBytes()); //Does display
//start engine, set params, settings,init task & renderoptions
htmlOptions.setHtmlRtLFlag(false);
htmlOptions.setEmbeddable(true);
htmlOptions.setOutputStream(stream );
htmlOptions.setOutputFormat("html");
task.setRenderOption(htmlOptions);
task.run();
stream.write("Text after..".getBytes()); //Does not print (!)
//stream is closed.
Workaround:
ByteArrayOutputStream foo = new ByteArrayOutputStream();
htmlOptions.setOutputStream(foo);
out.write(new String(foo.toByteArray()));
|
|
|
Re: setOutputStream closes the stream after processing. [message #363267 is a reply to message #362712] |
Tue, 17 June 2008 13:55 |
Eclipse User |
|
|
|
Originally posted by: mil.methodpark.de
Hello Achile,
I have had the same problem like you and used exactly the same workaround.
Did you perhaps find another solution meanwhile?
Regards,
Matthias
"Achille" <user@example.net> schrieb im Newsbeitrag
news:g1295e$kmm$1@build.eclipse.org...
> Greetings
> I'm using the Birt engine to embed the contents of a report in a servlet.
> I pass the response outputstream directly to the engine, but I find that
> the stream has been closed when the report is complete.
> Is there a way to disable this? As a workaround I could create a stream
> and convert it to a string, but I'm not sure if this sound.
> Thank you, Achile B.
>
> shortened code:
>
> doGet(request, response)
> ServletOutputStream stream = response.getOutputStream();
> stream.write("Text before..".getBytes()); //Does display
>
> //start engine, set params, settings,init task & renderoptions
> htmlOptions.setHtmlRtLFlag(false);
> htmlOptions.setEmbeddable(true);
> htmlOptions.setOutputStream(stream );
> htmlOptions.setOutputFormat("html");
> task.setRenderOption(htmlOptions);
> task.run();
>
> stream.write("Text after..".getBytes()); //Does not print (!)
> //stream is closed.
>
>
> Workaround:
> ByteArrayOutputStream foo = new ByteArrayOutputStream();
> htmlOptions.setOutputStream(foo);
> out.write(new String(foo.toByteArray()));
|
|
|
Re: setOutputStream closes the stream after processing. [message #1220553 is a reply to message #362712] |
Thu, 12 December 2013 14:23 |
Ibo 2050 Messages: 1 Registered: December 2013 |
Junior Member |
|
|
Hallo everybody,
I have the same problem, anyone has idee,
please help us
IRenderOption renderOption = this.getRenderOption(format);
reportingTask.setRenderOption(renderOption);
ByteArrayOutputStream reportOutput= (ByteArrayOutputStream)renderOption.getOutputStream();
when I send 2 Requestt (Parallel) I get only one Response, the other reponse can not process it, because the outputstream is already in use.......
private static final Logger LOGGER = Logger.getLogger(DefaultReportService.class.getName());
IRunAndRenderTask reportingTask = null;
public byte[] report(Format format, InputStream design, List<String> dataSourceNames, Map<String, String>dataSourcePropeties) {
this.init(design, dataSourceNames, dataSourcePropeties);
IRenderOption renderOption = this.getRenderOption(format);
reportingTask.setRenderOption(renderOption);
try {
reportingTask.run();
} catch (EngineException e) {
LOGGER.error("EngineException exception while creating report.", e);
e.printStackTrace();
} catch (Exception e){
LOGGER.error("Unexpecte exception while creating report." + e.getClass()+ " " + e.getMessage(), e);
e.printStackTrace();
} finally{
reportingTask.close();
}
ByteArrayOutputStream reportOutput = (ByteArrayOutputStream)renderOption.getOutputStream();
return reportOutput.toByteArray();
}
-
Attachment: delete.JPG
(Size: 55.08KB, Downloaded 188 times)
|
|
|
|
Powered by
FUDForum. Page generated in 0.06716 seconds