Loading XML from a file on Google App Engine - google-app-engine

What I'm trying to do is simple. Load am XML file using ElementTree so I can traverse it.
Here's the code:
_uri = '/news.xml'
self.root = ElementTree.parse(_uri).getroot()
And, the error:
file not accessible: '/news.xml'
From what I can tell, the parser can't find the document. Is there something I need to configure so python can see my site's files?

This is probably similar to:
Read a file on App Engine with Python?
I.e. files that are marked as static are not accessible, but you can also serve it as an application resource file.

Related

How do I store the private key of my server in google app engine?

I'm using "github.com/dgrijalva/jwt-go" to create JSON web tokens.
When I hosted my server locally, I could use my private key as usual. But in GAE it won't work because I don't have access to the file system.
How would you guys do it? Store the key in datastore or any other ideas?
Thanks
Edit:
My app.yaml looks like this (below api_version and stuff):
handlers:
- url: /.*
script: _go_app
On AppEngine you don't have access to the file system of the host operating system, but you can access files of your web application (you have read-only permission, you can't change them and you can't create new files in the app's folder).
So the question is: do you want to change this private key from your application without redeploying your app? Or it is perfectly fine if it is deployed "statically" with your app's code?
If you don't need to change it (or only when you redeploy your app), easiest is to store it as a "static" file as part of your webapp. You may refer to files of your app using relative paths, where the current or working directory is your app's root. E.g. if your app contains a key folder in its root (where app.yaml resides), and there is a my_key.txt file inside the key folder, you can refer to it with the path: key/my_key.txt.
Actually it is quite common to "ship" static files with your app's code: just think of HTML templates which are read and processed by the Go code (e.g. package html/template) to produce HTML result; the content of the HTML template files are not served directly to clients.
If you need to change it from time to time without having to redeploy your app, then store it in the Datastore which your app can read and modify.
Note:
One important note: not every file is readable by code, this depends on the app configuration. Quoting from Configuring with app.yaml / Static file handlers:
Static files are files to be served directly to the user for a given URL, such as images, CSS stylesheets, or JavaScript source files. Static file handlers describe which files in the application directory are static files, and which URLs serve them.
For efficiency, App Engine stores and serves static files separately from application files. Static files are not available in the application's file system. If you have data files that need to be read by the application code, the data files must be application files, and must not be matched by a static file pattern.
Static file handlers can be defined in two ways: as a directory structure of static files that maps to a URL path, or as a pattern that maps URLs to specific files.
Read the link how to properly configure application and static files / directories.
The solution was to leave app.yaml as it were. Put app.yaml at root lvl in project. Then change all imports from starting at GOPATH to start at project root instead. The problem that made me choose to put app.yaml and main go file in a different folder under project root was because of double imports. Read this for a better understanding: Google Go AppEngine imports and conflicts when serving / testing
The solution made my project find the files I wanted.

GAE Yaml handler to use URLS

I have configured a bucket and to access the files uploaded here what should be the Yaml handler statement?
For example: http://commondatastorage.googleapis.com/yii2assets/e896c38e/css/bootstrap.css
When I browse this CSS file it prompts to download and looks it doesn’t understand the MIME type.
I can’t provide a static directory since it’s hosted on Google Storage and to access I need to use the URL mentioned above.
Please let me if you have any IDEAS.
What I need is a handle like:
url: bootstrap.css
script : URL FROM where TO SERVER
Like if I have to use a JQuery CDN URL.
You can upload static file with your code then config Yaml with static_files please see in doc.
If you want to upload file to Google Storage you can access by sending parameter from python to html file. It depend how you implement it Java, Python have a difference way to implement this.

XPages and Apache CXF: what's the best place for WSDL files?

