English subtitles

← Explore Project Layout and Configuration - Developing Scalable Apps with Java

Get Embed Code
4 Languages

Showing Revision 5 created 05/25/2016 by Udacity Robot.

  1. Now the Hello World project here that you've got, it's
  2. a very simple, application that uses end points. What I want
  3. to do now is just talk you quickly through the code
  4. so that you understand how to define endpoints, so you see
  5. how to call them from a web page. So let's
  6. take a look at the files in the Hello World end
  7. points application. So here, you see here in src > main
  8. > java. In the com > google > training > helloworld
  9. package, you see the Java files.
  10. There are three Java files, Constants.java, HelloClass.java
  11. and HelloWorldEndpoints.java. So Constants.java defines some constants,
  12. as you might expect. HelloClass.java is a
  13. very simple class we'll look at
  14. in a minute. And then HelloWorldEndpoints.java defines
  15. the endpoints used in the application. So
  16. the source dir, contains the main folder,
  17. which contains the java and the webapp folders.
  18. We just looked at java, but now we're
  19. going to look at webapp. So the webapp
  20. folder contains the static files, the index.html, other
  21. HTML files if you have them, JavaScript files,
  22. any static content. It also contains the WEB-I-N-F,
  23. or WEB-INF folder. And this folder's common to
  24. all web applications, and it's where you configure
  25. your application. So for app engine apps, you have
  26. to have the appengine-web.xml file, which we already looked at,
  27. which is where you configure the things that are specific
  28. to your app engine app in, particular, you have to
  29. specify the app ID if you want to deploy it
  30. to Appspot. Another file in here is web.xml. And let's
  31. take a quick look at that. So web.xml is where
  32. you'd configure servers if you have them. In your web.xml
  33. you should see that you have
  34. the SystemsServiceServlet. And
  35. it's mapped to com.google.api.server.spi.SystemServiceServlet.
  36. And this spi, means end points. So this servlet is crucial to your application,
  37. if you want to use end points.
  38. Basically you must have com.google.api.server.spi.SystemServiceServlet in your
  39. app if you want to use endpoints. Also see we define the welcome file
  40. here which is index.html, which is pretty much
  41. the default. Another configuration I want to draw your
  42. attention to, is this one here for the
  43. security constraint, where we specified that all web pages
  44. must use HTTPS and this is how we
  45. specify it, by setting the transport guarantee confidential. So
  46. whenever you see this in your web.xml, it just
  47. means that when the app's running on app spot,
  48. if the user goes to it without using
  49. HTTPS, they'll be redirected to HTTPS. Okay, so back
  50. in the webapp dir, you see there's also
  51. hello.js. And there's index.html. And these are the two
  52. files that this app uses in the web
  53. UI, or in the web front-end. Hello.js contains the
  54. JavaScript functions used by the app, and index.html
  55. is the home page for the app, and it
  56. shows the two buttons, and the input field. And
  57. here you see the two buttons, and the input failed.