com.ibm.ecm.sample.webhook

Class WebhookReceiver

  • java.lang.Object
    • com.ibm.ecm.sample.webhook.WebhookReceiver


  • @Path(value="/receiver/")
    public class WebhookReceiver
    extends java.lang.Object
    Main servlet, which handles the logic for the Content Event Webhook Receiver. Whenever the Webhook External Event Action makes a call to the Webhook Receiver on the /receiver path of this application, the methods of this class will process the call.

    This sample application only has one method, listener(String), to handle POST calls for this servlet. This class can be extended with more methods to handle other scenarios.

    Note that the sample application primarily attempts to demonstrate how to do certain actions. Some of the example logic is not necessarily realistic and might not be used in an actual Webhook Receiver application. In developing a real life Webhook Receiver application, feel free to remove logic that is not required.

    • Constructor Summary

      Constructors 
      Constructor and Description
      WebhookReceiver() 
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      javax.ws.rs.core.Response listener(java.lang.String eventJson)
      This is the entry point for the Webhook Receiver to receive events from Content Platform Engine.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WebhookReceiver

        public WebhookReceiver()
    • Method Detail

      • listener

        @POST
         @Consumes(value="application/json")
        public javax.ws.rs.core.Response listener(java.lang.String eventJson)
        This is the entry point for the Webhook Receiver to receive events from Content Platform Engine. Every time an event is received, the following events will occur.

        1. Parse the JSON payload from the Webhook External Event Action call
        2. Ping the Content Services GraphQL Server
        3. If the event is a CreationEvent:
          • Retrieve the Webhook Event Action and subscription created when the Receiver application started.
          • Check if the subscription that triggered the callout is associated with the first event action created by the Receiver application.
          • If the subscription that triggered the callout is the same as the first subscription created on startup, update the event action and subscription name and description. Also, change the subscription to be subscribed to UpdateEvent instead of CreationEvent.
        4. Retrieve the source document and its properties. (Note: Source object properties are in the JSON payload of the External Event Action call. The GraphQL API call to retrieve the document is merely an example. In a real life use case it might be better to parse the JSON payload for the properties instead of calling the GraphQL API unless you need to retrieve the content of the document).
        5. If this event was triggered by a CreationEvent, keep track of the object for later deletion when the Webhook Receiver sample application shuts down.
        6. Parse the JSON of the retrieved source object for specific custom properties (WebhookDollarAmount, WebhookPriority, and WebhookRiskFactor). These properties are defined on the class definition of the subscribed custom class WebhookClaim.
        7. Perform custom backend processing of the document and its custom properties. This section is left blank on purpose. In a real life application, the enterprise specific processing would go here. As this is only a sample application, it is left as an exercise for the user to provide the logic for processing the source object.
        8. If the WebhookRiskFactor value has not been set, update the source object to set the property to and arbitrary value (15). Make sure not to update the object if WebhookRiskFactor value has already been set, or we will get stuck in an infinite loop, as each update will trigger another event.

        Note that some of the logic below might not be realistic or desirable in a real Webhook Receiver application. Some of the logic is included only for demonstration purposes as an example and can be removed if it does not make sense for an actual use case.

        Parameters:
        eventJson - JSON payload from the Content Event Webhook External Event Action call
        Returns:
        An Ok response if everything goes well, or another response if something is wrong. If a GraphQL call returns an error code, that error code will be returned here as well.