我们正在使用google cloud messenger进行推送通知。几天前工作正常,但突然间它开始出现异常。
以下是堆栈跟踪
java.lang.IllegalArgumentException:参数不能为null com.google.android.gcm.server.Sender.nonNull(Sender.java:553)at com.google.android.gcm.server.Sender.getString(Sender.java:534)at com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:365)at com.google.android.gcm.server.Sender.send(Sender.java:261)at org.cdac.gist.restws.gcm.GCMSender.sendGCM(GCMSender.java:48)at org.cdac.gist.restws.handlers.GCMAndroidPushHandler.gcmSender(GCMAndroidPushHandler.java:156) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:498)at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory $ 1.invoke(ResourceMethodInvocationHandlerFactory.java:81) 在 org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher $ 1.run(AbstractJavaResourceMethodDispatcher.java:144) 在 org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) 在 org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider $ TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205) 在 org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) 在 org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) 在 org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) 在 org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) 在 org.glassfish.jersey.server.ServerRuntime $ 2.run(ServerRuntime.java:326) 在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:271)at at org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:267)at org.glassfish.jersey.internal.Errors.process(Errors.java:315)at org.glassfish.jersey.internal.Errors.process(Errors.java:297)at org.glassfish.jersey.internal.Errors.process(Errors.java:267)at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) 在 org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) 在 org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) 在 org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471) 在 org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425) 在 org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383) 在 org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336) 在 org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) 在 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) 在 org.cdac.gist.restws.security.ClickjackFilter.doFilter(ClickjackFilter.java:64) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 在 org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100) 在 org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:687) 在 org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.doRun(AprEndpoint.java:2508) 在 org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.run(AprEndpoint.java:2497) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在 java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) 在 org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:745)
以下是我的源代码
public final static int sendGCM(final String title, final List<String> registrationID) throws IOException{
int status = 0;
Sender sender = new Sender(apiKey);
Message message = new Message.Builder()
// .collapseKey("1")
.timeToLive(86400)//sets the time of 1 day for GCM to push notifications when android device is off, offline or unavailable
.delayWhileIdle(true)
.addData("message", title)
.build();
MulticastResult result = sender.send(message, registrationID, 1);
System.out.println("Result "+result);
if(result == null){
throw new IOException("Could not send message");
}else{
status = 1;
}
return status;
}
答案 0 :(得分:1)
问题是由于GCM支持单条消息最多1,000个收件人
所以我将注册ArrayList分成1000个相等的部分,然后我将消息发送给GCM。现在我可以发送推送通知。
以下是我更新的代码
public final static int sendGCM(final String title, final List<String> registrationID) throws IOException{
int status = 0;
MulticastResult result =null;
for (int start = 0; start < registrationID.size(); start += 1000) {
int end = Math.min(start + 1000, registrationID.size());
List<String> sublist = registrationID.subList(start, end);
System.out.println(sublist);
Sender sender = new Sender(apiKey);
Message message = new Message.Builder()
// .collapseKey("1")
.timeToLive(86400)//sets the time of 1 day for GCM to push notifications when android device is off, offline or unavailable
.delayWhileIdle(true)
.addData("message", title)
.build();
result = sender.send(message, sublist, 1);
System.out.println("Result "+result);
}
if(result == null){
throw new IOException("Could not send message");
}else{
status = 1;
}
return status;
}