Skip to content

Commit

Permalink
Start of HTTP2
Browse files Browse the repository at this point in the history
* minimal support and working version for Undertow
* this is a work in progress
* undertow 1.4.x ref #443
  • Loading branch information
jknack committed Aug 4, 2016
1 parent c6d882f commit 4dc925f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
2 changes: 1 addition & 1 deletion jooby-undertow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<artifactId>jooby</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Undertow -->
<dependency>
<groupId>io.undertow</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,27 @@ private interface SetOption {
private long awaitShutdown;

@Inject
public UndertowServer(final org.jooby.spi.HttpHandler dispatcher, final Config config,
public UndertowServer(final org.jooby.spi.HttpHandler dispatcher, final Config conf,
final Provider<SSLContext> sslContext)
throws Exception {

awaitShutdown = config.getDuration("undertow.awaitShutdown", TimeUnit.MILLISECONDS);
shutdown = new GracefulShutdownHandler(doHandler(dispatcher, config));
Undertow.Builder ubuilder = configure(config, io.undertow.Undertow.builder())
.addHttpListener(config.getInt("application.port"),
host(config.getString("application.host")));
awaitShutdown = conf.getDuration("undertow.awaitShutdown", TimeUnit.MILLISECONDS);
shutdown = new GracefulShutdownHandler(doHandler(dispatcher, conf));
Undertow.Builder ubuilder = configure(conf, io.undertow.Undertow.builder())
.addHttpListener(conf.getInt("application.port"),
host(conf.getString("application.host")));

if (config.hasPath("application.securePort")) {
ubuilder.addHttpsListener(config.getInt("application.securePort"),
host(config.getString("application.host")), sslContext.get());
boolean http2 = conf.getBoolean("server.http2.enabled");
ubuilder.setServerOption(UndertowOptions.ENABLE_HTTP2, http2);

boolean securePort = conf.hasPath("application.securePort");
if (http2 && !securePort) {
throw new IllegalStateException("HTTP2 requires 'aplication.securePort'");
}

if (securePort) {
ubuilder.addHttpsListener(conf.getInt("application.securePort"),
host(conf.getString("application.host")), sslContext.get());
}

this.server = ubuilder.setHandler(shutdown)
Expand All @@ -92,12 +100,6 @@ static Builder configure(final Config config, final Builder builder) {
builder.setBufferSize(value);
});

set($undertow, "buffersPerRegion", name -> {
int value = $undertow.getInt(name);
log.debug("undertow.buffersPerRegion({})", value);
builder.setBuffersPerRegion(value);
});

set($undertow, "directBuffers", name -> {
boolean value = $undertow.getBoolean(name);
log.debug("undertow.directBuffers({})", value);
Expand Down
19 changes: 19 additions & 0 deletions jooby-undertow/src/test/java/utow/UtowHttp2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package utow;

import org.jooby.Jooby;

public class UtowHttp2 extends Jooby {

{

http2();
securePort(8443);

get("/http2", () -> "OK");

}

public static void main(final String[] args) throws Throwable {
run(UtowHttp2::new, args);
}
}
10 changes: 9 additions & 1 deletion jooby/src/main/java/org/jooby/Jooby.java
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ public EnvDep(final Predicate<String> predicate, final Consumer<Config> callback

private String numberFormat;

private boolean http2;

public Jooby() {
this(null);
}
Expand Down Expand Up @@ -3855,7 +3857,7 @@ public Jooby port(final int port) {
}

/**
* Set the HTTPS port.
* Set the HTTPS port to use.
*
* @param port HTTPS port.
* @return This instance.
Expand All @@ -3865,6 +3867,11 @@ public Jooby securePort(final int port) {
return this;
}

public Jooby http2() {
this.http2 = true;
return this;
}

/**
* Run app in javascript.
*
Expand Down Expand Up @@ -4466,6 +4473,7 @@ private Config defaultConfig(final Config config) {
.withValue("application.lang", ConfigValueFactory.fromAnyRef(lang))
.withValue("application.tz", ConfigValueFactory.fromAnyRef(tz))
.withValue("application.numberFormat", ConfigValueFactory.fromAnyRef(nf))
.withValue("server.http2.enabled", ConfigValueFactory.fromAnyRef(http2))
.withValue("runtime.processors", ConfigValueFactory.fromAnyRef(processors))
.withValue("runtime.processors-plus1", ConfigValueFactory.fromAnyRef(processors + 1))
.withValue("runtime.processors-plus2", ConfigValueFactory.fromAnyRef(processors + 2))
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,7 @@ org.eclipse.jdt.apt.processorOptions/defaultOverwrite=true
<properties>
<!-- Dependencies -->
<jackson.version>2.7.3</jackson.version>
<undertow.version>1.3.23.Final</undertow.version>
<undertow.version>1.4.0.CR4</undertow.version>
<servlet.version>3.1.0</servlet.version>
<jetty.version>9.3.9.v20160517</jetty.version>
<netty.version>4.1.4.Final</netty.version>
Expand Down

0 comments on commit 4dc925f

Please sign in to comment.