Skip to content

Instantly share code, notes, and snippets.

@ingramchen
Created May 8, 2014 13:17
Show Gist options
  • Save ingramchen/98d0cc3b325999fa0a7a to your computer and use it in GitHub Desktop.
Save ingramchen/98d0cc3b325999fa0a7a to your computer and use it in GitHub Desktop.
Embed Tomcat with nio connector
Tomcat tomcat = ....
final Connector nioConnector = new Connector(Http11NioProtocol.class.getName());
nioConnector.setPort(58090);
nioConnector.setSecure(false);
nioConnector.setScheme("http");
nioConnector.setProtocol("HTTP/1.1");
try {
nioConnector.setProperty("address", InetAddress.getByName("localhost").getHostAddress());
} catch (Exception e) {
throw new RuntimeException("unexpected", e);
}
tomcat.getService().removeConnector(tomcat.getConnector());
tomcat.getService().addConnector(nioConnector);
tomcat.setConnector(nioConnector);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment