I am having a bit of a problem with my code and that it always throws NullPointerException
:
public class WhateverResource extends ServerResource {
@Get("json")
public Representation represent(){
InputStream is = getContext().getClass().getClassLoader().getResourceAsStream("/whatever.properties");
Properties props = new Properties();
try {
props.load(is); // NPE here!
String whatever = props.getProperty("whatever_key");
setStatus(Status.SUCCESS_OK);
} catch (IOException e) {
e.printStackTrace();
setStatus(Status.SERVER_ERROR_INTERNAL);
}
return new StringRepresentation(props.toString());
}
}
I've check the genererated WAR file and in the target folder there is that properties
file under WEB-INF
folder. What could be wrong with this code?
The answer is to do this:
InputStream is = getContext().getClass().getResourceAsStream("/whatever.properties");
And GAE can read the stream without problems.
Without the getClassLoader()