So I'm running my app now on localhost. And
you'll see, if you look in the APIs Explorer,
and drill down in to the functions in the
conference API, that the set announcement method is not here.
That's because we didn't expose it as an endpoints
function. Instead, we defined it as a servlet on
purpose, to keep it internal to the application. So
the APIs Explorer let's you explore endpoint functions, but it
doesn't let you explore your servlets. Since we're going to
put things into memcache, I've deployed my app to app
spot so I can use the memcache viewer. First, I'll
make sure I have some conferences that are nearly sold out.
Okay, this one's pretty close to being sold out. Only
three seats left. This one's only got one seat left. Okay,
so I've got a couple of conferences that only have
a couple of seats left. To test the new set announcement
function, you can use the browser to go to the
URL mapped to the servlet. However, you do have to be
logged in as a developer on the application or you'll
get an error that you're not in the required role. And
that's because we don't want just any old person coming
along, setting the announcements by going to the URL in the
browser. So to trigger the set announcement function, we go
to the URL that we mapped it to in the servlet,
in this case which is crons/set_announcment. So we
go to the URL. Crons_\set announcement. Nothing seems to
happen. But actually that's expected. Remember that the servlet
doesn't set a response so nothing happens in the
page, and if you've got to the place where it asks you to log in and you
go ahead and log in you're going to remain on
the log in page even when the URL executes.
However, we can use a memcache viewer to check
that the announcement got set. So here in the memcache
viewer we do see that we have one item. We
can use the content lookup section to look to see
if it is our announcement. The key we use
with recent announcements is a Java String, so let's display
it, see if we have an announcement. And yes, we
do. So the announcement about the conferences that have been
nearly sold out has been created and saved in memcache.
So now, we can save values in memcache and we
can use a memcache viewer to get those values back.
We're going to want to show this announcement to other people, not
to the developers of the application. Let's go ahead and
create an endpoint function to get the announcement out of Memcache
so we can show it to other people. So another
thing I want to mention is that in the constants class,
constants.java, we define the key for the
announcements, and this is where we get the
recent announcements key from. So in the conference
API class you can define the get announcement
function. This is going to be an end points function so this is a fairly simple
function. Basically get some memcache service, and then
calls the get method on the memcache service,
passing in the announcement key. We check if the value is null. So long as it's
not null, we create a new announcement object,
and we set the message property to the announcement
that we got out of memcache. And again,
we have to return an announcement, rather than
just a string, because this is an endpoint
function. And end point functions can't return just strings.