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