Search code examples
google-app-engineandroid-c2dm

Does anyone know why C2DMConfigLoader (c2dm-server.jar) was changed subtly?


In an eclipse c2dm connected project, the c2dm-server.jar is generated for you and added to your project. If you dig inside the source for it you'll see that it's pretty much the same as the source from the original chrometophone project:

http://code.google.com/p/chrometophone/source/browse/trunk/appengine/c2dm/com/google/android/c2dm/server/C2DMConfigLoader.java?r=2

But there's one big difference: the InputStream line was changed from:

InputStream is = this.getClass().getClassLoader()
                                .getResourceAsStream("/dataMessagingToken.txt");

To

InputStream is = servletContext.getResourceAsStream("/dataMessagingToken.txt");

The big difference being that you now require a ServletContext and not just any class to grab that dataMessagingToken.txt resource out of the war. The only reason I ask is because I'm trying to reinstate that old style line thus not requiring a ServletContext to get that resource, but for whatever reason that line no longer works and it can never find the file. (to be clear, I've tried putting that file in the war's base directory as the default project had it, and also in the /WEB-INF/classes directory also as others have suggested)

One last thing, for those wondering why I want to do this and not just pass a ServletContext. It's because I want to do the sending from the task queue and not from any user interaction. So I'm probably going about this all the wrong way, but I feel I'm close .

Thanks!


Solution

  • You can fight this, or I think you will find that tasks in a task queue are executed as servlets and will also have a ServletContext.

    Also, if not passed down through your calls, you should be able to get it anywhere via:

    getThreadLocalRequest().getSession().getServletContext()