RFR: bot: modularize HTTP server

Erik Joelsson erikj at openjdk.java.net
Wed May 12 12:34:57 UTC 2021


On Wed, 12 May 2021 07:25:08 GMT, Erik Helin <ehelin at openjdk.org> wrote:

> Hi all,
> 
> please review this patch that modularizes the bot HTTP server. The HTTP server featured by the bot runner is currently only used to process webhooks, but I have coming patches that extends it with other functionality. This refactoring make the bot runner start the actual server and then handlers can be configured in a configuration file. A minimal configuration file looks like:
> 
> 
> {
>     "scratch": {
>         "path": "/tmp/skara/scratch"
>     },
>     "storage": {
>         "path": "/tmp/skara/storage"
>     },
>     "runner": {
>         "interval": "PT10S",
>         "watchdog": "PT30M",
>         "concurrency": 2
>     },
>     "log": {
>         "console": {
>             "level": "FINER"
>         }
>     },
>     "http-server": {
>         "port": 8080,
>         "/api": {
>             "type": "webhook"
>         }
>    }
> }
> 
> 
> Using the above configuration stored in `config.json` the bot runner can then be started as:
> 
> 
> $ make bots
> $ ./bots/bin/bin/skara-bots $PWD/config.json
> 
> 
> The HTTP server can be then be queried using e.g. `curl`:
> 
> 
> $ curl --verbose --request POST --data '{"foo": "bar"}'  http://localhost:8080/api
> Note: Unnecessary use of -X or --request, POST is already inferred.
>   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
>                                  Dload  Upload   Total   Spent    Left  Speed
>   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 127.0.0.1:8080...
> * TCP_NODELAY set
> * Connected to localhost (127.0.0.1) port 8080 (#0)
>> POST /api HTTP/1.1
>> Host: localhost:8080
>> User-Agent: curl/7.68.0
>> Accept: */*
>> Content-Length: 14
>> Content-Type: application/x-www-form-urlencoded
>>
> } [14 bytes data]
> * upload completely sent off: 14 out of 14 bytes
> * Mark bundle as not supporting multiuse
> < HTTP/1.1 200 OK
> < Date: Wed, 12 May 2021 07:18:50 GMT
> < Content-length: 2
> <
> { [2 bytes data]
> 100    16  100     2  100    14     66    466 --:--:-- --:--:-- --:--:--   533
> * Connection #0 to host localhost left intact
> {}
> 
> 
> I also updated the webhook handler to return `404` if the supplied data cannot be parsed as valid JSON.
> 
> Testing:
> - [x] Tested manually on Linux x64
> 
> Thanks,
> Erik

bot/src/main/java/org/openjdk/skara/bot/BotRunner.java line 2:

> 1: /*
> 2:  * Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved.

Copyright should have a comma after each year.

bot/src/main/java/org/openjdk/skara/bot/WebhookHandler.java line 2:

> 1: /*
> 2:  * Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved.

Comma after each year

-------------

PR: https://git.openjdk.java.net/skara/pull/1149


More information about the skara-dev mailing list