File download and Exception handling using a servlet.

671 views
Skip to first unread message

Appien

unread,
Mar 12, 2012, 6:19:29 AM3/12/12
to google-we...@googlegroups.com
Hi guys,

In my GWT application the user can download a PDF file by using a servlet. To start the download I create in GWT a hidden Frame Object which calls the servlet. The happy workflow path works great however I want give the user some feedback when generating the PDF file fails. Since the result of the servlet call gets ‘printed’ in the Frame object, the printed exception also appears in the hidden Frame and not e.g. by a popup for the user.

Unfortunately I don’t see a way so the servlet throws directly exceptions to the AsyncCallback of GWT.

I’ve the following pseudo code for handling my exception. 

My questions are the following: 
- Is this the right way to do exception handling for servlet exceptions in GWT?
- If not, which approach should I use for this?

Many thanks for all the help!

Albert

dodo dard

unread,
Mar 12, 2012, 10:29:21 AM3/12/12
to Google Web Toolkit
Helo,

Well it is a delicate subject to handle. There is no default method to
deal with the error result.
A way to approach this, is by testing the servlet response. The
fastest is to make sure that there is no "ERROR CODE" (404, 503 ...)
in resultHtml.
But this make your application depends on your servlet container
implementation. If you can rewritte your ServletReponse, then you can
decide your own error code and how to handle it.

Hope this help you,
Bowie
====================
http://www.html5bydemo.com/

Albert van Veen

unread,
Mar 13, 2012, 3:14:52 AM3/13/12
to google-we...@googlegroups.com
Hi Bowie,

Im actually interested in how to read the error code or exception when setting an url in a frame object. When the servlet call goes correct correct, the browser shows a file download window. If the servlet call fails, the frontend needs to be aware of this somehow.

Do I need somehow read the content of the frame object? If so, how can I achieve this? There is no AsyncCallback object since I just set an url of a frame.

Thanks.

Albert

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


dodo dard

unread,
Mar 14, 2012, 5:22:42 AM3/14/12
to google-we...@googlegroups.com
Hi Appien

Ho do you call the servlet ?

==================== 
http://www.html5bydemo.com/  

Albert van Veen

unread,
Mar 14, 2012, 5:26:02 AM3/14/12
to google-we...@googlegroups.com
Hi Bowie,

I use the code below. The PDF_HOST_URL variable is the url to my local servlet. downloadFrame is a GWT Frame object.

pdfService.storeFormInSession(form, new AsyncCallback<EfPdfData>() {

public void onSuccess(EfPdfData arg0) {

RootPanel.get().remove(downloadFrame);
downloadFrame.setUrl(PDF_HOST_URL);
downloadFrame.setVisible(false); 
RootPanel.get().add(downloadFrame);
downloadFrame.addLoadHandler(new LoadHandler() {

public void onLoad(LoadEvent arg0) {
waitDialog.hide();
}
});

new ReadyStateWatch(downloadFrame, waitDialog).addReadyStateChangeHandler(
new ValueChangeHandler<ReadyState>() {

public void onValueChange(ValueChangeEvent<ReadyState> event) {

}
});

}

public void onFailure(Throwable exception) {
new EfDialog(exception.getMessage()).show();
waitDialog.hide();

}
});

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

dodo dard

unread,
Mar 14, 2012, 10:27:30 AM3/14/12
to google-we...@googlegroups.com
Well I found something interesting related to this.

Try to look at this.


=====================

George Georgovassilis

unread,
Mar 14, 2012, 11:29:19 AM3/14/12
to google-we...@googlegroups.com
Hi Albert,

The way I did this is by reading SubmitCompleteEvent.getResults(), i.e.

uploadForm.addSubmitCompleteHandler(new SubmitCompleteHandler() {
            public void onSubmitComplete(SubmitCompleteEvent event) {
 if (event.getResults().contains("SizeException")
         Window.alert("Data entry over limit");
}
}

You would just have to make sure that the servlet which handles the upload generates some meaningful, machine readable output which you can parse on the client
Reply all
Reply to author
Forward
0 new messages