在Jetty v.9.4.3中不能使用两个连接器(http和https) [英] Can't use two connectors (http and https) in Jetty v.9.4.3

查看:226
本文介绍了在Jetty v.9.4.3中不能使用两个连接器(http和https)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我向嵌入式Jetty服务器添加两个连接器时,我既不能使用HTTP也不能使用HTTPS-浏览器/卷曲只是卡住了.我用于创建嵌入式Jetty的代码大致如下(它基于此示例-

When I'm adding two connectors to embedded Jetty server I can't use neither HTTP nor HTTPS - browser/curl is simply stuck. The code I use to create embedded Jetty is approximately the following (it is based on this example - http://self-learning-java-tutorial.blogspot.de/2015/10/jetty-configuring-many-connectors.html):

HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setRequestHeaderSize(requestHeaderSize);

ServerConnector httpConnector= new ServerConnector(server, 1, -1, new 
    HttpConnectionFactory(httpConfiguration));
httpConnector.setPort(getPort());
httpConnector.setReuseAddress(true);
httpConnector.setIdleTimeout(maxTimeout);
server.addConnector(httpConnector);

HttpConfiguration httpsConfiguration = new HttpConfiguration();
httpsConfiguration.setSecureScheme("https");
httpsConfiguration.setSecurePort(securePort);
httpsConfiguration.addCustomizer(new SecureRequestCustomizer());

ServerConnector sslConnector = new ServerConnector(server,
            new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
            new HttpConnectionFactory(httpsConfiguration));
sslConnector.setPort(securePort);
sslConnector.setIdleTimeout(maxTimeout);
sslConnector.setReuseAddress(true);

server.addConnector(sslConnector);

ServletContextHandler servContext = new 
ServletContextHandler(ServletContextHandler.NO_SESSIONS);
servContext.setContextPath("/");
server.setHandler(servContext);
server.start();

我打开了org.eclipse.jetty中的调试日志,并且在任何请求下我都得到以下信息:

I turned on debug logs inside org.eclipse.jetty and on any request I get the following:

 Selector loop woken up from select, 0/1 selected [] [io.ManagedSelector][jetty-default-3]
 Running action org.eclipse.jetty.io.ManagedSelector$Accept@4278b8a5 [][io.ManagedSelector] [jetty-default-3]
 Queued change org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@535fb063 on org.eclipse.jetty.io.ManagedSelector@3959754c id=3 keys=2 selected=0 [] [io.ManagedSelector] [jetty-default-3]
 EatWhatYouKill@1289003f/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@7ff1b622/PRODUCING/0/1->PRODUCING/0/1 PEC org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@535fb063 [] [strategy.EatWhatYouKill] [jetty-default-3]
 Selector loop waiting on select [] [io.ManagedSelector] [jetty-default-3]

仅添加一个连接器时,所有功能均按预期工作.

When only one connector is added everything works as expected.

P.S.这样的问题选择器循环等待选择"在运行使用Wiremock存根的多个测试用例时 Jetty + Jersey infinite带有curl post查询的循环除了是9.3(我使用9.4.3)中修复的码头错误外,没有给出任何答案

P.S. SO questions "Selector loop waiting on select" when running multiple test cases which use wiremock stubs and Jetty+Jersey infinite loop with curl post query don't give any answer other than it's a jetty bug fixed in 9.3 (I use 9.4.3)

推荐答案

Embedded Jetty支持一台服务器上尽可能多的连接器. Jetty没有技术限制(仅有的限制存在于您环境中的OS和网络堆栈中)

Embedded Jetty supports as many connectors on 1 server as you can dream up. There is no technical limitation in Jetty (the only limitations that exist are in the OS and Networking stacks on your environment)

请务必注意,您必须具有健全的HttpConfiguration设置. 因为它们可以引用彼此的连接器. (这是针对安全"行为,安全约束等)

Its important to note that you have to have a sane HttpConfiguration setup. As they can refer to each other's connectors. (this is for "is secure" behavior, security constraints, etc)

虽然可能有多个简单的彼此不认识的连接器,但这不是一般的用例.

While it is possible to have multiple connectors that simple are not aware of each other, this is not the general use case.

使用HTTPS(又名TLS/SSL上的HTTP)时,证书(大小,类型,标识等)的选择以及密码套件的选择将影响您连接到该HTTPS连接器的能力.

When using HTTPS (aka HTTP over TLS/SSL) the choice of Certificates (sizes, types, alogorithms, etc), and Cipher suite selections will impact your ability to connect to that HTTPS connector.

请注意,HTTPS是TLS(不是SSL),Jetty可以使用TLS的ALPN扩展名,该扩展名允许客户端协商下一个实际使用的协议(HTTP/1.x或HTTP/2或您配置的任何协议)下一个协议列表是)

Note that HTTPS is TLS (not SSL), and Jetty can use the ALPN extensions to TLS which allow the client to negotiate the next protocol to actually use (be it HTTP/1.x or HTTP/2 or whatever your configured next protocol list is)

以下是嵌入式Jetty中多个连接器的示例.

Here's a few examples of multiple connectors in embedded Jetty.

jetty-project/embedded-jetty-cookbook-ConnectorSpecificContexts.java

jetty-project/embedded-jetty-cookbook-ConnectorSpecificWebapps.java

jetty-project/embedded-jetty-cookbook-SecuredRedirectHandlerExample.java

jetty-project/embedded-jetty-cookbook-ServletTransportGuaranteeExample.java

这篇关于在Jetty v.9.4.3中不能使用两个连接器(http和https)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