@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.
public class MyNotificationServlet extends NotificationServlet { private static final long serialVersionUID = 1L; public MyNotificationServlet() throws IOException { super(new SomeDataStoreFactory()); } }Sample web.xml setup:
<servlet > <servlet-name >MyNotificationServlet </servlet-name > <servlet-class >com.mypackage.MyNotificationServlet </servlet-class > </servlet > <servlet-mapping > <servlet-name >MyNotificationServlet </servlet-name > <url-pattern >/notifications </url-pattern > </servlet-mapping >
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:
<servlet > <servlet-name >NotificationServlet </servlet-name > <servlet-class >com.google.api.client.googleapis.extensions.servlet.notificationsNotificationServlet </servlet-class > </servlet > <servlet-mapping > <servlet-name >NotificationServlet </servlet-name > <url-pattern >/notifications </url-pattern > </servlet-mapping >
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–2019 Google. All rights reserved.