I am currently testing Apache CXF (2.7.11). Purpose is to build a Web Service client. I am roughly following Martin Vereecken's blog post (http://www.bizzybee.be/2013/01/23/creating-a-java-webservice-client-in-domino-using-apache-cxf/#more-451). I have a WSDL file and I created sample code with the wsdl2java tool.
My first thought was to store the wsdl file in the NSF (e.g. WebContent\WEB-INF\resources\wsdl). However, the code generated does not seem to find the WSDL file. Code looks something like this (class name Session comes form the WSDL):
Session.java:
URL url = Session.class.getResource("WEB-INF/wsdl/twinfield/session.wsdl");
if (url == null) {
url = Session.class.getClassLoader().getResource("WEB-INF/wsdl/twinfield/session.wsdl");
}
I tried both WEB-INF and /WEB-INF but neither seem to work.
If I put the WSDL file on the web (e.g. domino/html/wsdl folder) the url above works, but the code breaks later (it seems that it uses java.io.File trying to load the WSDL).
Local reference (e.g. C:\temp\wsdl) could work but does not really sound like a robust option.
The final java code will be in WebContent\WEB-INF\src, not in Code\Java.
So, what is the "best practice" for storing and referencing WSDL files in Domino environment?
UPDATE
I went with #stwissel's proposal and noticed that the wsdl2java tool can actually create the whole jar for you. Just specify option -clientJar and the resulting JAR file will contain all class files + the wsdl file.
When you generate the Java classes from the WSDL, you should pack them into a JAR file. Put the WSDL into the Jar file, so it never gets lost. This blog article and the comments explain it.
A potential issue could be the access rights (Java execution permissions) when you keep that jar inside the NSF.
The blog entry contains the sample code, so check it out!

Location of GS File in Local/Dev AppEngine

I'm trying to trouble shoot some issues I'm having with an export task I have created. I'm attempting to export CSV data using Google Cloud Storage and I seem to be unable to export all my data. I'm assuming it has something to do with the (FAR TOO LOW) 30 second file limit when I attempt to restart the task.
I need to trouble shoot, but I can't seem to find where my local/development server writing the files out. I see numerous entries in the GsFileInfo table so I assume something is going on, but I can't seem to find the actual output file.
Can someone point me to the location of the Google Cloud Storage files in the local AppEngine development environment?
Thanks!
Looking at dev_appserver code, looks like you can specify a path or it will calculate a default based on the OS you are using.
blobstore_path = options.blobstore_path or os.path.join(storage_path,
'blobs')
Then it passed this path to blobstore_stub (GCS storage is backed by blobstore stub), which seems to shard files by their blobstore key.
def _FileForBlob(self, blob_key):
"""Calculate full filename to store blob contents in.
This method does not check to see if the file actually exists.
Args:
blob_key: Blob key of blob to calculate file for.
Returns:
Complete path for file used for storing blob.
"""
blob_key = self._BlobKey(blob_key)
return os.path.join(self._DirectoryForBlob(blob_key), str(blob_key)[1:])
For example, i'm using ubuntu and started with dev_appserver.py --storage_path=~/tmp, then i was able to find files under ~/tmp/blobs and datastore under ~/tmp/datastore.db. Alternatively, you can go to local admin_console, the blobstore viewer link will also display gcs files.
As tkaitchuck mentions above, you can use the included LocalRawGcsService to pull the data out of the local.db. This is the only way to get the file, as they are stored in the Local DB using the blobstore. Here's the original answer:
which are the files uri on GAE java emulating cloud storage with GCS client library?

Appengine: Best way to read a CSV file into app inventor

I have a csv file and I'd need to get it into a list object in app inventor.
I'm not sure if there is a better / simpler method, but I've looked at the following methods and I'm not really sure the best route.
Also I'm using python but I could switch to use java app engine.
Google Fusion Tables (gft)
Google Docs & TinyGSdb
App Engine & Python
Down in the comments there is an example on how to update the app.yaml to include some code to parse a csv file.
import csv
reader = csv.reader(open(‘efile_newestSFO_8354d71d-e3fb-4864-b9bf-5312a89e24d7_2010.csv’,”rU”), delimiter=’,')
for row in reader:
print row[0],row[1]
I'd rather not go out to the web every time the app loads to retrieve the list.
Thoughts?
You can write a handler to let you upload the cvs to BlobStore, then use BlobStore APIs from your app to read the file.
That approach is well-described here (in Java, but the same idea applies to Python).

Resources