Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jepalenz opened this issue Dec 22, 2016 · 0 comments

Comments

@jepalenz
Copy link

jepalenz commented Dec 22, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant