Java Module
Java Module

Install

Add the dependency to the project configuration:

Maven

1
2
3
4
5
<dependency>
    <groupId>com.botbye</groupId>
    <artifactId>java-module</artifactId>
    <version>0.0.3</version>
</dependency>

or

Gradle

1
implementation("com.botbye:java-module:0.0.3")

Configuration

Create BotbyeConfig with your server-key (available inside your Project):

1
2
3
4
5
BotbyeConfig config = new BotbyeConfig.Builder()
        .serverKey("00000000-0000-0000-0000-000000000000") // Use your project server-key
        .build();

Botbye botbye = new Botbye(config);

Usage

Add validateRequestAsync or validateRequest to your handler

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ExecutionException, InterruptedException {
    ConnectionDetails connectionDetails = new ConnectionDetails(
            req.getServerPort(),
            req.getRemoteAddr(),
            req.getServerName(),
            req.getMethod(),
            req.getRequestURI()
    );

    Headers headers = extractHeaders(req);

    // Get token from header or any place you store it.
    // For example in "x-botbye-token" header
    String token = req.getHeader("x-botbye-token");

    BotbyeResponse asyncResponse = botbye.validateRequestAsync(token, connectionDetails, headers).get();

    // Or use Sync

    BotbyeResponse syncResponse = botbye.validateRequest(token, connectionDetails, headers);

    if (syncResponse.getResult().isAllowed() == false) {
        // your logic
        // for example
        // throw new RuntimeException(syncResponse.getError().getMessage());
    }
}

private Headers extractHeaders(HttpServletRequest request) {
    Map<String, List<String>> headers = new HashMap<>();
    Enumeration<String> headerNames = request.getHeaderNames();

    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();

        List<String> valuesList = Collections.list(request.getHeaders(headerName));

        headers.put(headerName, valuesList);
    }

    return new Headers(headers);
}

Settings

BotbyeConfig contains next configurable parameters:

Setting Description Required Default Value
botbyeEndpoint Host of the API Server no https://verify.botbye.com
serverKey Your BotBye server-key yes -
contentType Content type for API requests no application/json
readTimeout Read timeout for HTTP client no Duration.ofSeconds(2)
writeTimeout Write timeout for HTTP client no Duration.ofSeconds(2)
connectionTimeout Connection timeout for HTTP client no Duration.ofSeconds(2)
callTimeout Total call timeout no Duration.ofSeconds(5)
maxIdleConnections Max idle connections in the pool no 250
keepAliveDuration Keep-alive duration no Duration.ofSeconds(300)
maxRequestsPerHost Max requests per host no 1500
maxRequests Max requests total no 1500

Examples of BotBye API responses

Bot detected:

1
2
3
4
5
6
7
{
  "reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
  "result": {
    "isAllowed": false
  },
  "error": "Automation tool used"
}

Bot not detected:

1
2
3
4
5
6
7
{
  "reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
  "result": {
    "isAllowed": true
  },
  "error": null
}

Request banned by custom rule:

1
2
3
4
5
6
7
8
9
{
  "reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
  "result": {
    "isAllowed": false
  },
  "error": {
    "message": "Banned by rule: MY_CUSTOM_RULE"
  }
}

Invalid server-key:

1
2
3
4
5
6
7
{
  "reqId": "f77b2abd-c5d7-44f0-be4f-174b04876583",
  "result": null,
  "error": {
    "message": "[BotBye] Bad Request: Invalid Server Key"
  }
}