java.security.AccessControlException when sending JMS message in GAE - google-app-engine

I am trying to send a JMS message to tibco designer using GAE. Here are my codes:
try{
Connection connection = null;
Session session = null;
MessageProducer msgProducer = null;
Destination destination = null;
String userName = null;
String password = null;
String destName = "q.message";
TextMessage msg = null;
ConnectionFactory factory = new TibjmsConnectionFactory("localhost");
connection = factory.createConnection(userName, password);
/* create the session */
session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
/* create the destination */
destination = session.createQueue(destName);
//replyDestination = session.createTopic("reply.topic");
/* create the producer */
msgProducer = session.createProducer(null); //changed for request-reply
//replyConsumer = session.createConsumer(replyDestination); //for request-reply
/* start the connection */
connection.start();
/* create text message */
msg = session.createTextMessage();
/* set message text */
msg.setText(message);
//msg.setJMSReplyTo(replyDestination); //for request-reply
/* publish message */
msgProducer.send(destination, msg); //Send XML message to destination
}catch(JMSException e){
System.out.println("Error");
}
However, after running this web application, i got the following error:
Nov 10, 2013 11:04:36 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: /process_message.do
java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
at java.security.AccessController.checkPermission(AccessController.java:549)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:383)
at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkAccess(DevAppServerFactory.java:408)
at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:299)
at java.lang.Thread.init(Thread.java:336)
at java.lang.Thread.<init>(Thread.java:434)
at com.tibco.tibjms.TibjmsxLinkTcp$Pinger.<init>(TibjmsxLinkTcp.java:142)
at com.tibco.tibjms.TibjmsxLinkTcp._createPinger(TibjmsxLinkTcp.java:223)
at com.tibco.tibjms.TibjmsxLinkTcp._doHandshake(TibjmsxLinkTcp.java:900)
at com.tibco.tibjms.TibjmsxLinkTcp.connect(TibjmsxLinkTcp.java:923)
at com.tibco.tibjms.TibjmsConnection._create(TibjmsConnection.java:1299)
at com.tibco.tibjms.TibjmsConnection.<init>(TibjmsConnection.java:4155)
at com.tibco.tibjms.TibjmsxCFImpl._createImpl(TibjmsxCFImpl.java:209)
at com.tibco.tibjms.TibjmsxCFImpl._createConnection(TibjmsxCFImpl.java:253)
at com.tibco.tibjms.TibjmsConnectionFactory.createConnection(TibjmsConnectionFactory.java:58)
at com.ebs.process_buy.doPost(process_buy.java:108)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
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.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
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 com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:368)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:351)
at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
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.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:485)
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.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Does that mean that GAE cannot work with JMS as JMS uses database connection and GAE needs to use their own cloud database? How can I work around this?
Thank you for your help.

Try to specify the full EMS provider URL in the form tcp://host:port. For example:
ConnectionFactory factory = new TibjmsConnectionFactory("tcp://localhost:7222");

Related

Dataflow Program on Google App Engine

