1 / 32

MCS 270 Spring 2014

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. MCS 270 Object-Oriented Software Development. Overview. Google App Engine is:

truman
Download Presentation

MCS 270 Spring 2014

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MCS 270 Spring 2014 Object-Oriented Software Development

  2. MCS 270 Object-Oriented Software Development Today’s schedule GAE – Google App Engine Modules User Service Blob Service

  3. 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

  4. 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)

  5. 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)

  6. MCS 270 Object-Oriented Software Development

  7. 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

  8. 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

  9. 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

  10. 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

  11. MCS 270 Object-Oriented Software Development GAE User Services Demo

  12. MCS 270 Object-Oriented Software Development Program Flow – GusList.java public void onModuleLoad() { glView.setController(GusList.this); homeURL = Window.Location.getHref(); clientModelService.setAppBaseURL(homeURL, new AsyncCallback<String>() { public void onFailure(Throwable caught) {return;} public void onSuccess(String result) {}}); clientModelService.isUserLoggedIn( new AsyncCallback<Boolean>() { public void onFailure(Throwable caught) {return;} public void onSuccess(Boolean result) { if(result) glView.viewWelcomePage(); else glView.setWindow("../GusListWelcome.html"); }});}

  13. MCS 270 Object-Oriented Software Development Program Flow – GusListView.java public void setWindow(String url) { Window.Location.replace(url); }

  14. MCS 270 Object-Oriented Software Development Program Flow – GusListWelcome.html <p style="text-align: center;"> Welcome to GusList - the Gustavus on-line classified ad system.&nbsp; To start checking out the latest ads from the coolest students, please <a href="guslist/loginservice">login</a>. &nbsp; If you are new to the system, you will need to <a href="https://accounts.google.com/SignUp">create a Google account</a> to login. </p>

  15. MCS 270 Object-Oriented Software Development Program Flow – web.xml <servlet> <servlet-name>LoginService</servlet-name> <servlet-class>edu.gac.mcs270.hvidsten.guslistgae.server.LoginService</servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginService</servlet-name> <url-pattern>/guslist/loginservice</url-pattern> </servlet-mapping>

  16. MCS 270 Object-Oriented Software Development Program Flow - LoginService public class LoginService extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); if (user != null) { resp.setStatus(HttpServletResponse.SC_SEE_OTHER); resp.setHeader("Location", "../GusList.html”); } else { String logInLink = userService.createLoginURL("../GusList.html”); resp.setStatus(HttpServletResponse.SC_SEE_OTHER); resp.setHeader("Location", logInLink); }}}

  17. 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.

  18. MCS 270 Object-Oriented Software Development Program Flow – After Login returns to GusList.html <body> Basically Empty – filled in by GusListView </body>

  19. 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.

  20. 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)

  21. MCS 270 Object-Oriented Software Development HTTP Request / Response Cycle Web Server HTTP Request HTTP Response Browser IE, FireFox, Chrome,Safari http://www.oreilly.com/openbook/cgi/ch04_02.html

  22. MCS 270 Object-Oriented Software Development HTTP Request / Response Cycle Web Server <head> .. </head> <body> <h1>Welcome to my application</h1> .... </body> HTTP Request HTTP Response GET /index.html Browser IE, FireFox, Chrome,Safari http://www.oreilly.com/openbook/cgi/ch04_02.html

  23. MCS 270 Object-Oriented Software Development RPC vs HTTP Servlets LoginService - Transfers actual URL’s, comes from GET request. Must be HTTP servlet.

  24. MCS 270 Object-Oriented Software Development Program Flow - LoginService public class LoginService extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); if (user != null) { resp.setStatus(HttpServletResponse.SC_SEE_OTHER); resp.setHeader("Location", "../GusList.html”); } else { String logInLink = userService.createLoginURL("../GusList.html”); resp.setStatus(HttpServletResponse.SC_SEE_OTHER); resp.setHeader("Location", logInLink); }}}

  25. MCS 270 Object-Oriented Software Development GAE Blob Service Blobstore API - mechanism to store “blobs” of information Blob can be up to 50MB in size (typically large files –video, images) Datastore vs Blob Service Datastore – data size limited to 1mb, Access only through a GAE app. Blob Service – Size up to 50mb. Cheaper than Datastore. Data can be served directly as url access. Designed for images – can do image transformations in place.  

  26. MCS 270 Object-Oriented Software Development GAE Blob Service Demo

  27. MCS 270 Object-Oriented Software Development Program Flow - GusListView FormPanel submitFormPanel // The submitFormPanel, when submitted, will trigger an HTTP call to the // servlet. The following parameters must be set submitFormPanel.setEncoding(FormPanel.ENCODING_MULTIPART); submitFormPanel.setMethod(FormPanel.METHOD_POST); // Set Names for the text boxes so that they can be retrieved from the // HTTP call as parameters nameTextbox.setName("name"); titleTextbox.setName("title"); descrText.setName("description"); priceTextbox.setName("price"); upload.setName("upload");

  28. MCS 270 Object-Oriented Software Development Program Flow - GusListView submitButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { control.handlePostFromSubmitForm(submitFormPanel); }});

  29. MCS 270 Object-Oriented Software Development Program Flow - GusList public void handlePostFromSubmitForm(final FormPanel submitFormPanel) { blobService.getBlobStoreUploadUrl( new AsyncCallback<String>() { public void onSuccess(String result) { // Set the form action to the newly created blobstore upload URL submitFormPanel.setAction(result.toString()); // Submit the form to complete the upload // This causes activation of an upload HTTP servlet submitFormPanel.submit(); } public void onFailure(Throwable caught) { glView.sendErrorMessage("Upload Failed"); }}); }

  30. MCS 270 Object-Oriented Software Development Program Flow - BlobService public class BlobServiceImpl extends RemoteServiceServlet implements BlobService { //Start a GAE BlobstoreService session BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); //Generate a Blobstore Upload URL public String getBlobStoreUploadUrl() { // Map the BlobService UploadURL to the // HTTP servlet which will be called when // submitting the FormPanel (see web.xml for servlet def) return blobstoreService.createUploadUrl("/guslist/uploadservice"); }

  31. MCS 270 Object-Oriented Software Development Program Flow - SubmitPostHTTPService public class SubmitPostHTTPServiceImpl extends HttpServlet { //Start Blobstore BlobstoreServiceblobstoreService = BlobstoreServiceFactory.getBlobstoreService(); //Override the doPost method to store the Blob's meta-data @Override public void doPost(HttpServletRequestreq, HttpServletResponse res) throws ServletException, IOException { Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req); BlobKeyblobKey = blobs.get("upload");

  32. MCS 270 Object-Oriented Software Development Program Flow - SubmitPostHTTPService //Get the parameters from the request to post the ad String name = req.getParameter("name"); String title = req.getParameter("title"); String descr = req.getParameter("description"); double price = Double.valueOf(req.getParameter("price")); //Map the ImageURL to the blobservice servlet, which will serve the image String url = "/guslist/blobservice?blob-key=" + blobKey.getKeyString(); PostData post = new PostData(title,descr,price, url, new Seller(name), null); GusListModel.storePost(post); }}

More Related