I am writing a Google App Engine (Java) application that reads data from a number of REST services, using OAuth for authentication. In order to support OAuth callbacks in my Development and Online environments, I have created 2 separate OAuth keys for the REST services - 1 that does a callback to 127.0.0.1 (development server) and 1 that does a callback to my real GAE website URL. This all works fine and happy.
Currently, to support this, I basically have a number of these statements throughout my code, anywhere that needs different values for Dev vs Online...
String devServer = request.getServerName();
if (devServer != null && devServer .equals("127.0.0.1")){
oauthKey = "<my_dev_key>";
}
else {
oauthKey = "<my_online_key>";
}
I was wondering whether GAE has any ability to auto-substitute different values for Development vs Online. I was thinking something like a 'settings' file that specifies 2 different values for a single setting, such that when the app is uploaded to GAE it replaces all setting references with the Online values. I would prefer that the values are substituted at upload-time rather than having a file sitting on the server with my Development settings in it, for security purposes.
Are there any alternatives that would be able to achieve a similar result without too much manual work every time I wish to upload a new version to GAE?
I would store the credential in different Properties files using something like Maven and its Profile feature to build an artifact for any specific environment.
Have a look to this project for the Google App Engine Maven plugin.
Related
I am working on a proof of concept for a spring-boot java web app hosted on a google cloud compute instance using the google cloud datastore.
Here is what I did:
Followed the steps on the getting started - sign up page
I did not create my instances via the command line, but created them in the console. I ensured that I added the proper scopes through the advanced settings.
Another difference is that i used an ubuntu image instead of the compute default
I have the demo java code from here: https://cloud.google.com/datastore/docs/getstarted/start_java/ plugged in to my #repository
the only difference is that I removed the command line code and hardcoded my dataset_id
I stood up the gcd local dev instance of the datastore set the appropriate environmental variables and was able to successfully execute the java code from within my web app.
I moved the jar out to my google cloud compute vm
I did not set any environmental variables as the documentation says that setting the proper scopes should enable the java libraries to pull the config from environment
I attempted to PUT to my resource (which uses the #reposoitory) (just like i did locally), I receive:
DatastoreException(Backend Error): beginTransaction 503
com.google.api.services.datastore.client.DatastoreException: Backend Error
at com.google.api.services.datastore.client.RemoteRpc.makeException(RemoteRpc.java:115)
at com.google.api.services.datastore.client.RemoteRpc.call(RemoteRpc.java:81)
at com.google.api.services.datastore.client.BaseDatastoreFactory$RemoteRpc.call(BaseDatastoreFactory.java:41)
at com.google.api.services.datastore.client.Datastore.beginTransaction(Datastore.java:77)
... more
I researched a few other issues like this on stack overflow, and the answers have been:
did you follow the steps in the getting started? (Yes, to the best of my knowledge, I have)
Contacted Google support and they fixed something (Not a good answer in my book. I want to role out services like this and having Google tweak something without letting me know how i can affect that same change from within the existing tooling is not an answer)
Thanks for the help
After sending my dataset id to Ed at Google Support, he noticed that there was a "zero width space" unicode character at the end of the dataset id.
I guess I was lazy when coding it up and copied it from the project's page of the Google Developer Console.
Re-keying the dataset-id/project-id did the trick.
Our new start-up company is trying to build a mobile app with an accompanied website. We are trying to setup our application on Amazon Web Services.
We have Java code running in an EC2 instance, which will store data in S3. We want clients (iOS and Web for now) to communicate with the Java Backend via a REST API. Ideally the website would be hosted under the same AWS account.
The Java Code and REST API are already set up in a very basic form, but the setup of the Website is unclear, since this is new to us all. We also would like to evaluate beforehand if such a setup is even feasible.
Since I am in charge of the Website i have already spend hours researching this specific setup, but i simply lack experience in cloud/backend development to come to a conclusion.
Here are some questions we would like to answer:
Where would the HTML files and accompanied JavaScript etc. files be stored?
How can data (images etc.) that is stored within S3 by the JAVA code be accessed from the Website directly?
How could something like bootstrapping of data within HTML files be achieved (in JSON format preferably)?
How could the server be set up to compress certain files like CSS or JavaScript?
Please point me into the right direction, any comment is appreciated.
Where would the HTML files and accompanied JavaScript etc. files be
stored?
Either on the same AWS EC2 box or a different one, just give it a static IP and link that IP to the domain you want, done. Just remember to have port 80 open as a firewall rule.
How can data (images etc.) that is stored within S3 by the JAVA code
be accessed from the Website directly?
The files will have some url that you can link to directly in your html so it's essentially just a url.
How could something like bootstrapping of data within HTML files be
achieved (in JSON format preferably)?
You have a number of choices here. You could potentially create some JSP files to generate the HTML and load the JSP files on access and cache them so they load up super fast. You could argue however, this is overkill and in some ways, the REST endpoint should be robust enough to handle the requests.
Part of me thinks you should endeavor to use the REST API for this information so you just have to manage one endpoint, why make an extra endpoint or over engineered solution for the HTML that you then have to maintain? Build once and reuse.
How could the server be set up to compress certain files like CSS or
JavaScript?
During the build process, run the files through a minify process. This is built into maven so you could do it automatically or by hand using something like jscompress. This Minify plugin shows how to automatically minify your resources. Consider you'll need to be using Maven though as your build tool.
in a student project we are currently developing a website which service is also accessibly via native Android and Windows Phone Apps.
The mobile apps access the service through a public RESTful API written in JAVA which is running on the same server as the website. The website is written in PHP and independent from the API, but they both use the same database (MySQL).
We wanted to extend the functionality of the API and allow registration for the service in the mobile apps.
The problem is that the user receives an email with a confirmation link as soon as he registers for the service.
What is the best approach to ensure that the emails sent by the API are identical to the ones sent by the website?
The easiest way we figured out doing this would be just using the same templates for both, website and API, but in that case we need to manually keep those templates in sync.
Is there a better way than the one above?
Templates need not be in flat file model in each environment. You can store it at one place but should be read by a common intra-web-api say local RPC.
I.e. Write a script in current website environment that returns either a template or duly filled in as the requirement case may be.
And the same API should be called from both web-site php scripts and from java API.
This process will not alter the output in both the environments. The output would always be the same when on a later date you change the template.
I have an app that currently uses the com.google.appendinge.api.appidentity.AppIdentityService to facilitate authentication & authorization for using the same app's [ie. same account] spreadsheet data via the SpreadsheetService API. Works great in production mode deployed to the GAE environment. But for obvious reasons, it doesn't work (authentication error, no surprise there) running in my development appengine environment.
My question is: is it possible & 'supported' to configure one's local development server to use the necessary key & certificate info to enable the AppIdentityService to work as intended?
I read the article https://sites.google.com/site/oauthgoog/authenticate-google-app-engine-app and I understand it to suggest that it is possible but I be mis-understanding key points & would appreciate any feedback pro & con regarding this.
In a perfect world, I'd like my testing env to mimic the production mode as closely as possible. I am also considering using the 'normal' oauth2 web app authentication in my testing env but would prefer sticking with using AppIdentityService if at all possible.
I suspect the com.google.appengine.api.appidentity.dev.LocalAppIdentityService class in the appengine-api-stubs.jar is the intended technique but has anyone else also used this to provide AppIdentityService authentication within a development server? My initial assumption is that replacing the class com.google.appengine.api.appidentity.IAppIdentityServiceFactoryProvider found in com.google.appengine.spi.FactoryProvider to use my own factory class using the above LocalAppIdentityService class. Or am I barking up the wrong tree?
Using GAE SDK 1.8.8 for Java.
When running under the local dev server, the GAE Java App Identity API calls the GoogleCredentials library to retrieve the default application credential.
The environment variable GOOGLE_APPLICATION_CREDENTIALS is checked. If this variable is specified it should point to a file that
defines the credentials. The simplest way to get a credential for this
purpose is to create a service account using the Google Developers
Console in the section APIs
& Auth, in the sub-section Credentials. Create a service account
or choose an existing one and select Generate new JSON key. Set
the environment variable to the path of the JSON file downloaded.
If you have installed the Google Cloud SDK on your machine and have run the command gcloud auth login, your identity can be used as
a proxy to test code calling APIs from that machine.
If you are running in Google App Engine production, the built-in service account associated with the application will be used.
If you are running in Google Compute Engine production, the built-in service account associated with the virtual machine instance
will be used.
If none of these conditions is true, an error will occur.
It looks like option #2 is probably easiest for you (run gcloud auth login to have your code use your Google account for authentication when run locally), but you could also do #1.
I have been working with GAE's PHP dev server and had the same issue with the AppIdentity service not working correctly. In PHP you can get around this by setting the $_SERVER['APPLICATION_ID'] to dev~yourapplicationid. I am sure there must be a way to do the same in Java, you just need to prepend dev~ to the start of your application ID to work with the dev environment.
I'm working on a web-app using Google App Engine with GWT, and I need to use Google API's (Google Calendar, Documents and so...).
As I know, I must configure a domain with Google to set my domain as callback of an OAuth Authentication. Am I right?
If so, am I forced to deploy on GAE to test? I mean, I can't run locally because my localhost can't be a valid callback.
Do you know any way to debug locally even using Google API's?
I have recommended to config a DynDNS, but isn't a solution in short term (incompatible router)...
If you use AuthSub instead I don't think you need to register a domain. The user just need a google account.
I have in the past used AuthSub together with Google Docs/Spreadsheet APIs on GAE and also been able to test it locally.
I can unfortunately not give you my code and exact solution (it was a while ago). But one of the samples I used extensively to base my code on was the FetcherServlet, check this code out:
http://code.google.com/p/google-app-engine-samples/source/browse/trunk/retrieving-gdata-feeds-java/src/com/google/appengine/demo/web/FetcherServlet.java?r=122
Also, I guess you might already have read this page (but their FetcherServlet uses OAuth, not AuthSub), so maybe just use it for some background info:
http://code.google.com/appengine/articles/java/retrieving_gdata_feeds.html