I am trying to use Google Objectify for Datastore (https://github.com/objectify/objectify). My app is not hosted on GAE, but I still make use of Datastore, so I need to use the remote API. Right now, I use the low level API and connect successfully like this :
DatastoreOptions options = DatastoreOptions.builder()
.projectId("PROJECT_NAME")
.authCredentials(AuthCredentials.createApplicationDefaults()).build();
Datastore client = options.service();
And the library used is http://googlecloudplatform.github.io/gcloud-java/0.2.0/index.html. My application defaults for "AuthCredentials.createApplicationDefaults()" is in my home folder in development as well as on the server.
In the doc I saw for Objectify, I did not see anyway of specifying the connection like above, thus no way of telling to use the credentials file in our home folder. The code I see for Objectify is mostly like this Objectify.ofy(). So I see no way with this method of telling to use the auth credentials defaults.
Thank you very much.
Use the Google App Engine remote api:
https://cloud.google.com/appengine/docs/java/tools/remoteapi
You could try gcloud-java datastore module.
http://googlecloudplatform.github.io/gcloud-java/0.2.0/index.html
But I encounter some performance issues on outside of Google Sandbox (GAE-Compute Engine)
Related
On an App Engine application, deployed on standard environment with java 8 activated, I get the exception below if I use both Objectify 6.0 AND the tag <url-stream-handler>urlfetch</url-stream-handler> in the appengine-web.xml file.
com.google.cloud.datastore.DatastoreException: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
Any idea how I can bypass that?
Things get back to normal if I remove the urlfetch tag (and activate the billing) or if I downgrade Objectify to v5.
I suspect what you're running into is one of the differences between the Java 7 and the Java 8 Standard Environments. There are substantial benefits to avoiding the urlfetch path, as Issuing HTTP(S) Requests notes (e.g. HTTP/2). In particular, the metadata server, which does automatic authentication for the Google Cloud SDKs when running on App Engine, isn't reachable using urlfetch (see that page).
I think your best option here is probably to enable billing, if you're comfortable with that. From the docs page:
Despite the requirement to enable your application for billing, your app won't incur any more cost than the same application running on Java 7.
If you'd still like to give urlfetch a try, I think the error you're encountering can be fixed by manually supplying credentials (e.g. bundling them in your app), but that won't be as secure or performant.
The best option is to use the
<appengine-web-app>
<url-stream-handler>native</url-stream-handler>
<appengine-web-app>
and enable billing. Without billing you can only use the legacy urlfetch and you have to face all these problems.
you can set credentials explicitly, like it is shown in the example below:
Resource credentialsCyberpower = resourceLoader.getResource("classpath:yourservice-datastore-access.json");
GoogleCredentials credentials = GoogleCredentials.fromStream(credentialsCyberpower.getInputStream())
.createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
DatastoreOptions options =
DatastoreOptions.newBuilder().setProjectId("XXXXXX").setCredentials(credentials).build();
Datastore datastore = options.getService();
ObjectifyService.init(new ObjectifyFactory(datastore));
generate yourservice-datastore-access.json in IAM service accounts. working with Objectify 6.0.5
I am new to Google App engine and I have tried to run an demo application called guestbook to connect to Google cloud sql from the Google app engine with app-engine-sdk version 1-7.0. But each time I am getting an error saying "java.lang.IllegalStateException: System property rdbms.driver must be set at com.google.appengine.api.rdbms.dev.LocalRdbmsServiceLocalDriver.registerDriver(LocalRdbmsServiceLocalDriver.java:80)". I double check my code and every thing looks ok, and I still have no glue where the error coming from.
Below is a snippet of my connection code :
c = DriverManager.getConnection("jdbc:google:rdbms://my_instance/my_database");
and mysql-connector-java-5.1.21-bin is in the class path,
and I have enable Google cloud sql in the Google app engine,
and I have checked the use of Google Cloud instance in the app engine as well with the my instance of the database, database name, login , and password,
and I am using Eclipse Juno.
I think I have missed something important; so would you please help me if you know what I have missed.
Thank you very much in advance,
Minh
Once you are new to GAE I recommend to give a try on the Big Table database. Using it you will not have to setup any database localy. So just the eclipse plugin will be enough for your first test. The Guestbook uses this database so it will be easier to follow the tutorial.
If I want to deploy anything on Google Apps, I'll have to create an application in Google App Engine, is that right? Is there a way to use FTP like in other web hosting services?
If I have myapp in GAE, and I already let myownsite.com to use this app. But I don't want anyone else to use this app on myapp.appspot.com, how can I do it?
Thanks in advance!
Perhaps not the best solution, but you can use self.request.headers["HOST"] in your handler to see which domain the request was requested to and redirect the user based on that.
You will need to upload your application. There is no FTP access for that as far as I know, but the GAE SDK contains a commandline tool to do that. You can also do it from IDE.
There is always an associated myapp.appspot.com domain with your application, so no one will take it. But you can also use your own domain (but not for SSL!). But you cannot also block access through myapp.appspot.com, but in Java you can create a filter that will redirect all requests to your custom domain. And keep in mind you cannot use naked domains (without www) in GAE.
I would like to write a client application for Android that uses the Google App Engine as a database backend. My Android client would connect to the App Engine to save information, then it would connect later for reports. Is it possible to use the App Engine as a backend like this?
If you're looking for something like the remote api that the App Engine has in python, then you'll be disappointed to find it missing in Java.
That said, absolutely nothing stops your from hitting your app and posting data either through POST / JSON / XML / any other format you can think of. The same thing goes for getting your reports back.
If security is a concern, the OAuth protocol allows you to authenticate to app engine from your android device.
This is an aside, but as far as reporting is concerned, you might not find the app engine a very suitable platform for reporting type apps. Just make sure you understand its limitations - the lack of joins, 1000 object limit, no sum / average, necessary indexes, etc. It's certainly not impossible, but do think carefully about how you're going to model your data.
Yes, it is possible.
Without more details in your question, any more details in the answer would be speculation.
Yes, its very much possible. It's something I am also currently working on.
My code uses HTTP GET and HTTP POST and I am using a RESTful service on the GAE.
I'm sorry I can't provide any code because I am still learning however the library I'm using is called RESTLET. They have libraries for both GAE and Android however I'm only using RESTLET on the GAE and I'm just using the HTTP library in the Android SDK for the client.
http://www.restlet.org/
The version you require is 2.0 M6 and not the stable release.
No.
In your response to Laurence, you said you want a direct DB connetion. A client cannot connect directly to the GAE datastore. You must write web handlers to interface between the client and your data. It doesn't have to be much, but it must be something.
Yes, it is very possible. You would not connect directly to the GAE database though. A better architecture would be to make your app hit a URL that writes to the DB. For example, you could set up a Struts 2 action that takes the values of your query parameters and then mutates and validates them as necessary before persisting them.
How do I setup Account Registration, Login, etc in Grails when developing for the Google App Engine? Normally I would use the Acegi plugin but I've read that it doesn't work with Google App Engine.
For reference, I'm using the Grails app-engine and gorm-jpa plugins.
Google App Engine allows you to manage users through their Google Accounts Java API. The page provides example codes which you can easily implement with Groovy.
Hope it helps.
You should take a look at this patch: http://jira.codehaus.org/browse/GRAILSPLUGINS-1233. I haven't used it yet but might be what you are after.
In my opinion, it is essential to create custom authentication instead of using Google Account API to create any viable application run on GAE.
So, I created my own solution to tackle this problem which you may interested to have a look at URL:
http://grailsfuse.vobject.com/
(You will hit http 500 error for first request, please wait for 30 seconds and refresh)
The missing part is the self-registration page and remember me feature. Please contact us (hyperlink located below the page of URL above) if you are still interested.
Wish to heard from you soon!