@Beta public class NotificationServlet extends javax.servlet.http.HttpServlet
Beta
In order to use this servlet you should create a class inheriting from NotificationServlet
and register the servlet in your web.xml.
It is a simple wrapper around WebhookUtils.processWebhookNotification(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, com.google.api.client.util.store.DataStoreFactory)
, so if you you
may alternatively call that method instead from your HttpServlet.doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
with no loss of
functionality. Example usage:
public class MyNotificationServlet extends NotificationServlet {
private static final long serialVersionUID = 1L;
public MyNotificationServlet() throws IOException {
super(new SomeDataStoreFactory());
}
}
Sample web.xml setup:
{@literal <}servlet{@literal >}
{@literal <}servlet-name{@literal >}MyNotificationServlet{@literal <}/servlet-name{@literal >}
{@literal <}servlet-class{@literal >}com.mypackage.MyNotificationServlet{@literal <}/servlet-class{@literal >}
{@literal <}/servlet{@literal >}
{@literal <}servlet-mapping{@literal >}
{@literal <}servlet-name{@literal >}MyNotificationServlet{@literal <}/servlet-name{@literal >}
{@literal <}url-pattern{@literal >}/notifications{@literal <}/url-pattern{@literal >}
{@literal <}/servlet-mapping{@literal >}
WARNING: by default it uses MemoryDataStoreFactory.getDefaultInstance()
which means it
will NOT persist the notification channels when the servlet process dies, so it is a BAD CHOICE
for a production application. But it is a convenient choice when testing locally, in which case
you don't need to override it, and can simply reference it directly in your web.xml file. For
example:
{@literal <}servlet{@literal >}
{@literal <}servlet-name{@literal >}NotificationServlet{@literal <}/servlet-name{@literal >}
{@literal <}servlet-class{@literal >}com.google.api.client.googleapis.extensions.servlet.notificationsNotificationServlet{@literal <}/servlet-class{@literal >}
{@literal <}/servlet{@literal >}
{@literal <}servlet-mapping{@literal >}
{@literal <}servlet-name{@literal >}NotificationServlet{@literal <}/servlet-name{@literal >}
{@literal <}url-pattern{@literal >}/notifications{@literal <}/url-pattern{@literal >}
{@literal <}/servlet-mapping{@literal >}
Modifier | Constructor and Description |
---|---|
|
NotificationServlet()
Constructor to be used for testing and demo purposes that uses
MemoryDataStoreFactory.getDefaultInstance() which means it will NOT persist the notification
channels when the servlet process dies, so it is a bad choice for a production application. |
protected |
NotificationServlet(DataStore<StoredChannel> channelDataStore)
Constructor that allows a specific notification data store to be specified.
|
protected |
NotificationServlet(DataStoreFactory dataStoreFactory)
Constructor which uses
StoredChannel.getDefaultDataStore(DataStoreFactory) on the given
data store factory, which is the normal use case. |
Modifier and Type | Method and Description |
---|---|
protected void |
doPost(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp) |
doDelete, doGet, doHead, doOptions, doPut, doTrace, getLastModified, service, service
public NotificationServlet() throws IOException
MemoryDataStoreFactory.getDefaultInstance()
which means it will NOT persist the notification
channels when the servlet process dies, so it is a bad choice for a production application.IOException
protected NotificationServlet(DataStoreFactory dataStoreFactory) throws IOException
StoredChannel.getDefaultDataStore(DataStoreFactory)
on the given
data store factory, which is the normal use case.dataStoreFactory
- data store factoryIOException
protected NotificationServlet(DataStore<StoredChannel> channelDataStore)
channelDataStore
- notification channel data storeprotected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
doPost
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
IOException
Copyright © 2010–2022 Google. All rights reserved.