Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8724849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:54:48+00:00 2026-06-13T07:54:48+00:00

As many other newbies to java and android i’m trying to run gcm demo

  • 0

As many other newbies to java and android i’m trying to run gcm demo server and gcm demo client on windows, using eclipse to run vertual device and tomcat as a webserer.

I have no problems with registering and unregestering device but i got an error 401 when trying to send a message. Read a lot answers on similar questions but still don’t have a clue what i’m doing wrong. I put apy key, server url and sender id in places mentioned in tutorial. Also changed code in SendAllMessagesServlet.java a bit:

// Processes the request to add a new message.  
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp)
  throws IOException, ServletException {
    List<String> devices = Datastore.getDevices();
    String status;
    if (devices.isEmpty()) {
        status = "Message ignored as there is no device registered!";
    } else {
        // NOTE: check below is for demonstration purposes; a real application
        // could always send a multicast, even for just one recipient
        // MY CODE
        String collapseKey = "mycollapsekey";
        String userMessage = "testmessage";
        // END OF MY CODE
        if (devices.size() == 1) {
            // send a single message using plain post
            String registrationId = devices.get(0);
            //  Message message = new Message.Builder().build();
            //  BELOW I HAVE CHANGED MESSAGE BUILDING A BIT:
            Message message = new Message.Builder()
                .collapseKey(collapseKey)
                .timeToLive(30)
                .delayWhileIdle(true)
                .addData("message", userMessage)
                .build();
            Result result = sender.send(message, registrationId, 5);
            status = "Sent message to one device: " + result;
        } else {
            // send a multicast message using JSON
            // must split in chunks of 1000 devices (GCM limit)
            int total = devices.size();
            List<String> partialDevices = new ArrayList<String>(total);
            int counter = 0;
            int tasks = 0;
            for (String device : devices) {
                counter++;
                partialDevices.add(device);
                int partialSize = partialDevices.size();
                if (partialSize == MULTICAST_SIZE || counter == total) {
                    asyncSend(partialDevices);
                    partialDevices.clear();
                    tasks++;
                }
            }
            status = "Asynchronously sending " + tasks + " multicast messages to " + total + " devices";
        }
    }
    req.setAttribute(HomeServlet.ATTRIBUTE_STATUS, status.toString());
    getServletContext().getRequestDispatcher("/home").forward(req, resp);
}

But I still get next error when sending message, here is my tomcat localhost log file:

окт 22, 2012 1:06:39 PM org.apache.catalina.core.ApplicationContext log
INFO: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
окт 22, 2012 1:06:39 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
окт 22, 2012 1:06:39 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
окт 22, 2012 1:06:39 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
окт 22, 2012 1:06:39 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
окт 22, 2012 1:07:05 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet SendAllMessagesServlet threw exception
com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401
    at com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:177)
    at com.google.android.gcm.server.Sender.send(Sender.java:121)
    at com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServlet.java:93)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:881)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:674)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:541)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Unknown Source)

Stderr log:

2012-10-22 13:06:37 Commons Daemon procrun stderr initialized
окт 22, 2012 1:06:38 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Android\android-sdk\tools;C:\Program Files\Android\android-sdk\platform-tools;c:\ant\bin;C:\Program Files\Java\jdk1.7.0_07\lib;;.
окт 22, 2012 1:06:38 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
окт 22, 2012 1:06:38 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 531 ms
окт 22, 2012 1:06:38 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
окт 22, 2012 1:06:38 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.36
окт 22, 2012 1:06:38 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
окт 22, 2012 1:06:39 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive gcm-demo.war
окт 22, 2012 1:06:39 PM com.google.android.gcm.demo.server.ApiKeyInitializer contextInitialized
INFO: Reading /api.key from resources (probably from WEB-INF/classes
окт 22, 2012 1:06:39 PM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
окт 22, 2012 1:06:39 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
окт 22, 2012 1:06:39 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/32  config=null
окт 22, 2012 1:06:39 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
окт 22, 2012 1:06:39 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1219 ms
окт 22, 2012 1:06:58 PM com.google.android.gcm.demo.server.Datastore register
INFO: Registering APA91bF0kArKvvJsHu4qS92FQl-CLKt0CJL8_SrtyL9OkGSqQQUMywMvPhulG4xmdiX_uVhdXs6xERY5pwQzHES-aI-tBCOgMZ_JOBT8S_RIK9XhyQDf49Yfr9g4nSnfgN2GIJHlnqTA4mAJBolnjfuQKLmULl0g5g

What I’ve missed or where to read more on such a problems solving?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:54:49+00:00Added an answer on June 13, 2026 at 7:54 am

    I just answered a similar question – accessing /gcm-demo/sendAll. Reason: HTTP Status Code: 401

    Check the sender API key that you are using.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using boost::program_options and it suffers from the same as many other c++ libs,
I have this custom JSlider, which will be used in many other forms/windows. But
C++ has std::vector and Java has ArrayList , and many other languages have their
I'm a newbie to eclipse. (I've done many java programs through command line) I'm
As many other developers new to Cocoa, I struggle with delegate and controller concept.
Seen many other similar questions like this on this website and i would say
I have looked at many other threads that show how to use accelerometer values,
The following code works fine in firefox but as with many other things, I
Was just wondering how do these sites (and many other softwares that generate flash
Possible duplicate of: should-i-link-to-google-apis-cloud-for-js-libraries also many other discussions, including: Where do you include the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.