0
@RequestMapping("/initSendPushNotification.html")
public String initSendPushNotification() throws FileNotFoundException {
    log.debug(".............Start initSendPushNotification method............");
    String password="Initial";
    boolean sandbox = true;
    String[] devices = {"cc287c9008c08a8d6cedb9ca22318d675c6b4bf20101244fa1964790c9585f48"
                        ,"41f888fe5dc2ac37481d6e7e6f7fac09a30ad408a016276504eab20c5db1e9ba"};
    try{
        String certificate = "/Certificates.p12";
        File keystore = new File(getClass().getResource(certificate).toURI());

        log.debug("............keystore..........."+keystore);
        List<PushedNotification> notifications=Push.alert("Hello Apple This is a test message as push! From: Recrosoft ", keystore, password, sandbox, devices);
        for (PushedNotification notification : notifications) { 
            if (notification.isSuccessful()) {
                log.debug("...............Success! Apple accepted the notification and should deliver it............"+notification);
            } 
            else { 
                String invalidToken = notification.getDevice().getToken(); 
                log.debug("...............UnSuccess! Add code here to remove invalidToken from your database............"+invalidToken); 
            }
        }
        log.debug("..............End initSendPushNotification method............");
        return "hello";
    }catch(CommunicationException e){
        log.error(".................CommunicationException.................",e);
    }
    catch(KeystoreException e){
        log.error(".................KeystoreException.................",e);
    }
    catch(URISyntaxException e){
        log.error(".................URISyntaxException.................",e);
    }
    return "hello";

}

}

我已经创建了 .p12 证书,并且获得了 64 个字长的设备令牌。在这里,上面的应用程序运行正常并从我的本地主机发送推送通知,但是当我将它部署在谷歌云中时,它不会发送推送通知,这两种情况我都使用谷歌应用引擎作为服务器。这是谷歌云抛出的异常。

[s~bbdpayment/1.382061744668575915].<stdout>: 2015-02-13 07:25:22,053 [Request 2B2E8452] ERROR (DemoController.java:54) ? .................CommunicationException.................
javapns.communication.exceptions.CommunicationException: Communication exception: com.google.apphosting.api.ApiProxy$FeatureNotEnabledException: The Socket API will be enabled for this application once billing has been enabled in the admin console.
    at javapns.communication.ConnectionToAppleServer.getSSLSocket(ConnectionToAppleServer.java:158)
    at javapns.notification.PushNotificationManager.initializeConnection(PushNotificationManager.java:106)
    at javapns.Push.sendPayload(Push.java:171)
    at javapns.Push.alert(Push.java:47)
    at com.controller.DemoController.initSendPushNotification(DemoController.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.                hi
Method.invoke(Method.java:606)
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_$1.run(Method_.java:179)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.privilegedInvoke(Method_.java:176)
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke_(Method_.java:137)
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke(Method_.java:45)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:254)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:484)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:438)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:445)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:309)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:301)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:442)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:724)
Caused by: com.google.apphosting.api.ApiProxy$FeatureNotEnabledException: The Socket API will be enabled for this application once billing has been enabled in the admin console.
    at java.lang.Thread.getStackTrace(Thread.java:1568)
    at com.google.apphosting.runtime.ApiProxyImpl.doSyncCall(ApiProxyImpl.java:258)
    at com.google.apphosting.runtime.ApiProxyImpl.access$000(ApiProxyImpl.java:69)
    at com.google.apphosting.runtime.ApiProxyImpl$1.run(ApiProxyImpl.java:201)
    at com.google.apphosting.runtime.ApiProxyImpl$1.run(ApiProxyImpl.java:198)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.google.apphosting.runtime.ApiProxyImpl.makeSyncCall(ApiProxyImpl.java:198)
    at com.google.apphosting.runtime.ApiProxyImpl.makeSyncCall(ApiProxyImpl.java:69)
    at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:116)
    at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:65)
    at com.google.appengine.api.socket.SocketApiHelper.apiProxyMakeSyncCall(SocketApiHelper.java:90)
    at com.google.appengine.api.socket.SocketApiHelper.makeSyncCall(SocketApiHelper.java:58)
    at com.google.appengine.api.socket.NameServiceImpl.lookupAllHostAddr(NameServiceImpl.java:61)
    at com.google.apphosting.util.ResolverManager$AppEngineNameservice.lookupAllHostAddr(ResolverManager.java:42)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1388)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1341)
    at java.net.InetAddress.getAllByName(InetAddress.java:1255)
    at java.net.InetAddress.getAllByName(InetAddress.java:1186)
    at java.net.InetAddress.getByName(InetAddress.java:1136)
    at java.net.InetSocketAddress.<init>(InetSocketAddress.java:220)
    at sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:409)
    at sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:88)
    at javapns.communication.ConnectionToAppleServer.getSSLSocket(ConnectionToAppleServer.java:155)
    ... 57 more
Caused by: com.google.apphosting.api.ApiProxy$FeatureNotEnabledException: The Socket API will be enabled for this application once billing has been enabled in the admin console.
    at com.google.apphosting.utils.runtime.ApiProxyUtils.convertApiError(ApiProxyUtils.java:54)
    at com.google.apphosting.runtime.ApiProxyImpl$AsyncApiFuture.success(ApiProxyImpl.java:497)
    at com.google.apphosting.runtime.ApiProxyImpl$AsyncApiFuture.success(ApiProxyImpl.java:411)
<continued in next message> 
4

1 回答 1

-1

您的例外是明确的:The Socket API will be enabled for this application once billing has been enabled in the admin console.

所以进入你的管理控制台,然后选择你的项目,并启用计费?

于 2015-02-14T18:43:06.153 回答