RFR: bot: modularize HTTP server [v2]

Erik Helin ehelin at openjdk.java.net
Wed May 12 12:53:41 UTC 2021


> 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>

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

Changes:
  - all: https://git.openjdk.java.net/skara/pull/1149/files
  - new: https://git.openjdk.java.net/skara/pull/1149/files/c7966cc8..e421184e

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=skara&pr=1149&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=skara&pr=1149&range=00-01

  Stats: 2 lines in 2 files changed: 0 ins; 0 del; 2 mod
  Patch: https://git.openjdk.java.net/skara/pull/1149.diff
  Fetch: git fetch https://git.openjdk.java.net/skara pull/1149/head:pull/1149

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


More information about the skara-dev mailing list