0

Okay, that's embarrassing, because everything was fine in the debug mode. But when I tried to test my (almost finished) app once I deployed it, I got a 500 server error: "The server encountered an error and could not complete your request."

Maybe it's because I am trying to read a local file. I have searched on Internet for a possible solution but none of them works. Here's the code I had on the debug mode:

AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {

    String path = "C:\\Users\\Alice\\Desktop\\data.txt";
    BufferedReader br = null;
    try
    {
        br = new BufferedReader(new FileReader(path));
    }
    catch (FileNotFoundException e)
    {
        e.printStackTrace();
    }
    String line;
    try
    {
        line = br.readLine(); // In the deploy mode I got here a NullPointerException 
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}

AccessControlled allows me to read a local file from a Servlet.

Is there a possible way to read a file like in the debug mode when the app is deployed on Google App Engine?

Thank you all for the help!

Alice

EDIT: I have found the error and has nothing to do with if I am correctly reading the file or not. Looking at the logs, I saw that: The API call datastore_v3.RunQuery() required more quota than is available. Which means I have exceeded the limit of writing data on the datastore.

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
  • how did you put this file on app engine servers, btw? – Igor Artamonov Mar 13 '16 at 17:45
  • I haven't put the data.txt file on the App Engine Servers, should I? I mean, I am trying to read the file from my own desktop – Alicia Pascual Mar 13 '16 at 17:47
  • how app engine will get access to your desktop? – Igor Artamonov Mar 13 '16 at 17:48
  • Yeah, that sounds crazy. Maybe if I put the file in the WEB-INF folder could work? – Alicia Pascual Mar 13 '16 at 17:51
  • ok. there're two problems - you don't have access to file system on app engine servers. you cannot put anything there, and read. not allowed. but you can deploy file as a resource, with your code, within WEB-INF for example. and then read it as a resource, not file. and second, google servers don't have access to your home computer – Igor Artamonov Mar 13 '16 at 17:51
  • And how do I read the file as a resource? I have tried with the solutions proposed on stackoverflow and other web sites but I still got the same error. – Alicia Pascual Mar 13 '16 at 18:01
  • Which solutions did you try? There at least a few answers on SO that explain how to read a file on App Engine. – Andrei Volgin Mar 13 '16 at 18:21
  • This one: http://stackoverflow.com/questions/4340653/file-path-to-resource-in-our-war-web-inf-folder Apparently, it reads the file. But for some reason, when the data is going to be stored in the Datastore, the 500 error appears. It is possible that the error is because I am reading the file and storing the data from a doGet method within a class that extends from HttpServlet? – Alicia Pascual Mar 13 '16 at 18:48
  • I have found the error and I have already updated the post. Thank you all guys :) – Alicia Pascual Mar 13 '16 at 19:28

0 Answers0