|
Re: IllegalStateException when calling response.getOutputStream [message #701504 is a reply to message #701414] |
Mon, 25 July 2011 07:37 |
Eclipse User |
|
|
|
Originally posted by:
Andrew,
the exception is thrown because the getWriter() method has been called
on this response (see the JavaDoc of getOutputStream).
The UICallBack#runNonUIThreadWithFakeContext() is unnecessary as your
code is already executed on the UI thread.
Please see the FAQ [1] for hints on how to download files.
HTh
Rüdiger
[1] http://wiki.eclipse.org/RAP/FAQ#How_to_provide_download_link.3F
On 25.07.2011 06:24, Andrew Eisenberg wrote:
> I am calling HttpServletResponse.getOutputStream, and I get a stack
> trace like this:
>
>
> Caused by: java.lang.IllegalStateException: WRITER
> at org.mortbay.jetty.Response.getOutputStream(Response.java:594)
> at com.springsource.sts.roo.rap.RAPDownloader$1.run(RAPDownloader.java:62)
> at
> org.eclipse.rwt.internal.lifecycle.FakeContextUtil.runNonUIThreadWithFakeContext(FakeContextUtil.java:60)
>
> at
> org.eclipse.rwt.lifecycle.UICallBack.runNonUIThreadWithFakeContext(UICallBack.java:48)
>
> at com.foo.Downloader.performDownload(Downloader.java:46)
> ..
>
>
> I am trying to download a file that was generated on the server. I am
> using UICallBack.runNonUIThreadWithFakeContext as other posts have
> suggested, but this does not seem to help.
>
> Here is a snippet of the code I am running:
>
>
> Button doit = new Button(parent, SWT.PUSH);
> doit.setText("Execute command");
> doit.addSelectionListener(new SelectionListener() {
> public void widgetSelected(SelectionEvent e) {
> UICallBack.runNonUIThreadWithFakeContext(text.getDisplay(), new
> Runnable() {
> public void run() {
> HttpServletResponse response = RWT.getResponse();
> try {
> response.getOutputStream();
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> });
> }
> }
>
>
> I get the illegal state exception in the run method. Does anyone have
> any ideas how to avoid that?
>
--
Rüdiger Herrmann
Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/
Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
|
|
|
|
|
|
Re: IllegalStateException when calling response.getOutputStream [message #701889 is a reply to message #701854] |
Mon, 25 July 2011 17:57 |
Ivan Furnadjiev Messages: 2426 Registered: July 2009 Location: Sofia, Bulgaria |
Senior Member |
|
|
Hi Andrew,
it's not possible to use the standard RAP Ajax request for download
purpose. Using a service handler is the way to go.
Best,
Ivan
On 7/25/2011 8:22 PM, Andrew Eisenberg wrote:
> Thanks for your response. I did have a look at the the FAQ, but it is
> not really what I am trying to do. I do not want to create a link for
> downloading.
>
> The workflow is supposed to be like this:
>
> 1. User clicks on a SWT/RWT button widget
> 2. Application generates a zip file
> 3. Zip file is downloaded to user's machine.
>
> Is using a Service handler the only way to accomplish this? If so,
> then it would break my intended workflow since the zip file cannot be
> generated through the selection listener as I show above, but only
> through the service handler. Apologies if I am misunderstanding
> something fundamental here. I have lots of experiences with RCP, but
> little/no experience with web-apps.
>
> I would like to write to the response through the SelectionListener as
> I show above, but is this not possible?
|
|
|
|
|
|
|
Re: IllegalStateException when calling response.getOutputStream [message #703412 is a reply to message #702622] |
Wed, 27 July 2011 14:16 |
Eclipse User |
|
|
|
Originally posted by:
Adding a note like you sugested to the FAQ is certainly a good thing. I
also added a paragraph to the JavaDoc of RWT#getResponse() which now reads:
Returns the <code>HttpServletResponse</code> that is mapped to the
currently processed request.
Typical application code <em>never</em> needs to call this method. It is
meant only for service handlers to be able to write output and control
other aspects of the response.
Calling this method from a life cycle request (e.g. in an SWT event
listener) is almost certainly an error.
What do you think?
Regards,
Rüdiger
On 26.07.2011 17:33, Andrew Eisenberg wrote:
> I was thinking something like adding a short section at the end of the
> FAQ for downloading:
> http://wiki.eclipse.org/RAP/FAQ#How_to_provide_download_link.3F
>
> Something like this would have helped a lot:
>
> Please Note
>
> If you want to send a file to download, you must use a ServiceHandler.
> Responding to a standard SWT event will not work. Here's why...
--
Rüdiger Herrmann
Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/
Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
|
|
|
|
Powered by
FUDForum. Page generated in 0.04486 seconds