Embedding Jetty 9 and customizing Socket Address, Port and ThreadPool?

霸气de小男生 提交于 2019-12-13 01:42:01

问题


I have previously used Jetty 8.1.14 as embedded web server in my application. Now I am trying to upgrade to version 9.2.10.

With Jetty 8, it was possible to specify the Host Address and Port using the setters in the "SelectChannelConnector" or "SslSelectChannelConnector", and also the ThreadPool as a constructor argument in the "Server" class.

Now, it seems one can only specify one or the other in the "Server" class. There are only constructor variants for the address and/or port, or the ThreadPool to use. I can't find any variant with all three arguments.

How can I specify all those parameters with Jetty 9? I have tried:

String bindAddress = "myValue";
int port = 12345;
Server s = new Server(new InetSocketAddress(bindAdress, port));

and

ThreadPool t = MyHighlyCustomizedThreadPool();
Server s = new Server(t);

回答1:


Use the ServerConnector for setting listen ports, setting listen host addresses, setting idle timeouts, and setting default protocols. Once started, the same connector can be used to determine actual listening port (if using dynamically assigned ports), actual listen hosts (if using dynamic host addresses), etc ...

Use the HttpConfiguration for setting buffers, secure identification (used for secure redirects), tweaking headers, powered by, server version announcement, etc..

Use ConnectionFactory implementations to control how the progression of protocol selection should work with a recently accepted incoming connection. (Yes, this is a thing that is important in today's Web infrastructure)

For a basic example of HTTP/1.1 and SSL+HTTP/1.1 (aka HTTPS) see the ManyConnectors.java embedded example

For an example of ConnectionFactory behavior with SPDY, see the SpdyConnector.java example (note: SPDY has been deprecated in favor of HTTP/2 in Jetty 9.3.x)

For an example of ConnectionFactory behavior with TLS + ALPN + HTTP/2, see the Http2Server.java example (note: you'll need Jetty 9.3.x for this)



来源:https://stackoverflow.com/questions/30186506/embedding-jetty-9-and-customizing-socket-address-port-and-threadpool

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!