Spring Framework on GAE Standard Java 8 / Remote API in Thread

67 views
Skip to first unread message

Bernard Willemot

unread,
Oct 26, 2017, 9:03:46 AM10/26/17
to Google App Engine
Running spring-boot on Google Appengine Standard/Java8.

Is it possible to access the datastore from a thread created in the spring framework? For example in events to give an example.

Have been trying for days without success. Working fine on DevAppServer, but not in production on GAE. Also works fine in separate java application.

I do understand that I have to install the remote api on those created threads? This is the part where it fails.

Tried with every possible method I found, to no success.

Using .p12 file and service account.


PrivateKey private_key = null;


                                               


                                                        try {


                                       


                                                                private_key = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(),


                                                           


                                         


                                                                getClass().getClassLoader().getResourceAsStream("aap-id-9999999.p12"),


                                                                        "notasecret", "private_key", "notasecret");


                                       


                                                } catch (GeneralSecurityException e) {


                                                       


                                                    e.printStackTrace(System.err);


                                                   


                                                } catch (IOException e) {


                                                       


                                                    e.printStackTrace(System.err);


                                                   


                                                }


                                                                                                                       


                                                        options =


                                                                new RemoteApiOptions()


                                                                        .server(googleCloudProject + ".appspot.com", 443)


                                                ////.useServiceAccountCredential(service_account_e_mail, new ClassPathResource("aap-id-9999999.p12").getFile().getAbsolutePath())


                                                //.useServiceAccountCredential(service_account_e_mail, credential.getServiceAccountPrivateKey())


                                                .useServiceAccountCredential(service_account_e_mail, private_key)


                                                //.useApplicationDefaultCredential()


                                                ;


Exception would be raised on:

installer.install(options);



[e~cloudlatching-dev/20171026t085910.405069418774964093].<stdout>: 2017-10-26 07:03:56.888 ERROR 1 --- [-163887603-mqtt] eu.cloudlatching.web.config.Application  : Problem in M2MFactoryEventListener.

java
.lang.NullPointerException: null
        at com
.google.appengine.repackaged.com.google.api.client.util.SecurityUtils.loadKeyStore(SecurityUtils.java:84) ~[appengine-remote-api-1.9.58.jar:na]
        at com
.google.appengine.repackaged.com.google.api.client.googleapis.GoogleUtils.getCertificateTrustStore(GoogleUtils.java:76) ~[appengine-remote-api-1.9.58.jar:na]
        at com
.google.appengine.repackaged.com.google.api.client.googleapis.javanet.GoogleNetHttpTransport.newTrustedTransport(GoogleNetHttpTransport.java:55) ~[appengine-remote-api-1.9.58.jar:na]
        at com
.google.appengine.tools.remoteapi.RemoteApiOptions.getOrCreateHttpTransportForOAuth(RemoteApiOptions.java:357) ~[appengine-remote-api-1.9.58.jar:na]
        at com
.google.appengine.tools.remoteapi.RemoteApiOptions.getCredentialBuilder(RemoteApiOptions.java:245) ~[appengine-remote-api-1.9.58.jar:na]
        at com
.google.appengine.tools.remoteapi.RemoteApiOptions.useServiceAccountCredential(RemoteApiOptions.java:213) ~[appengine-remote-api-1.9.58.jar:na]
        at eu
.cloudlatching.web.config.Application$M2MFactoryEventListener.onApplicationEvent(
Application.java:703) [classes/:na]
        at eu
.cloudlatching.web.config.Application$M2MFactoryEventListener.onApplicationEvent(
Application.java:1) [classes/:na]
        at org
.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(
SimpleApplicationEventMulticaster.java:172) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(
SimpleApplicationEventMulticaster.java:165) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(
SimpleApplicationEventMulticaster.java:139) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.context.support.AbstractApplicationContext.publishEvent(
AbstractApplicationContext.java:393) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.context.support.AbstractApplicationContext.publishEvent(
AbstractApplicationContext.java:347) [spring-context-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at eu
.cloudlatching.web.config.Application$1.handleMessage(
Application.java:397) [classes/:na]
        at org
.springframework.integration.config.annotation.ServiceActivatorAnnotationPostProcessor$ReplyProducingMessageHandlerWrapper.handleRequestMessage(
ServiceActivatorAnnotationPostProcessor.java:98) [spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(
AbstractReplyProducingMessageHandler.java:109) [spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.integration.handler.AbstractMessageHandler.handleMessage(
AbstractMessageHandler.java:127) [spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(
AbstractDispatcher.java:116) [spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(
UnicastingDispatcher.java:148) [spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(
UnicastingDispatcher.java:121) [spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.integration.channel.AbstractSubscribableChannel.doSend(
AbstractSubscribableChannel.java:89) [spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.integration.channel.AbstractMessageChannel.send(
AbstractMessageChannel.java:425) [spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.integration.channel.AbstractMessageChannel.send(
AbstractMessageChannel.java:375) [spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.messaging.core.GenericMessagingTemplate.doSend(
GenericMessagingTemplate.java:115) [spring-messaging-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.messaging.core.GenericMessagingTemplate.doSend(
GenericMessagingTemplate.java:45) [spring-messaging-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.messaging.core.AbstractMessageSendingTemplate.send(
AbstractMessageSendingTemplate.java:105) [spring-messaging-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.integration.endpoint.MessageProducerSupport.sendMessage(
MessageProducerSupport.java:188) [spring-integration-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter.messageArrived(
MqttPahoMessageDrivenChannelAdapter.java:328) [spring-integration-mqtt-4.3.12.RELEASE.jar:4.3.12.RELEASE]
        at org
.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(
CommsCallback.java:354) [org.eclipse.paho.client.mqttv3-1.0.2.jar:na]
        at org
.eclipse.paho.client.mqttv3.internal.CommsCallback.run(
CommsCallback.java:162) [org.eclipse.paho.client.mqttv3-1.0.2.jar:na]
        at java
.lang.Thread.run(Thread.java:745) [na:1.8.0_112-google-v7]



Using the latest version of GAE 1.9.58.

Hope someone can confirm, BW.

Nilson Pontello

unread,
Oct 26, 2017, 1:25:29 PM10/26/17
to Google App Engine
I've seen this a few times when trying to use AppIdentity apis from request scoped threads.  But on my case the issue happened because GAE was killing the thread as it can't outlive the request.

Try using appengine background threads and check if problem will be fixed.

Regards

Bernard Willemot

unread,
Oct 27, 2017, 12:11:46 PM10/27/17
to Google App Engine
I understand that, but I am not creating the threads myself, they are created by Spring Boot. Not sure I can manually create them using the appengine thread system? I am referring to is a thread, but I am really exiting it properly after the event is received. 

I believe the M2MFactoryEventListener Not sure GAE is destroying it?

You mean try to create a Thread myself and see if it goes well there?

Yannick (Cloud Platform Support)

unread,
Oct 27, 2017, 6:19:07 PM10/27/17
to Google App Engine
If you haven't already done so, I suggest you ask your question on Stack Overflow. It is better suited to such technical questions.
Reply all
Reply to author
Forward
0 new messages