title: How to send a message from java restful server to gcm server
body: <p>I have a java restful webservice (1) and an Android application that consumes this (2). A third application is responsible for entering data into the database via the webservice. I want that when the third application enter new data in my db, the webservice notifies the  android application by GCM. My Android application is able to receive the reg-Id GCM. (I have the project created in google developers etc, server api key..)</p>
  
  <p>I tried this: when the third app accesses the URI to enter data byPOST, sending the message to the google servers. DOES NOT WORK</p>
  
  <pre><code>@POST
  @Override
  @Consumes({"application/xml", "application/json"})
  public void create(Usuarios entity) {
   String deviceId=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...;
  
  Sender sender = new Sender("AIzaSyXXXXXXXXXXXXXXXXXXXXXXXXXXX");
   Message message = new Message.Builder()
  .addData("message", "this is the message")
  .addData("other-parameter", "some value")
  .build();
  
    Result result = sender.send(message, deviceId, 3);
  
      super.create(entity);
  }
  </code></pre>
  
  <p>I have also tried to create a servlet. But does not work</p>
  
  <pre><code>@WebServlet(name = "NewServlet_1", urlPatterns = {"/NewServlet_1"})
  public class NewServlet extends HttpServlet {
  
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      try (PrintWriter out = response.getWriter()) {
  
          out.println("&lt;!DOCTYPE html&gt;");
          out.println("&lt;html&gt;");
          out.println("&lt;head&gt;");
          out.println("&lt;title&gt;Servlet NewServlet&lt;/title&gt;");            
          out.println("&lt;/head&gt;");
          out.println("&lt;body&gt;");
          out.println("&lt;h1&gt;Servlet NewServlet at " + request.getContextPath() + "&lt;/h1&gt;");
          out.println("&lt;/body&gt;");
          out.println("&lt;/html&gt;");
      }
  }
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {    
      processRequest(request, response);
  }
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
     Sender sender = new Sender("AIzaSyBNFur3sFJpMujkVYW9rzEq3udI0khRCOI");
   Message message = new Message.Builder()
  .addData("message", "this is the message")
  .addData("other-parameter", "some value")
  .build();
    Result result = sender.send(message, "xxxxxxxxxxxx", 3);
  
      processRequest(request, response);
  }
  
  @Override
  public String getServletInfo() {
      return "Short description";
  }// &lt;/editor-fold&gt;
  </code></pre>
  
  <p>}</p>
  
  <p>Some idea ??</p>