RFR: bot: modularize HTTP server [v2]

Erik Joelsson erikj at openjdk.java.net
Wed May 12 12:53:42 UTC 2021


On Wed, 12 May 2021 12:51:06 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
>
> Erik Helin has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Update bot/src/main/java/org/openjdk/skara/bot/WebhookHandler.java
>    
>    Co-authored-by: Erik Joelsson <37597443+erikj79 at users.noreply.github.com>
>  - Update bot/src/main/java/org/openjdk/skara/bot/BotRunner.java
>    
>    Co-authored-by: Erik Joelsson <37597443+erikj79 at users.noreply.github.com>

Marked as reviewed by erikj (Reviewer).

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

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


More information about the skara-dev mailing list