public class DemoServlet extends HttpServlet {
/*
code for getting the data from the REST api and putting it into
HashMap Collection and then creating the pipeline from that collection and writing the pipeline into bq table */
String[] credentials = {"--project=" + projectId, "--stagingLocation=" + staggingLocation};
PipelineOptionsFactory.Builder builder = PipelineOptionsFactory.fromArgs(credentials);
PipelineOptions options = builder.create();
//Setting to run the pipeline in google cloud.By Changing this parameter we can run even in local mode
options.setRunner(DataflowPipelineRunner.class);
//Creating pipeline with above options
Pipeline youTubeChannelPipeline = Pipeline.create(options);
PCollection<String> lines = null;
lines = youTubeChannelPipeline.apply(Create.of(allValues)).setCoder(StringUtf8Coder.of());
//Transforming PCollection<String> to PCollection<TableRow> and then writing to bq
bqRows = lines.apply(ParDo.named("Transforming String To TableRow").of(new DoFn() {
#Override
public void processElement(ProcessContext pc) throws Exception {
TableRow tmpRow = new TableRow();
String[] columns = pc.element().split(YoutubeConstants.COMA_DELIMITER);
for (int i = 0; i < no_of_col; i++) {
tmpRow.set(YoutubeConstants.CHANNEL_LEVEL_HEADERS[i], columns[i]);
}
pc.output(tmpRow);
}
}));
//Writing the rows in bq table
bqRows.apply(BigQueryIO.Write
.named("Write To BQ")
.to(destination_path)
.withSchema(schema)
.withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND)
.withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED));
youTubeChannelPipeline.run();
W 12:36:16.124 /demo
java.lang.RuntimeException: Failed to construct instance from factory method com.google.cloud.dataflow.sdk.runners.DataflowPipelineRunner#fromOptions
at com.google.cloud.dataflow.sdk.util.InstanceBuilder.buildFromMethod(InstanceBuilder.java:228)
at com.google.cloud.dataflow.sdk.util.InstanceBuilder.build(InstanceBuilder.java:161)
at com.google.cloud.dataflow.sdk.runners.PipelineRunner.fromOptions(PipelineRunner.java:52)
at com.google.cloud.dataflow.sdk.Pipeline.create(Pipeline.java:117)
at myapp.DemoServlet.doGet(DemoServlet.java:91)
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:257)
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:482)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:230)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:234)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at com.google.appengine.runtime.Request.process-8f9b045d763b7321(Request.java)
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.Method.invoke(Method.java:45)
at com.google.cloud.dataflow.sdk.util.InstanceBuilder.buildFromMethod(InstanceBuilder.java:221)
at com.google.cloud.dataflow.sdk.util.InstanceBuilder.build(InstanceBuilder.java:161)
at com.google.cloud.dataflow.sdk.runners.PipelineRunner.fromOptions(PipelineRunner.java:52)
at com.google.cloud.dataflow.sdk.Pipeline.create(Pipeline.java:117)
at myapp.DemoServlet.doGet(DemoServlet.java:91)
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 org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
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 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 org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:230)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
... 1 more
Caused by: java.lang.RuntimeException: Unable to get application default credentials. Please see https://developers.google.com/accounts/docs/application-default-credentials for details on how to specify credentials. This version of the SDK is dependent on the gcloud core component version 2015.02.05 or newer to be able to get credentials from the currently authorized user via gcloud auth.
at com.google.cloud.dataflow.sdk.util.Credentials.getCredential(Credentials.java:122)
at com.google.cloud.dataflow.sdk.util.GcpCredentialFactory.getCredential(GcpCredentialFactory.java:43)
at com.google.cloud.dataflow.sdk.options.GcpOptions$GcpUserCredentialsFactory.create(GcpOptions.java:185)
at com.google.cloud.dataflow.sdk.options.GcpOptions$GcpUserCredentialsFactory.create(GcpOptions.java:175)
at com.google.cloud.dataflow.sdk.options.ProxyInvocationHandler.getDefault(ProxyInvocationHandler.java:288)
at com.google.cloud.dataflow.sdk.options.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:127)
at com.sun.proxy.$Proxy20.getGcpCredential(Unknown Source)
at com.google.cloud.dataflow.sdk.util.Transport.newDataflowClient(Transport.java:120)
at com.google.cloud.dataflow.sdk.options.DataflowPipelineDebugOptions$DataflowClientFactory.create(DataflowPipelineDebugOptions.java:157)
at com.google.cloud.dataflow.sdk.options.DataflowPipelineDebugOptions$DataflowClientFactory.create(DataflowPipelineDebugOptions.java:154)
at com.google.cloud.dataflow.sdk.options.ProxyInvocationHandler.getDefault(ProxyInvocationHandler.java:288)
at com.google.cloud.dataflow.sdk.options.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:127)
at com.sun.proxy.$Proxy20.getDataflowClient(Unknown Source)
at com.google.cloud.dataflow.sdk.runners.DataflowPipelineRunner.<init>(DataflowPipelineRunner.java:160)
<continued in next message>
W 12:36:16.124 <continued from previous message>
at com.google.cloud.dataflow.sdk.runners.DataflowPipelineRunner.fromOptions(DataflowPipelineRunner.java:155)
... 34 more
Caused by: java.io.IOException: Application Default Credentials failed to create the Google App Engine service account credentials class com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential$AppEngineCredentialWrapper. Check that the component 'google-api-client-appengine' is deployed.
at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.tryGetAppEngineCredential(DefaultCredentialProvider.java:274)
at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredentialUnsynchronized(DefaultCredentialProvider.java:159)
at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:86)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:213)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:191)
at com.google.cloud.dataflow.sdk.util.Credentials.getCredential(Credentials.java:120)
... 48 more
Caused by: java.lang.ClassNotFoundException: com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential$AppEngineCredentialWrapper
at com.google.appengine.runtime.Request.process-8f9b045d763b7321(Request.java)
at java.lang.Class.forName(Class.java:136)
at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.forName(DefaultCredentialProvider.java:208)
at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.tryGetAppEngineCredential(DefaultCredentialProvider.java:259)
... 53 more
Support for getting credentials compatible with Dataflow via Application Default Credentials in AppEngine exists in version 1.9.20+ of the Google API libraries. Please make sure that your WAR that you deploy to AppEngine contains google-api-client version 1.9.20+ and google-api-client-appengine version 1.9.20+. Beware that you may need to upgrade other dependencies because of this change.

