Releases: FlareBot/WebHookDistributor
Releases · FlareBot/WebHookDistributor
Authorization header is persistent (oops)
1.0.1.2
1.0.1.1
Safety measures
This release pushes some safety measures which can be used to better verify the sender of the WebHook. This introduces two new methods to Event, getAuthorization()
and getIP()
. getAuthorization()
is to get the Authorization header (null if it doesn't have one) and getIP()
is to return the IP which sent the request.
Usage:
public void onWebHookReceive(WebHookReceiveEvent e){
if (e.getAuthorization() != null && e.getAuthorization().equals("secretKey1337")) {
LoggerFactory.getLogger(Example.class).info(String.format("Received webhook from %s, data: %s",
e.getSender().toString(), e.getPayload().toString()));
} else
LoggerFactory.getLogger(Example.class)
.warn(String.format("Received webhook with invalid authorization from %s pretending to be %s",
e.getIP(), e.getSender().toString()));
}
Base release
Start of the WebHookDistributor system. Full implementation client and server side. Code below as an example of client side.
For server just build and use.
Example class:
import org.slf4j.LoggerFactory;
import stream.flarebot.webhook_distributor.WebHookDistributor;
import stream.flarebot.webhook_distributor.WebHookDistributorBuilder;
import stream.flarebot.webhook_distributor.WebHookListener;
import stream.flarebot.webhook_distributor.events.WebHookReceiveEvent;
public class Example {
public static void main(String[] args) {
// This will say that the server is located at "https://cool-webhooks.flarebot.stream", the service is called "example" and the port for this service is '8181'.
WebHookDistributor distributor = new WebHookDistributorBuilder("https://cool-webhooks.flarebot.stream", "example", 8181)
// This will add the listener which is defined below.
.addEventListener(new Listener())
// This is the starting retry time, when connection to the server fails it will use this value first and double each failed attempt.
.setStartingRetryTime(500)
// The amount of connection attempts to make to the server before giving up.
.setMaxConnectionAttempts(5)
.build();
// Start listening to WebHooks from the server.
distributor.start();
}
private static class Listener extends WebHookListener {
public void onWebHookReceive(WebHookReceiveEvent e){
LoggerFactory.getLogger(Example.class).info(String.format("Received webhook from %s, data: %s",
e.getSender().toString(), e.getPayload().toString()));
}
}
}