Class NotificationServlet (2.5.1)

public class NotificationServlet extends HttpServlet

Beta
Thread-safe Webhook Servlet to receive notifications.

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, so if you you may alternatively call that method instead from your HttpServlet#doPost 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 <} ervlet-name{@literal="">}
 {@literal <}servlet-class{@literal>}com.mypackage.MyNotificationServlet{@literal <} ervlet-class{@literal="">}
 {@literal <} ervlet{@literal="">}
 {@literal <}servlet-mapping{@literal>}
 {@literal <}servlet-name{@literal>}MyNotificationServlet{@literal <} ervlet-name{@literal="">}
 {@literal <}url-pattern{@literal>}/notifications{@literal <} rl-pattern{@literal="">}
 {@literal <} ervlet-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 <} ervlet-name{@literal="">}
 {@literal <}servlet-class{@literal>}com.google.api.client.googleapis.extensions.servlet.notificationsNotificationServlet{@literal <} ervlet-class{@literal="">}
 {@literal <} ervlet{@literal="">}
 {@literal <}servlet-mapping{@literal>}
 {@literal <}servlet-name{@literal>}NotificationServlet{@literal <} ervlet-name{@literal="">}
 {@literal <}url-pattern{@literal>}/notifications{@literal <} rl-pattern{@literal="">}
 {@literal <} ervlet-mapping{@literal="">}
 

Inheritance

java.lang.Object > javax.servlet.GenericServlet > HttpServlet > NotificationServlet

Constructors

NotificationServlet()

public 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.

NotificationServlet(DataStore<StoredChannel> channelDataStore)

protected NotificationServlet(DataStore<StoredChannel> channelDataStore)

Constructor that allows a specific notification data store to be specified.

Parameter
Name Description
channelDataStore com.google.api.client.util.store.DataStore<StoredChannel>

notification channel data store

NotificationServlet(DataStoreFactory dataStoreFactory)

protected NotificationServlet(DataStoreFactory dataStoreFactory)

Constructor which uses StoredChannel#getDefaultDataStore(DataStoreFactory) on the given data store factory, which is the normal use case.

Parameter
Name Description
dataStoreFactory com.google.api.client.util.store.DataStoreFactory

data store factory

Methods

doPost(HttpServletRequest req, HttpServletResponse resp)

protected void doPost(HttpServletRequest req, HttpServletResponse resp)
Parameters
Name Description
req HttpServletRequest
resp HttpServletResponse
Overrides
Exceptions
Type Description
ServletException
IOException