SocketTimeoutException using Parse REST API at GAE

I use GAE as a server for my app, and when something occurs I want to notify the relevant users about it. I use Parse REST API to do this push notification (not GCM because I have iphone user too). But sometimes (can't realize when) I get
java.net.SocketTimeoutException: Timeout while fetching: https://api.parse.com/1/push
at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:52)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.fetchResponse(URLFetchServiceStreamHandler.java:417)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getInputStream(URLFetchServiceStreamHandler.java:296)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getResponseCode(URLFetchServiceStreamHandler.java:149)
at com.starling.parse.PushNotifications.sendRequest(PushNotifications.java:113)
at com.starling.parse.PushNotifications.sendPushUpdate(PushNotifications.java:71)
at com.starling.parse.PushNotifications.notifyUsersWithSongUpdates(PushNotifications.java:121)
at com.straling.server.db.actions.VoteActions$1.run(VoteActions.java:86)
at com.straling.server.db.actions.VoteActions$1.run(VoteActions.java:1)
at com.googlecode.objectify.impl.cmd.ObjectifyImpl.transactOnce(ObjectifyImpl.java:257)
at com.googlecode.objectify.impl.cmd.ObjectifyImpl.transactNew(ObjectifyImpl.java:234)
at com.googlecode.objectify.impl.cmd.ObjectifyImpl.transactNew(ObjectifyImpl.java:224)
at com.googlecode.objectify.impl.cmd.ObjectifyImpl.transact(ObjectifyImpl.java:216)
at com.straling.server.db.actions.VoteActions.newVote(VoteActions.java:50)
at com.straling.server.servlets.VoteSongServlet.doPost(VoteSongServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
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.googlecode.objectify.cache.AsyncCacheFilter.doFilter(AsyncCacheFilter.java:59)
at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:49)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:110)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
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 com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
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.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:380)
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.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
and when it happens, it happens immediately (not after 45 sec. which is GAE request timeout)?
My code :
private static void sendRequest(String payload) throws IOException {
HttpURLConnection connection = null;
URL urlObject = new URL("https://api.parse.com/1/push");
connection = (HttpURLConnection) urlObject.openConnection();
connection.setRequestProperty("X-Parse-Application-Id", APPLICATION_ID);
connection.setRequestProperty("X-Parse-REST-API-Key", REST_API_KEY);
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.getOutputStream().write(payload.getBytes());
connection.getResponseCode();
}
The payload string :
{ "channel": "vID18483", "data": {"action": "com.starling.app.UPDATE_SONGS","songs":[{"id":36209,"length":0,"points":104,"isPlaying":false,"isInPlaylist":true}]}}
Any suggestions?
Thanks,
Dan
URLConnection on GAE has a default deadline of 5 seconds. You should increase that by setting connection timeout via setConnectTimeout() plus the read timeout via setReadTimeout(). Both connection and read timeout together are a deadline time, which can be max 60s.

