Twitter, Soundcloud, Salesforce, Pinterest, FitBit, Tumblr, Box, Foursquare... What do they all have in common? They all run finagle in production. For java, it is about as battletested and as good as you'll get unless you want to write your own. Personally, I'm more of a golang and python developer, but respect where it is due. Twitter is massively more scalable than the overwhelmingly majority of the sites on the internet and they've gotten their act together since abandoning Ruby and the fail whale.
Pick two.
> There is no way to configure timeouts
They're configured by properties if I recall.
> Filters have to be added to each handler separately, by mucking with its filter list
I personally prefer the explicitness of this.
As for the rest... I think a lot of these issues stem from the fact it's an old, not particularly well-known API in the JDK.
* serving of files and directories
* LetsEncrypt certificates and SSL
package main
import (
"fmt"
"net/http"
"path/filepath"
)
var (
host = "0.0.0.0"
path = "/var/www/public"
port = 8080
)
func main() {
path, err := filepath.Abs(path)
if err != nil {
panic(err)
}
listenAt := fmt.Sprintf("%s:%v", host, port)
fmt.Println("static-serve-dir serving", path, "over http at", listenAt)
err = http.ListenAndServe(listenAt, http.FileServer(http.Dir(path)))
if err != nil {
panic(err)
}
}
https://gist.github.com/tomwhoiscontrary/b4888b86057c74a636c...
The main takeaway is that the JDK's built-in web server is poor:
* There is no way to configure timeouts
* Filters have to be added to each handler separately, by mucking with its filter list
* Filters have to extend an abstract class with two methods (one totally pointless), so you can't use lambdas for them
* Handlers use a simple string prefix match, so a request for "/healthzone" will hit the health handler
* The stop method always blocks for the specified timeout, and never returns early as the docs promise (IME)
Other minor irritations:
* There is no method to parse an InetSocketAddress from a string
* Java's support for handling clean process shutdown is not great; i think there's some sort of race between the shutdown hook and the logging system getting shut down, so you never see the "Server stopped" message