English subtitles

← Testing Announcements - Developing Scalable Apps with Java

Get Embed Code
4 Languages

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

  1. So I'm running my app now on localhost. And
  2. you'll see, if you look in the APIs Explorer,
  3. and drill down in to the functions in the
  4. conference API, that the set announcement method is not here.
  5. That's because we didn't expose it as an endpoints
  6. function. Instead, we defined it as a servlet on
  7. purpose, to keep it internal to the application. So
  8. the APIs Explorer let's you explore endpoint functions, but it
  9. doesn't let you explore your servlets. Since we're going to
  10. put things into memcache, I've deployed my app to app
  11. spot so I can use the memcache viewer. First, I'll
  12. make sure I have some conferences that are nearly sold out.
  13. Okay, this one's pretty close to being sold out. Only
  14. three seats left. This one's only got one seat left. Okay,
  15. so I've got a couple of conferences that only have
  16. a couple of seats left. To test the new set announcement
  17. function, you can use the browser to go to the
  18. URL mapped to the servlet. However, you do have to be
  19. logged in as a developer on the application or you'll
  20. get an error that you're not in the required role. And
  21. that's because we don't want just any old person coming
  22. along, setting the announcements by going to the URL in the
  23. browser. So to trigger the set announcement function, we go
  24. to the URL that we mapped it to in the servlet,
  25. in this case which is crons/set_announcment. So we
  26. go to the URL. Crons_\set announcement. Nothing seems to
  27. happen. But actually that's expected. Remember that the servlet
  28. doesn't set a response so nothing happens in the
  29. page, and if you've got to the place where it asks you to log in and you
  30. go ahead and log in you're going to remain on
  31. the log in page even when the URL executes.
  32. However, we can use a memcache viewer to check
  33. that the announcement got set. So here in the memcache
  34. viewer we do see that we have one item. We
  35. can use the content lookup section to look to see
  36. if it is our announcement. The key we use
  37. with recent announcements is a Java String, so let's display
  38. it, see if we have an announcement. And yes, we
  39. do. So the announcement about the conferences that have been
  40. nearly sold out has been created and saved in memcache.
  41. So now, we can save values in memcache and we
  42. can use a memcache viewer to get those values back.
  43. We're going to want to show this announcement to other people, not
  44. to the developers of the application. Let's go ahead and
  45. create an endpoint function to get the announcement out of Memcache
  46. so we can show it to other people. So another
  47. thing I want to mention is that in the constants class,
  48. constants.java, we define the key for the
  49. announcements, and this is where we get the
  50. recent announcements key from. So in the conference
  51. API class you can define the get announcement
  52. function. This is going to be an end points function so this is a fairly simple
  53. function. Basically get some memcache service, and then
  54. calls the get method on the memcache service,
  55. passing in the announcement key. We check if the value is null. So long as it's
  56. not null, we create a new announcement object,
  57. and we set the message property to the announcement
  58. that we got out of memcache. And again,
  59. we have to return an announcement, rather than
  60. just a string, because this is an endpoint
  61. function. And end point functions can't return just strings.