Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was getting the exact same error. Looking at the source code for Sender.java, this appears to happen right when the Sender tries to figure out the nature of the error via HttpURLConnection.getErrorStream(). </p> <pre><code>if (status != 200) { // Exception on the line below due to getErrorStream() returning null responseBody = getString(conn.getErrorStream()); logger.finest("JSON error response: " + responseBody); throw new InvalidRequestException(status, responseBody); } </code></pre> <p>In my case the error was getting triggered due to the gcm server returning a 401 (I had forgotten I was VPNed to work and had not white-listed that IP on my Google API account). </p> <p>You are likely getting a non 200 status from the server. Try looking at what the problem is via:</p> <pre><code>$ curl -D headers.txt --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"$registrationID\"]}" &amp;&amp; cat headers.txt </code></pre> <p>where $api_key is your apiKey and $registrationID is the destination registration Id. </p> <p>The fact that the Sender doesn't handle this correctly is a different problem though, I'm not sure if it's related to the way the gcm library is attempting to read the error or if it's an issue with the jdk.. (1.6 here). It is very odd that this is getting thrown given that the GCM docs <a href="http://developer.android.com/guide/google/gcm/gcm.html#auth_error" rel="nofollow">mention this scenario</a> explicitly.</p> <p>According to the docs, <a href="http://docs.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html#getErrorStream%28%29" rel="nofollow">getErrorStream()</a> will return null:</p> <blockquote> <p>if there have been no errors, the connection is not connected or the server sent no useful data.</p> </blockquote> <ul> <li>We know there was an error (status code != 200 checked)</li> <li>We know there was a connection (401 was returned in my case)</li> <li>We know the server sends useful data:</li> </ul> <p>From an unauthorized ip:</p> <pre><code>[carlos@bad-box ~]$ curl -D headers.txt --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"$registrationID\"]}" &amp;&amp; cat headers.txt &lt;HTML&gt; &lt;HEAD&gt; &lt;TITLE&gt;Unauthorized&lt;/TITLE&gt; &lt;/HEAD&gt; &lt;BODY BGCOLOR="#FFFFFF" TEXT="#000000"&gt; &lt;H1&gt;Unauthorized&lt;/H1&gt; &lt;H2&gt;Error 401&lt;/H2&gt; &lt;/BODY&gt; &lt;/HTML&gt; HTTP/1.1 401 Unauthorized Content-Type: text/html; charset=UTF-8 Date: Tue, 14 Aug 2012 00:30:47 GMT Expires: Tue, 14 Aug 2012 00:30:47 GMT Cache-Control: private, max-age=0 X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Transfer-Encoding: chunked </code></pre> <p><strong>EDIT:</strong> This has now been entered as an issue to the GCM project here: <a href="http://code.google.com/p/gcm/issues/detail?id=7" rel="nofollow">http://code.google.com/p/gcm/issues/detail?id=7</a></p> <p><strong>EDIT:</strong> The issue has been fixed and should be available on the next release of the gcm.jar helper classes.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload