servers

servers

Run your application on top of your favorite server!

Change one line and switch between Netty, Jetty or Undertow!!

netty

Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients.

exports

  • Server

dependency

<dependency>
  <groupId>org.jooby</groupId>
  <artifactId>jooby-netty</artifactId>
  <version>1.3.0</version>
</dependency>

usage

In order to use a web server all you have to do is add the dependency to your build system.

http/2

HTTP/2 is fully supported:

| H2        | H2C           | PUSH  |
| --------- | ------------- | ----- |
| Yes       | Yes           | Yes   |

No extra configuration is necessary.

server.conf

These are the default properties for netty:

# netty defaults 
server.module = org.jooby.netty.Netty

server.http2.cleartext = true

netty {

  http {

    MaxInitialLineLength = 4k

    MaxHeaderSize = ${server.http.HeaderSize}

    MaxChunkSize = 16k

    MaxContentLength = ${server.http.MaxRequestSize}

    IdleTimeout = ${server.http.IdleTimeout}

  }

  threads {

    Min = ${server.threads.Min}

    Max = ${server.threads.Max}

    Name = netty task

    Boss = 1

    Worker = ${runtime.processors-x2}

  }

  options {

    SO_REUSEADDR = true

  }

  worker {

    options {

      SO_REUSEADDR = true

    }

  }

}

undertow

Undertow is a flexible performant web server written in java, providing both blocking and non-blocking API’s based on NIO.

exports

  • Server

dependency

<dependency>
  <groupId>org.jooby</groupId>
  <artifactId>jooby-undertow</artifactId>
  <version>1.3.0</version>
</dependency>

usage

In order to use a web server all you have to do is add the dependency to your build system.

http/2

HTTP/2 is fully supported:

| H2        | H2C           | PUSH  |
| --------- | ------------- | ----- |
| Yes       | Yes           | Yes   |

You need Java 8 Update 71 or higher (integration tests uses Java 8 Update 101).

See Java 8 releases for more details.

server.conf

These are the default properties for undertow:

# undertow defaults 
server.module = org.jooby.undertow.Undertow

server.http2.cleartext = true

undertow {

  bufferSize = ${server.http.ResponseBufferSize}

  workerThreads = ${server.threads.Max}

  # Waits a set length of time for the handler to shut down. It provides a way to prevent the server 
  # from accepting new requests, and wait for existing requests to complete 
  awaitShutdown = 1000

  server {

    ALLOW_EQUALS_IN_COOKIE_VALUE = true

    ALWAYS_SET_KEEP_ALIVE = true

    # The maximum size in bytes of a http request header. 
    MAX_HEADER_SIZE = ${server.http.HeaderSize}

    # The default maximum size of the HTTP entity body. 
    MAX_ENTITY_SIZE = ${server.http.MaxRequestSize}

    # The maximum number of parameters that will be parsed. This is used to protect against hash 
    # vulnerabilities. 
    # This applies to both query parameters, and to POST data, but is not cumulative 
    # (i.e. you can potentially have max parameters * 2 total parameters). 
    MAX_PARAMETERS = 1000

    # The maximum number of headers that will be parsed. This is used to protect against hash 
    # vulnerabilities. 
    MAX_HEADERS = 200

    # The maximum number of headers that will be parsed. This is used to protect against hash 
    # vulnerabilities. 
    MAX_COOKIES = 200

    URL_CHARSET = ${application.charset}

    # If this is true then the parser will decode the URL and query parameters using the selected 
    # character encoding (URL_CHARSET by default). If this is false they will not be decoded. 
    # This will allow a later handler to decode them into whatever charset is desired. 
    DECODE_URL = true

    # The idle timeout in milliseconds after which the channel will be closed. 
    # If the underlying channel already has a read or write timeout set the smaller of the two values will be used 
    # for read/write timeouts. 
    IDLE_TIMEOUT = ${server.http.IdleTimeout}

  }

  worker {

    WORKER_NAME = utow

  }

  socket {

    BACKLOG = 1024

  }

  ws {

    # The maximum size of a text message during parsing/generating. 
    MaxTextBufferSize = ${server.ws.MaxTextMessageSize}

    # The maximum size of a binary message during parsing/generating. 
    MaxBinaryBufferSize = ${server.ws.MaxBinaryMessageSize}

    # The time in ms (milliseconds) that a websocket may be idle before closing. 
    IdleTimeout = ${server.ws.IdleTimeout}

  }

}

jetty

Jetty provides a Web server and javax.servlet container, plus support for HTTP/2, WebSocket and many other integrations.

exports

  • Jetty Server

dependency

<dependency>
  <groupId>org.jooby</groupId>
  <artifactId>jooby-jetty</artifactId>
  <version>1.3.0</version>
</dependency>

usage

In order to use a web server all you have to do is add the dependency to your build system. Jooby will find the server and start it.

http/2

HTTP/2 is fully supported:

| H2        | H2C           | PUSH  |
| --------- | ------------- | ----- |
| Yes       | Yes           | Yes   |

You need to add alpn-boot to the JVM bootstrap path. See Jetty HTTP2 documentation.

server.conf

These are the default properties for jetty:

# jetty defaults 
server.module = org.jooby.jetty.Jetty

server.http2.cleartext = true

jetty {

  threads {

    MinThreads = ${server.threads.Min}

    MaxThreads = ${server.threads.Max}

    IdleTimeout = ${server.threads.IdleTimeout}

    Name = jetty task

  }

  FileSizeThreshold = 16k

  http {

    HeaderCacheSize = ${server.http.HeaderSize}

    RequestHeaderSize = ${server.http.HeaderSize}

    ResponseHeaderSize = ${server.http.HeaderSize}

    OutputBufferSize = ${server.http.ResponseBufferSize}

    SendServerVersion = false

    SendXPoweredBy = false

    SendDateHeader = false

    connector {

      # The accept queue size (also known as accept backlog) 
      AcceptQueueSize = 0

      # Use -1 to disable 
      SoLingerTime = -1

      StopTimeout = 30000

      # Sets the maximum Idle time for a connection, which roughly translates to the Socket#setSoTimeout(int) 
      # call, although with NIO implementations other mechanisms may be used to implement the timeout. 
      # The max idle time is applied: 
      # When waiting for a new message to be received on a connection 
      # When waiting for a new message to be sent on a connection 
      # This value is interpreted as the maximum time between some progress being made on the connection. 
      # So if a single byte is read or written, then the timeout is reset. 
      IdleTimeout = ${server.http.IdleTimeout}

    }

  }

  ws {

    # The maximum size of a text message during parsing/generating. 
    # Text messages over this maximum will result in a close code 1009 {@link StatusCode#MESSAGE_TOO_LARGE} 
    MaxTextMessageSize = ${server.ws.MaxTextMessageSize}

    # The maximum size of a text message buffer. 
    # Used ONLY for stream based message writing. 
    MaxTextMessageBufferSize = 32k

    # The maximum size of a binary message during parsing/generating. 
    # Binary messages over this maximum will result in a close code 1009 {@link StatusCode#MESSAGE_TOO_LARGE} 
    MaxBinaryMessageSize = ${server.ws.MaxBinaryMessageSize}

    # The maximum size of a binary message buffer 
    # Used ONLY for for stream based message writing 
    MaxBinaryMessageBufferSize = 32k

    # The timeout in ms (milliseconds) for async write operations. 
    # Negative values indicate a disabled timeout. 
    AsyncWriteTimeout = 60000

    # The time in ms (milliseconds) that a websocket may be idle before closing. 
    IdleTimeout = ${server.ws.IdleTimeout}

    # The size of the input (read from network layer) buffer size. 
    InputBufferSize = 4k

  }

  url.charset = ${application.charset}

}

servlets

{{war.md}}