Java libraries for parsing notifications using Spring Boot REST Controller as the WebHook Endpoint

Are there any Java libraries available for parsing the notifications to events I have subscribed to in my WebHook EndPoint

I am going to use a Spring boot RestController for the WebHook endpoint, has anybody used this for creating an endpoint?

Hey @davielang,

Thanks for joining our developer community!

While I’ll let our community check out your post as well, I did want to share some 3rd party resources (not Zoom Supported) that you might find helpful—For example:

Thanks,
Will

I’ve just started myself.

I haven’t come across any Spring Boot specific resources.

One gotcha that I’ve come across and started to implement is that all webhooks are sent to a single endpoint. Here are some notes that hopefully help you out (not sure how this will come through in the forum post:

  1. You will have a single controller method accepting ALL zoom webhooks as a single @RequestBody. This makes the Controller layer pretty basic, but poses challenges for Jackson deserialization as the incoming JSON payloads are different for each event type. There are probably more elegant ways to solve this, I’m still early in my development and am just posting what I have so far.
@PostMapping
@ResponseBody
public String handleWebhook(@RequestBody WebHookEvent event) {
    switch(event.getEvent()) {
        case WebHookEvent.WEBINAR_CREATED:
            webinarWebhookService.onCreated((WebinarCreated) event.getPayload());
            break;
        case WebHookEvent.WEBINAR_UPDATED:
            webinarWebhookService.onUpdated((WebinarUpdated) event.getPayload());
            break;
        case WebHookEvent.WEBINAR_DELETED:
            webinarWebhookService.onDeleted((WebinarDeleted) event.getPayload());
            break;
        case WebHookEvent.WEBINAR_ENDED:
            webinarWebhookService.onEnded((WebinarEnded) event.getPayload());
            break;
        default:
            log.warn("Unhandled event type: {}", event.getEvent());
            return "unhandled";
    }
    return "success";
}
  1. The POJO that comes in as an argument to the Controller, I have it with 2 properties.
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class WebHookEvent {
    public static final String WEBINAR_CREATED = "webinar.created";
    public static final String WEBINAR_UPDATED = "webinar.updated";
    public static final String WEBINAR_DELETED = "webinar.deleted";

    public static final String WEBINAR_ENDED = "webinar.ended";

    private String event;

    @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, 
                              property = "event", 
                              include = JsonTypeInfo.As.EXTERNAL_PROPERTY)
    @JsonSubTypes(value = {
            @JsonSubTypes.Type(value= WebinarCreated.class, name=WEBINAR_CREATED),
            @JsonSubTypes.Type(value= WebinarUpdated.class, name=WEBINAR_UPDATED),
            @JsonSubTypes.Type(value= WebinarDeleted.class, name=WEBINAR_DELETED),
            @JsonSubTypes.Type(value= WebinarEnded.class, name=WEBINAR_ENDED)
    })
    private WebhookPayload payload;
}

The payload attribute is heavily annotated. You can adjust this for the event types you are expecting your code to handle.

In my WebinarCreated/Updated/Deleted/Ended classes (or any that you want), those all implement the empty interface WebhookPayload.

public interface WebhookPayload {

}

Many thanks for sharing with the community, @adam-sercante :100:

1 Like

That’s really useful Adam. It’s along the lines of what I thought it might be. I will give it a go. Thanks for that, it gives me a good start.

1 Like

Glad they could help you, @davielang! :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.