gwtupload icon indicating copy to clipboard operation
gwtupload copied to clipboard

Execution breaks when the server is not reachable and the returned session is empty

Open jepalenz opened this issue 8 years ago • 0 comments

When trying to submit a file for the first time, the upload session is null. Then the code tries to create a new session

if (session == null) {
   event.cancel();
   // Sends a request to the server in order to get the session
   // When the response with the session comes, it re-submits the form.
   session = Session.createSession(servletPath, onSessionReceivedCallback);
   return; 
}

If the server is not reachable, the response is an empty string, that can not be parsed by the XMLParser in the getSession method of the ISession class and the execution breaks:

public void getSession(final RequestCallback callback) {
      sendRequest("session", new RequestCallback() {
        public void onResponseReceived(Request request, Response response) {
          String s  = Cookies.getCookie("JSESSIONID");
          if (s == null) {
            s = Utils.getXmlNodeValue(XMLParser.parse(response.getText()), TAG_SESSION_ID);
          }
          setSessionId(s);
          callback.onResponseReceived(request, response);
        }
        public void onError(Request request, Throwable exception) {
          setSessionId(null);
          callback.onError(request, exception);
        }
      }, PARAM_SESSION + "=true");
    }

Here it is only checked that the returned session is not null, but the browser returns an empty string and the parser fails.

The solution here would be to catch an exception when parsing the session and calling the "onError" method of the callback if an exception is produced.

jepalenz avatar Dec 22 '16 11:12 jepalenz