GAE Java- Null pointer exception when trying to retrieve an object

I am new to GAE development.
for me insertion using jpa to the datastore is working fine, but retrieval is not happening.
Below is a method which authenticates the user when he try to login.
public boolean loginUser(User user) {
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("SOAApp");
EntityManager mgr = emf.createEntityManager();
boolean login=false;
Query query=mgr.createQuery("select u from User u where u.userName=:uid and u.password=:pwd");
query.setParameter("uid", user.getUserName());
query.setParameter("pwd",user.getPassword());
query.setMaxResults(1);
try {
user=(User) query.getSingleResult();
System.out.println("user : "+user.getName());
if(user!=null) {
System.out.println("logged in...");
login=true;
}
}
catch(Exception e) {
e.printStackTrace();
}
finally {
mgr.close();
}
return login;
}
but I am getting the following errors when trying to execute the method by passing a user object with valid username and password.
java.lang.NullPointerException
at com.google.appengine.datanucleus.query.QueryEntityPKFetchFieldManager.fetchIntField(QueryEntityPKFetchFieldManager.java:70)
at org.datanucleus.identity.IdentityUtils.getApplicationIdentityForResultSetRow(IdentityUtils.java:93)
at com.google.appengine.datanucleus.EntityUtils.entityToPojo(EntityUtils.java:1009)
at com.google.appengine.datanucleus.query.DatastoreQuery$2.apply(DatastoreQuery.java:228)
at com.google.appengine.datanucleus.query.DatastoreQuery$2.apply(DatastoreQuery.java:225)
at com.google.appengine.datanucleus.query.LazyResult.resolveNext(LazyResult.java:96)
at com.google.appengine.datanucleus.query.LazyResult.resolveAll(LazyResult.java:121)
at com.google.appengine.datanucleus.query.LazyResult.size(LazyResult.java:115)
at com.google.appengine.datanucleus.query.StreamingQueryResult.size(StreamingQueryResult.java:151)
at org.datanucleus.store.query.Query.executeQuery(Query.java:1808)
at org.datanucleus.store.query.Query.executeWithMap(Query.java:1693)
at org.datanucleus.api.jpa.JPAQuery.getSingleResult(JPAQuery.java:231)
at com.soa.managers.UserManager.loginUser(UserManager.java:63)
at com.soa.servlets.LoginServlet.doPost(LoginServlet.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
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.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
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 com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
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.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:383)
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.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Nov 03, 2012 3:25:02 PM com.google.appengine.tools.development.LocalResourceFileServlet doGet
line number-63
[at com.soa.managers.UserManager.loginUser(UserManager.java:63)]
is "user=(User) query.getSingleResult();"
Please help me
Still searching?
I had the same problem and my entity User had a primaryKey named userId that was of type 'int'. Now I changed it to 'Long' and all of my problems and warnings are all gone! Maybe this helps you out!
I look forward hearing from you!
Regards,
Stephan
The reason why u get nullpointerexception is that getSingleResult method returns null. Because u used (User)query.getSingleResult(), the typecasting of null value throws exception.
I think there is no related user in datastore, so you are getting exception.
<?xml version="1.0" encoding="UTF-8"?>
<datastore-indexes autoGenerate="true">
<datastore-index kind="HABERLER" ancestor="false" source="manual">
<property name="__key__" direction="desc"/>
</datastore-index>
HABERLER is table name. Write your table name instead of HABERLER. Then create a datastore-indexes.xml file in WEB-INF directory. Then copy above code into this file.
Make sure you that the keys for your entities are of valid types as detailed here:
https://developers.google.com/appengine/docs/java/datastore/jdo/creatinggettinganddeletingdata#Keys
The exception you are getting is most likely related to a key issue.

TransientFailureException -- > While leasing tasks from pull queue

