Jetty 9.x 中Connectors 中的Connection 对象去哪儿了?
Where did the Connection object in the Connectors in Jetty 9.x go?
当我尝试从 Jetty 8.1.12 迁移到 Jetty 9.4.x 时,由于以下问题出现错误。
我们使用 connector.getConnection() 方法。而且我没有在 Jetty 9 中找到任何替代品。4.x。
这是
的后续问题
我们使用 connector.getConnection() 获取 inet 套接字地址。
private InetSocketAddress findFirstInetConnector(Server server) {
Connector[] connectors = server.getConnectors();
if (connectors != null) {
for (Connector connector : connectors) {
Object connection = connector.getConnection();
if (connection instanceof ServerSocketChannel) {
SocketAddress address = ((ServerSocketChannel) connector.getConnection()).socket().getLocalSocketAddress();
if (address instanceof InetSocketAddress) {
return (InetSocketAddress) address;
}
} else if (connection instanceof ServerSocket) {
SocketAddress address = ((ServerSocket) connector.getConnection()).getLocalSocketAddress();
if (address instanceof InetSocketAddress) {
return (InetSocketAddress) address;
}
}
}
}
return null;
}
谁能帮我找到相同的替代品。
一个连接器没有连接了。
你不能再随意地从中得到一个 SocketAddress
或 InetSocketAddress
。
为什么?
嗯,我们有逻辑连接器、物理连接器、非网络连接器、网络连接器、服务器连接器、本地连接器、基于管道的连接器、基于 jni 的连接器、基于 unixsocket 的连接器等...
您必须根据 started 和 运行[=28= 上的信息创建您想要的 InetSocketAddress
] 连接器(例如 NetworkConnector localPort 和 host)。
要遍历连接器信息,您可以...
for (Connector connector : server.getConnectors())
{
// What is the connector name (can be null or unset)
String connectorName = connector.getName();
// What is the declared protocol default for this connector?
String defaultProtocol = connector.getDefaultConnectionFactory().getProtocol();
// What other features does this connector handle?
for (ConnectionFactory connectionFactory : connector.getConnectionFactories())
{
// List of protocols handled by this specific connection factory for this specific connector
connectionFactory.getProtocols();
if (connectionFactory instanceof SslConnectionFactory)
{
// this can handle TLS/SSL based connections
}
if (connectionFactory instanceof HttpConnectionFactory)
{
// this can handle http protocols
// get the http specific configuration
HttpConfiguration httpConfig = ((HttpConnectionFactory) connectionFactory).getHttpConfiguration();
// what port is recognized as secure
httpConfig.getSecurePort();
// what scheme is recognized as secure
httpConfig.getSecureScheme();
}
if (connectionFactory instanceof HTTP2ServerConnectionFactory)
{
// can handle encrypted http/2 protocols (and alpn features)
}
if (connectionFactory instanceof HTTP2CServerConnectionFactory)
{
// this can handle http/2's special clear-text "h2c" protocol (no alpn features)
}
}
if (!connector.isRunning())
{
// no information below can be trusted unless the connector is started
continue;
}
if (connector instanceof NetworkConnector)
{
// we have a network capable connector
NetworkConnector networkConnector = (NetworkConnector) connector;
// What interface is it listening on?
String interfaceName = networkConnector.getHost();
// What local port is it bound to?
int localPort = networkConnector.getLocalPort();
}
}
当我尝试从 Jetty 8.1.12 迁移到 Jetty 9.4.x 时,由于以下问题出现错误。
我们使用 connector.getConnection() 方法。而且我没有在 Jetty 9 中找到任何替代品。4.x。
这是
我们使用 connector.getConnection() 获取 inet 套接字地址。
private InetSocketAddress findFirstInetConnector(Server server) {
Connector[] connectors = server.getConnectors();
if (connectors != null) {
for (Connector connector : connectors) {
Object connection = connector.getConnection();
if (connection instanceof ServerSocketChannel) {
SocketAddress address = ((ServerSocketChannel) connector.getConnection()).socket().getLocalSocketAddress();
if (address instanceof InetSocketAddress) {
return (InetSocketAddress) address;
}
} else if (connection instanceof ServerSocket) {
SocketAddress address = ((ServerSocket) connector.getConnection()).getLocalSocketAddress();
if (address instanceof InetSocketAddress) {
return (InetSocketAddress) address;
}
}
}
}
return null;
}
谁能帮我找到相同的替代品。
一个连接器没有连接了。
你不能再随意地从中得到一个 SocketAddress
或 InetSocketAddress
。
为什么?
嗯,我们有逻辑连接器、物理连接器、非网络连接器、网络连接器、服务器连接器、本地连接器、基于管道的连接器、基于 jni 的连接器、基于 unixsocket 的连接器等...
您必须根据 started 和 运行[=28= 上的信息创建您想要的 InetSocketAddress
] 连接器(例如 NetworkConnector localPort 和 host)。
要遍历连接器信息,您可以...
for (Connector connector : server.getConnectors())
{
// What is the connector name (can be null or unset)
String connectorName = connector.getName();
// What is the declared protocol default for this connector?
String defaultProtocol = connector.getDefaultConnectionFactory().getProtocol();
// What other features does this connector handle?
for (ConnectionFactory connectionFactory : connector.getConnectionFactories())
{
// List of protocols handled by this specific connection factory for this specific connector
connectionFactory.getProtocols();
if (connectionFactory instanceof SslConnectionFactory)
{
// this can handle TLS/SSL based connections
}
if (connectionFactory instanceof HttpConnectionFactory)
{
// this can handle http protocols
// get the http specific configuration
HttpConfiguration httpConfig = ((HttpConnectionFactory) connectionFactory).getHttpConfiguration();
// what port is recognized as secure
httpConfig.getSecurePort();
// what scheme is recognized as secure
httpConfig.getSecureScheme();
}
if (connectionFactory instanceof HTTP2ServerConnectionFactory)
{
// can handle encrypted http/2 protocols (and alpn features)
}
if (connectionFactory instanceof HTTP2CServerConnectionFactory)
{
// this can handle http/2's special clear-text "h2c" protocol (no alpn features)
}
}
if (!connector.isRunning())
{
// no information below can be trusted unless the connector is started
continue;
}
if (connector instanceof NetworkConnector)
{
// we have a network capable connector
NetworkConnector networkConnector = (NetworkConnector) connector;
// What interface is it listening on?
String interfaceName = networkConnector.getHost();
// What local port is it bound to?
int localPort = networkConnector.getLocalPort();
}
}