MCS 270 Spring 2014 ObjectOriented Software Development MCS
MCS 270 Spring 2014 Object-Oriented Software Development
MCS 270 Object-Oriented Software Development Today’s schedule GAE – Google App Engine Modules User Service Blob Service GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Overview Google App Engine is: - runtime platform that provides web application hosting, data storage, and high-speed networking - infrastructure (servers + storage ) at Google GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Overview GAE Advantages: Does one thing well: running web apps App Engine handles HTTP(S) requests, nothing else Simple (relatively) app configuration Automatic Scaling to Application Needs Secure Easy on budget: Pay only for what you use (small apps are free) GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development GAE Runtime Environment Java: Java 7 Virtual Machine (JVM) Java Servlet interface for client-server Python: Python 2. 7 Go Java or Python? Python: powerful python syntax, library, shorter code Java: can use Java Data Objects (JDO) and Java Persistance API (JPA) GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development GAE Sandbox Applications run in a secure environment - limited access to underlying OS Plus - App will NEVER affect other applications on the same server Minuses - Cannot spawn additional processes or threads Cannot make arbitrary network connections Only read its own code and resource files and cannot create or modify files GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development GAE Sandbox Restrictions - App can only access other computers on the Internet through URL fetch and email services. - App interaction to server only by HTTP (or HTTPS) requests on the standard ports - Applications cannot write to the file system GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development GAE Services URLFetch – fetch web resources/services (servlets) Images – manipulate images: resize, rotate, flip, crop User Services: Google Accounts Mail XMPP – instant messages Task Queue – message queue; allow integration with non-GAPPs Datastore – managing data objects Blobstore – large files, much larger than objects in datastore GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development GAE User Services Google App Engine service based on Google infrastructure Accessible by applications using libraries included with GAE SDK. Provides integration with Google user accounts. Users use existing Google accounts to sign in to Application GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development GAE User Services Demo GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow – Gus. List. java public void on. Module. Load() { gl. View. set. Controller(Gus. List. this); home. URL = Window. Location. get. Href(); client. Model. Service. set. App. Base. URL(home. URL, new Async. Callback<String>() { public void on. Failure(Throwable caught) {return; } public void on. Success(String result) {}}); client. Model. Service. is. User. Logged. In( new Async. Callback<Boolean>() { public void on. Failure(Throwable caught) {return; } public void on. Success(Boolean result) { if(result) gl. View. view. Welcome. Page(); else gl. View. set. Window(". . /Gus. List. Welcome. html"); }}); } GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow – Gus. List. View. java public void set. Window(String url) { Window. Location. replace(url); } GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow – Gus. List. Welcome. html <p style="text-align: center; "> Welcome to Gus. List - the Gustavus on-line classified ad system. To start checking out the latest ads from the coolest students, please <a href="guslist/loginservice">login</a>. If you are new to the system, you will need to <a href="https: //accounts. google. com/Sign. Up">create a Google account</a> to login. </p> GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow – web. xml <servlet> <servlet-name>Login. Service</servlet-name> <servletclass>edu. gac. mcs 270. hvidsten. guslistgae. server. Login. Service</servletclass> </servlet> <servlet-mapping> <servlet-name>Login. Service</servlet-name> <url-pattern>/guslist/loginservice</url-pattern> </servlet-mapping> GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow - Login. Service public class Login. Service extends Http. Servlet { public void do. Get(Http. Servlet. Request req, Http. Servlet. Response resp) throws IOException { User. Service user. Service = User. Service. Factory. get. User. Service(); User user = user. Service. get. Current. User(); if (user != null) { resp. set. Status(Http. Servlet. Response. SC_SEE_OTHER); resp. set. Header("Location", ". . /Gus. List. html”); } else { String log. In. Link = user. Service. create. Login. URL(". . /Gus. List. html”); resp. set. Status(Http. Servlet. Response. SC_SEE_OTHER); resp. set. Header("Location", log. In. Link); }}} GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Login by GAE Note: Login and logout pages are handle by GAE automatically, but the workflow is different : Run on local – It will simulate Google Accounts sign-in page (no password authentication). Run on GAE – It will redirect to actual Google Account login screen. GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow – After Login returns to Gus. List. html <body> Basically Empty – filled in by Gus. List. View </body> GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development RPC vs HTTP Servlets HTTP – Simplest way to retrieve data from server. Data can be anything (text, HTML, XML, binary data, etc). Programmer must make sense of data. RPC – Easiest way to tranfer Java objects from server<>client. Data can only contain Serializable objects. Programmer knows exactly what form data is in. GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development RPC “A remote procedure call (RPC) is an inter-process communication that allows a program to cause a procedure to execute in another address space (commonly on another computer on a shared network) without the programmer explicitly coding the details for this remote interaction. When the software in question uses object-oriented principles, RPC is called remote invocation or remote method invocation. ” (Wikipedia) GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development HTTP Request / Response Cycle Web Server HTTP Request HTTP Response Browser IE, Fire. Fox, Chrome, Safari http: //www. oreilly. com/openbook/cgi/ch 04_02. html GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development HTTP Request / Response Cycle Web Server GET /index. html HTTP Request <head>. . </head> <body> HTTP <h 1>Welcome to my Response application</h 1>. . </body> Browser IE, Fire. Fox, Chrome, Safari http: //www. oreilly. com/openbook/cgi/ch 04_02. html GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development RPC vs HTTP Servlets Login. Service - Transfers actual URL’s, comes from GET request. Must be HTTP servlet. GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow - Login. Service public class Login. Service extends Http. Servlet { public void do. Get(Http. Servlet. Request req, Http. Servlet. Response resp) throws IOException { User. Service user. Service = User. Service. Factory. get. User. Service(); User user = user. Service. get. Current. User(); if (user != null) { resp. set. Status(Http. Servlet. Response. SC_SEE_OTHER); resp. set. Header("Location", ". . /Gus. List. html”); } else { String log. In. Link = user. Service. create. Login. URL(". . /Gus. List. html”); resp. set. Status(Http. Servlet. Response. SC_SEE_OTHER); resp. set. Header("Location", log. In. Link); }}} GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development GAE Blob Service Blobstore API - mechanism to store “blobs” of information Blob can be up to 50 MB in size (typically large files –video, images) Datastore vs Blob Service Datastore – data size limited to 1 mb, Access only through a GAE app. Blob Service – Size up to 50 mb. Cheaper than Datastore. Data can be served directly as url access. Designed for images – can do image transformations in place. GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development GAE Blob Service Demo GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow - Gus. List. View Form. Panel submit. Form. Panel // The submit. Form. Panel, when submitted, will trigger an HTTP call to the // servlet. The following parameters must be set submit. Form. Panel. set. Encoding(Form. Panel. ENCODING_MULTIPART); submit. Form. Panel. set. Method(Form. Panel. METHOD_POST); // Set Names for the text boxes so that they can be retrieved from the // HTTP call as parameters name. Textbox. set. Name("name"); title. Textbox. set. Name("title"); descr. Text. set. Name("description"); price. Textbox. set. Name("price"); upload. set. Name("upload"); GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow - Gus. List. View submit. Button. add. Click. Handler(new Click. Handler() { public void on. Click(Click. Event event) { control. handle. Post. From. Submit. Form(submit. Form. Panel); }}); GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow - Gus. List public void handle. Post. From. Submit. Form(final Form. Panel submit. Form. Panel) { blob. Service. get. Blob. Store. Upload. Url( new Async. Callback<String>() { public void on. Success(String result) { // Set the form action to the newly created blobstore upload URL submit. Form. Panel. set. Action(result. to. String()); // Submit the form to complete the upload // This causes activation of an upload HTTP servlet submit. Form. Panel. submit(); } public void on. Failure(Throwable caught) { gl. View. send. Error. Message("Upload Failed"); }}); } GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow - Blob. Service public class Blob. Service. Impl extends Remote. Service. Servlet implements Blob. Service { //Start a GAE Blobstore. Service session Blobstore. Service blobstore. Service = Blobstore. Service. Factory. get. Blobstore. Service(); //Generate a Blobstore Upload URL public String get. Blob. Store. Upload. Url() { // Map the Blob. Service Upload. URL to the // HTTP servlet which will be called when // submitting the Form. Panel (see web. xml for servlet def) return blobstore. Service. create. Upload. Url("/guslist/uploadservice"); } GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow - Submit. Post. HTTPService public class Submit. Post. HTTPService. Impl extends Http. Servlet { //Start Blobstore. Service blobstore. Service = Blobstore. Service. Factory. get. Blobstore. Service(); //Override the do. Post method to store the Blob's meta-data @Override public void do. Post(Http. Servlet. Request req, Http. Servlet. Response res) throws Servlet. Exception, IOException { Map<String, Blob. Key> blobs = blobstore. Service. get. Uploaded. Blobs(req); Blob. Key blob. Key = blobs. get("upload"); GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
MCS 270 Object-Oriented Software Development Program Flow - Submit. Post. HTTPService //Get the parameters from the request to post the ad String name = req. get. Parameter("name"); String title = req. get. Parameter("title"); String descr = req. get. Parameter("description"); double price = Double. value. Of(req. get. Parameter("price")); //Map the Image. URL to the blobservice servlet, which will serve the image String url = "/guslist/blobservice? blob-key=" + blob. Key. get. Key. String(); Post. Data post = new Post. Data(title, descr, price, url, new Seller(name), null); Gus. List. Model. store. Post(post); }} GUSTAVUS ADOLPHUS COLLEGE gustavus. edu
- Slides: 32