Back to project page droidBBpush.
The source code is released under:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...
If you think the Android project droidBBpush listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.arg3.examples.push.api; /*from w ww .j a v a 2s . c om*/ import org.json.simple.JSONObject; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletResponse; import dagger.ObjectGraph; /** * Created by c0der78 on 2014-09-29. */ public class BaseAPIServlet extends HttpServlet { ObjectGraph objectGraph; @Override public void init() throws ServletException { super.init(); objectGraph = (ObjectGraph) getServletContext().getAttribute(ObjectGraph.class.getName()); if (objectGraph != null) { objectGraph.inject(this); } } protected void sendJSONResponse(HttpServletResponse resp, JSONObject json) throws IOException { resp.setContentType("application/json"); PrintWriter out = resp.getWriter(); out.print(json); out.flush(); } protected void sendErrorResponse(HttpServletResponse resp, String message) throws IOException { JSONObject obj = new JSONObject(); obj.put("error", message); sendJSONResponse(resp, obj); } protected void sendErrorResponse(HttpServletResponse resp, Throwable e) throws IOException { JSONObject obj = new JSONObject(); obj.put("error", e.getMessage()); sendJSONResponse(resp, obj); } }