We are using pull queues with backends in our scenario and our backend tries to lease tasks from our pull queue after some fixed intervals and in case there are no tasks , it does not do anything and in case there are any , those are processed . Yesterday we got this TransientFailureException in our system , which exactly is happening while my servlet is trying to lease task from pull queue . And the exception kept coming until we stopped our backend .
Our code snippet --
{
Boolean leasedTaskFromFastQueue = true;
Queue fastQueue = QueueFactory.getQueue("FastQueue");
Queue slowQueue = QueueFactory.getQueue("SlowQueue");
List<TaskHandle> tasks = fastQueue.leaseTasks(
3600, TimeUnit.SECONDS, 1);
TaskHandle taskHandle = null;
if(tasks.size() > 0) {
taskHandle = tasks.get(0);
}
}
We aret getting error on the line where we lease task from fastQueue , which is a pull queue
<queue>
<name>FastQueue</name>
<mode>pull</mode>
</queue>
I am also pasting my error trace , in case that helps
com.google.appengine.api.taskqueue.TransientFailureException:
at com.google.appengine.api.taskqueue.QueueApiHelper.translateError(QueueApiHelper.java:79)
at com.google.appengine.api.taskqueue.QueueApiHelper.translateError(QueueApiHelper.java:139)
at com.google.appengine.api.taskqueue.QueueApiHelper.makeSyncCall(QueueApiHelper.java:53)
at com.google.appengine.api.taskqueue.QueueImpl.leaseTasksInternal(QueueImpl.java:709)
at com.google.appengine.api.taskqueue.QueueImpl.leaseTasks(QueueImpl.java:731)
at com.implementhit.advancedsupport.server.queue.Backend.doGet(Backend.java:50)
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.bitdual.appengine.tools.datastore.server.NamespaceFilter.doFilter(NamespaceFilter.java:96)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102)
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.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:249)
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:135)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:477)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:449)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:455)
at com.google.tracing.TraceContext.runInContext(TraceContext.java:695)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:333)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:325)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:453)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
at java.lang.Thread.run(Thread.java:679)
It happend to us also, TransientFailureException is an internal error that as far as we could see had nothing to do with our code. We ended up by automatically restarting the backend if 50 errors happened in a row.

How can I retrieve a blobstore file by name

I wrote the following code:
FileService fileService = FileServiceFactory
.getFileService();
// Create a new Blob file with mime-type "text/plain"
AppEngineFile file = fileService.createNewBlobFile(
"image/jpeg", name);
if(null!=file)
log.warn(file.toString());
FileReadChannel readChannel =
fileService.openReadChannel(
file, true);
// Again, different standard Java ways of reading from
// the
// channel.
BufferedReader reader = new BufferedReader(Channels
.newReader(readChannel, "UTF8"));
String line = reader.readLine();
resp.setContentType("text/plain");
resp.getWriter().println(line);
readChannel.close();
But unfortunately, it gives me the following exception:
Uncaught exception from servlet
com.google.appengine.api.files.FinalizationException
at com.google.appengine.api.files.FileServiceImpl.translateException(FileServiceImpl.java:597)
at com.google.appengine.api.files.FileServiceImpl.makeSyncCall(FileServiceImpl.java:574)
at com.google.appengine.api.files.FileServiceImpl.open(FileServiceImpl.java:496)
at com.google.appengine.api.files.FileServiceImpl.openForRead(FileServiceImpl.java:456)
at com.google.appengine.api.files.FileServiceImpl.openForRead(FileServiceImpl.java:447)
at com.google.appengine.api.files.FileServiceImpl.openReadChannel(FileServiceImpl.java:202)
at com.myfileshost.MyfileshostServlet.doGet(MyfileshostServlet.java:362)
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:102)
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.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:249)
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:135)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:446)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:449)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:455)
at com.google.tracing.TraceContext.runInContext(TraceContext.java:695)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:333)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:325)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:453)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
at java.lang.Thread.run(Thread.java:679)
When a file is created via a GAE FileService it must be finalized before it can be read.
Javadoc of openReadChannel(..) clearly states that this method throws FinalizationException if file is not finalized.
Here is a full example on how to create file, finalize it and then read from it: https://developers.google.com/appengine/docs/java/blobstore/overview#Writing_Files_to_the_Blobstore

Resources