Presentation is loading. Please wait.

Presentation is loading. Please wait.

MCS 270 Spring 2014 Object-Oriented Software Development.

Similar presentations


Presentation on theme: "MCS 270 Spring 2014 Object-Oriented Software Development."— Presentation transcript:

1 MCS 270 Spring 2014 Object-Oriented Software Development

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

3 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Overview Google App Engine is: - runtime platform that provides web application hosting, data storage, and high-speed networking - infrastructure (servers + storage ) at Google MCS 270 Object-Oriented Software Development

4 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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) MCS 270 Object-Oriented Software Development

5 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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) MCS 270 Object-Oriented Software Development

6 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu MCS 270 Object-Oriented Software Development

7 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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 MCS 270 Object-Oriented Software Development

8 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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 MCS 270 Object-Oriented Software Development

9 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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 MCS 270 Object-Oriented Software Development

10 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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 MCS 270 Object-Oriented Software Development

11 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu GAE User Services Demo MCS 270 Object-Oriented Software Development

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

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

14 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Program Flow – GusListWelcome.html Welcome to GusList - the Gustavus on-line classified ad system. To start checking out the latest ads from the coolest students, please login. If you are new to the system, you will need to create a Google account to login. MCS 270 Object-Oriented Software Development

15 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Program Flow – web.xml LoginService edu.gac.mcs270.hvidsten.guslistgae.server.LoginService LoginService /guslist/loginservice MCS 270 Object-Oriented Software Development

16 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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); }}} MCS 270 Object-Oriented Software Development

17 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Login by GAE MCS 270 Object-Oriented Software Development 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 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Program Flow – After Login returns to GusList.html MCS 270 Object-Oriented Software Development Basically Empty – filled in by GusListView

19 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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. MCS 270 Object-Oriented Software Development

20 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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) MCS 270 Object-Oriented Software Development

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

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

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

24 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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); }}} MCS 270 Object-Oriented Software Development

25 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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. MCS 270 Object-Oriented Software Development

26 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu GAE Blob Service Demo MCS 270 Object-Oriented Software Development

27 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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"); MCS 270 Object-Oriented Software Development

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

29 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Program Flow - GusList public void handlePostFromSubmitForm(final FormPanel submitFormPanel) { blobService.getBlobStoreUploadUrl( new AsyncCallback () { 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"); }}); } MCS 270 Object-Oriented Software Development

30 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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"); } MCS 270 Object-Oriented Software Development

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

32 GUSTAVUS ADOLPHUS COLLEGEgustavus.edu 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); }} MCS 270 Object-Oriented Software Development


Download ppt "MCS 270 Spring 2014 Object-Oriented Software Development."

Similar presentations


Ads by Google