* Fixes #6410 - Use SocketAddress instead of InetSocketAddress. Removed usages of InetSocketAddress in method signatures where possible. Deprecated old methods, and added new methods with SocketAddress. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
a415606e01
commit
b8d6e3f010
|
@ -13,7 +13,7 @@
|
|||
|
||||
package org.eclipse.jetty.docs.programming.server.http2;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -82,7 +82,7 @@ public class HTTP2ServerDocs
|
|||
@Override
|
||||
public void onAccept(Session session)
|
||||
{
|
||||
InetSocketAddress remoteAddress = session.getRemoteAddress();
|
||||
SocketAddress remoteAddress = session.getRemoteSocketAddress();
|
||||
System.getLogger("http2").log(INFO, "Connection from {0}", remoteAddress);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -18,7 +18,6 @@ module org.eclipse.jetty.client
|
|||
exports org.eclipse.jetty.client.dynamic;
|
||||
exports org.eclipse.jetty.client.http;
|
||||
exports org.eclipse.jetty.client.jmx to org.eclipse.jetty.jmx;
|
||||
exports org.eclipse.jetty.client.proxy;
|
||||
exports org.eclipse.jetty.client.util;
|
||||
|
||||
requires org.eclipse.jetty.alpn.client;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.jetty.client;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
@ -62,7 +63,7 @@ public abstract class AbstractConnectorHttpClientTransport extends AbstractHttpC
|
|||
}
|
||||
|
||||
@Override
|
||||
public void connect(InetSocketAddress address, Map<String, Object> context)
|
||||
public void connect(SocketAddress address, Map<String, Object> context)
|
||||
{
|
||||
HttpDestination destination = (HttpDestination)context.get(HTTP_DESTINATION_CONTEXT_KEY);
|
||||
context.put(ClientConnector.CLIENT_CONNECTION_FACTORY_CONTEXT_KEY, destination.getClientConnectionFactory());
|
||||
|
@ -71,4 +72,10 @@ public abstract class AbstractConnectorHttpClientTransport extends AbstractHttpC
|
|||
context.put(ClientConnector.CONNECTION_PROMISE_CONTEXT_KEY, Promise.from(ioConnection -> {}, promise::failed));
|
||||
connector.connect(address, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(InetSocketAddress address, Map<String, Object> context)
|
||||
{
|
||||
connect((SocketAddress)address, context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -590,7 +590,7 @@ public class HttpClient extends ContainerLifeCycle
|
|||
connect(socketAddresses, nextIndex, context);
|
||||
}
|
||||
});
|
||||
transport.connect(socketAddresses.get(index), context);
|
||||
transport.connect((SocketAddress)socketAddresses.get(index), context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.jetty.client;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.io.ClientConnectionFactory;
|
||||
|
@ -69,9 +70,25 @@ public interface HttpClientTransport extends ClientConnectionFactory
|
|||
*
|
||||
* @param address the address to connect to
|
||||
* @param context the context information to establish the connection
|
||||
* @deprecated use {@link #connect(SocketAddress, Map)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public void connect(InetSocketAddress address, Map<String, Object> context);
|
||||
|
||||
/**
|
||||
* Establishes a physical connection to the given {@code address}.
|
||||
*
|
||||
* @param address the address to connect to
|
||||
* @param context the context information to establish the connection
|
||||
*/
|
||||
public default void connect(SocketAddress address, Map<String, Object> context)
|
||||
{
|
||||
if (address instanceof InetSocketAddress)
|
||||
connect((InetSocketAddress)address, context);
|
||||
else
|
||||
throw new UnsupportedOperationException("Unsupported SocketAddress " + address);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the factory for ConnectionPool instances
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.eclipse.jetty.client;
|
|||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
@ -60,10 +61,18 @@ public abstract class ProxyProtocolClientConnectionFactory implements ClientConn
|
|||
Tag tag = (Tag)destination.getOrigin().getTag();
|
||||
if (tag == null)
|
||||
{
|
||||
InetSocketAddress local = endPoint.getLocalAddress();
|
||||
InetSocketAddress remote = endPoint.getRemoteAddress();
|
||||
boolean ipv4 = local.getAddress() instanceof Inet4Address;
|
||||
tag = new Tag(ipv4 ? "TCP4" : "TCP6", local.getAddress().getHostAddress(), local.getPort(), remote.getAddress().getHostAddress(), remote.getPort());
|
||||
SocketAddress local = endPoint.getLocalSocketAddress();
|
||||
InetSocketAddress inetLocal = local instanceof InetSocketAddress ? (InetSocketAddress)local : null;
|
||||
InetAddress localAddress = inetLocal == null ? null : inetLocal.getAddress();
|
||||
SocketAddress remote = endPoint.getRemoteSocketAddress();
|
||||
InetSocketAddress inetRemote = remote instanceof InetSocketAddress ? (InetSocketAddress)remote : null;
|
||||
InetAddress remoteAddress = inetRemote == null ? null : inetRemote.getAddress();
|
||||
String family = local == null || inetLocal == null ? "UNKNOWN" : localAddress instanceof Inet4Address ? "TCP4" : "TCP6";
|
||||
tag = new Tag(family,
|
||||
localAddress == null ? null : localAddress.getHostAddress(),
|
||||
inetLocal == null ? 0 : inetLocal.getPort(),
|
||||
remoteAddress == null ? null : remoteAddress.getHostAddress(),
|
||||
inetRemote == null ? 0 : inetRemote.getPort());
|
||||
}
|
||||
return new ProxyProtocolConnectionV1(endPoint, executor, getClientConnectionFactory(), context, tag);
|
||||
}
|
||||
|
@ -198,10 +207,21 @@ public abstract class ProxyProtocolClientConnectionFactory implements ClientConn
|
|||
Tag tag = (Tag)destination.getOrigin().getTag();
|
||||
if (tag == null)
|
||||
{
|
||||
InetSocketAddress local = endPoint.getLocalAddress();
|
||||
InetSocketAddress remote = endPoint.getRemoteAddress();
|
||||
boolean ipv4 = local.getAddress() instanceof Inet4Address;
|
||||
tag = new Tag(Tag.Command.PROXY, ipv4 ? Tag.Family.INET4 : Tag.Family.INET6, Tag.Protocol.STREAM, local.getAddress().getHostAddress(), local.getPort(), remote.getAddress().getHostAddress(), remote.getPort(), null);
|
||||
SocketAddress local = endPoint.getLocalSocketAddress();
|
||||
InetSocketAddress inetLocal = local instanceof InetSocketAddress ? (InetSocketAddress)local : null;
|
||||
InetAddress localAddress = inetLocal == null ? null : inetLocal.getAddress();
|
||||
SocketAddress remote = endPoint.getRemoteSocketAddress();
|
||||
InetSocketAddress inetRemote = remote instanceof InetSocketAddress ? (InetSocketAddress)remote : null;
|
||||
InetAddress remoteAddress = inetRemote == null ? null : inetRemote.getAddress();
|
||||
Tag.Family family = local == null || inetLocal == null ? Tag.Family.UNSPEC : localAddress instanceof Inet4Address ? Tag.Family.INET4 : Tag.Family.INET6;
|
||||
tag = new Tag(Tag.Command.PROXY,
|
||||
family,
|
||||
Tag.Protocol.STREAM,
|
||||
localAddress == null ? null : localAddress.getHostAddress(),
|
||||
inetLocal == null ? 0 : inetLocal.getPort(),
|
||||
remoteAddress == null ? null : remoteAddress.getHostAddress(),
|
||||
inetRemote == null ? 0 : inetRemote.getPort(),
|
||||
null);
|
||||
}
|
||||
return new ProxyProtocolConnectionV2(endPoint, executor, getClientConnectionFactory(), context, tag);
|
||||
}
|
||||
|
@ -220,14 +240,14 @@ public abstract class ProxyProtocolClientConnectionFactory implements ClientConn
|
|||
*/
|
||||
public static final Tag LOCAL = new Tag(Command.LOCAL, Family.UNSPEC, Protocol.UNSPEC, null, 0, null, 0, null);
|
||||
|
||||
private Command command;
|
||||
private Family family;
|
||||
private Protocol protocol;
|
||||
private String srcIP;
|
||||
private int srcPort;
|
||||
private String dstIP;
|
||||
private int dstPort;
|
||||
private List<TLV> tlvs;
|
||||
private final Command command;
|
||||
private final Family family;
|
||||
private final Protocol protocol;
|
||||
private final String srcIP;
|
||||
private final int srcPort;
|
||||
private final String dstIP;
|
||||
private final int dstPort;
|
||||
private final List<TLV> tlvs;
|
||||
|
||||
/**
|
||||
* <p>Creates a Tag whose metadata will be derived from the underlying EndPoint.</p>
|
||||
|
@ -514,32 +534,36 @@ public abstract class ProxyProtocolClientConnectionFactory implements ClientConn
|
|||
{
|
||||
try
|
||||
{
|
||||
InetSocketAddress localAddress = endPoint.getLocalAddress();
|
||||
InetSocketAddress remoteAddress = endPoint.getRemoteAddress();
|
||||
SocketAddress local = endPoint.getLocalSocketAddress();
|
||||
InetSocketAddress inetLocal = local instanceof InetSocketAddress ? (InetSocketAddress)local : null;
|
||||
InetAddress localAddress = inetLocal == null ? null : inetLocal.getAddress();
|
||||
SocketAddress remote = endPoint.getRemoteSocketAddress();
|
||||
InetSocketAddress inetRemote = remote instanceof InetSocketAddress ? (InetSocketAddress)remote : null;
|
||||
InetAddress remoteAddress = inetRemote == null ? null : inetRemote.getAddress();
|
||||
String family = tag.getFamily();
|
||||
String srcIP = tag.getSourceAddress();
|
||||
int srcPort = tag.getSourcePort();
|
||||
String dstIP = tag.getDestinationAddress();
|
||||
int dstPort = tag.getDestinationPort();
|
||||
if (family == null)
|
||||
family = localAddress.getAddress() instanceof Inet4Address ? "TCP4" : "TCP6";
|
||||
family = local == null || inetLocal == null ? "UNKNOWN" : localAddress instanceof Inet4Address ? "TCP4" : "TCP6";
|
||||
family = family.toUpperCase(Locale.ENGLISH);
|
||||
boolean unknown = family.equals("UNKNOWN");
|
||||
StringBuilder builder = new StringBuilder(64);
|
||||
builder.append("PROXY ").append(family);
|
||||
if (!unknown)
|
||||
{
|
||||
if (srcIP == null)
|
||||
srcIP = localAddress.getAddress().getHostAddress();
|
||||
if (srcIP == null && localAddress != null)
|
||||
srcIP = localAddress.getHostAddress();
|
||||
builder.append(" ").append(srcIP);
|
||||
if (dstIP == null)
|
||||
dstIP = remoteAddress.getAddress().getHostAddress();
|
||||
if (dstIP == null && remoteAddress != null)
|
||||
dstIP = remoteAddress.getHostAddress();
|
||||
builder.append(" ").append(dstIP);
|
||||
if (srcPort <= 0)
|
||||
srcPort = localAddress.getPort();
|
||||
if (srcPort <= 0 && inetLocal != null)
|
||||
srcPort = inetLocal.getPort();
|
||||
builder.append(" ").append(srcPort);
|
||||
if (dstPort <= 0)
|
||||
dstPort = remoteAddress.getPort();
|
||||
if (dstPort <= 0 && inetRemote != null)
|
||||
dstPort = inetRemote.getPort();
|
||||
builder.append(" ").append(dstPort);
|
||||
}
|
||||
builder.append("\r\n");
|
||||
|
@ -590,16 +614,19 @@ public abstract class ProxyProtocolClientConnectionFactory implements ClientConn
|
|||
buffer.put((byte)versionAndCommand);
|
||||
V2.Tag.Family family = tag.getFamily();
|
||||
String srcAddr = tag.getSourceAddress();
|
||||
if (srcAddr == null)
|
||||
srcAddr = endPoint.getLocalAddress().getAddress().getHostAddress();
|
||||
SocketAddress local = endPoint.getLocalSocketAddress();
|
||||
InetSocketAddress inetLocal = local instanceof InetSocketAddress ? (InetSocketAddress)local : null;
|
||||
InetAddress localAddress = inetLocal == null ? null : inetLocal.getAddress();
|
||||
if (srcAddr == null && localAddress != null)
|
||||
srcAddr = localAddress.getHostAddress();
|
||||
int srcPort = tag.getSourcePort();
|
||||
if (srcPort <= 0)
|
||||
srcPort = endPoint.getLocalAddress().getPort();
|
||||
if (srcPort <= 0 && inetLocal != null)
|
||||
srcPort = inetLocal.getPort();
|
||||
if (family == null)
|
||||
family = InetAddress.getByName(srcAddr) instanceof Inet4Address ? V2.Tag.Family.INET4 : V2.Tag.Family.INET6;
|
||||
family = local == null || inetLocal == null ? V2.Tag.Family.UNSPEC : localAddress instanceof Inet4Address ? V2.Tag.Family.INET4 : V2.Tag.Family.INET6;
|
||||
V2.Tag.Protocol protocol = tag.getProtocol();
|
||||
if (protocol == null)
|
||||
protocol = V2.Tag.Protocol.STREAM;
|
||||
protocol = local == null ? V2.Tag.Protocol.UNSPEC : V2.Tag.Protocol.STREAM;
|
||||
int familyAndProtocol = (family.ordinal() << 4) | protocol.ordinal();
|
||||
buffer.put((byte)familyAndProtocol);
|
||||
int length = 0;
|
||||
|
@ -622,11 +649,14 @@ public abstract class ProxyProtocolClientConnectionFactory implements ClientConn
|
|||
length += vectorsLength;
|
||||
buffer.putShort((short)length);
|
||||
String dstAddr = tag.getDestinationAddress();
|
||||
if (dstAddr == null)
|
||||
dstAddr = endPoint.getRemoteAddress().getAddress().getHostAddress();
|
||||
SocketAddress remote = endPoint.getRemoteSocketAddress();
|
||||
InetSocketAddress inetRemote = remote instanceof InetSocketAddress ? (InetSocketAddress)remote : null;
|
||||
InetAddress remoteAddress = inetRemote == null ? null : inetRemote.getAddress();
|
||||
if (dstAddr == null && remoteAddress != null)
|
||||
dstAddr = remoteAddress.getHostAddress();
|
||||
int dstPort = tag.getDestinationPort();
|
||||
if (dstPort <= 0)
|
||||
dstPort = endPoint.getRemoteAddress().getPort();
|
||||
if (dstPort <= 0 && inetRemote != null)
|
||||
dstPort = inetRemote.getPort();
|
||||
switch (family)
|
||||
{
|
||||
case UNSPEC:
|
||||
|
@ -640,9 +670,14 @@ public abstract class ProxyProtocolClientConnectionFactory implements ClientConn
|
|||
break;
|
||||
case UNIX:
|
||||
int position = buffer.position();
|
||||
if (srcAddr != null)
|
||||
buffer.put(srcAddr.getBytes(StandardCharsets.US_ASCII));
|
||||
buffer.position(position + 108);
|
||||
position = position + 108;
|
||||
buffer.position(position);
|
||||
if (dstAddr != null)
|
||||
buffer.put(dstAddr.getBytes(StandardCharsets.US_ASCII));
|
||||
position = position + 108;
|
||||
buffer.position(position);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
|
|
|
@ -256,8 +256,8 @@ public class HttpConnectionOverHTTP extends AbstractConnection implements IConne
|
|||
return String.format("%s@%x(l:%s <-> r:%s,closed=%b)=>%s",
|
||||
getClass().getSimpleName(),
|
||||
hashCode(),
|
||||
getEndPoint().getLocalAddress(),
|
||||
getEndPoint().getRemoteAddress(),
|
||||
getEndPoint().getLocalSocketAddress(),
|
||||
getEndPoint().getRemoteSocketAddress(),
|
||||
closed.get(),
|
||||
channel);
|
||||
}
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others.
|
||||
//
|
||||
// This program and the accompanying materials are made available under the
|
||||
// terms of the Eclipse Public License v. 2.0 which is available at
|
||||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
|
||||
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
|
||||
//
|
||||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.client.proxy;
|
||||
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClientTransport;
|
||||
import org.eclipse.jetty.client.HttpDestination;
|
||||
import org.eclipse.jetty.client.Origin;
|
||||
import org.eclipse.jetty.client.api.Connection;
|
||||
import org.eclipse.jetty.io.AbstractConnection;
|
||||
import org.eclipse.jetty.io.ClientConnectionFactory;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.Promise;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ProxyProtocolClientConnectionFactory implements ClientConnectionFactory
|
||||
{
|
||||
private final ClientConnectionFactory connectionFactory;
|
||||
private final Supplier<Origin.Address> proxiedAddressSupplier;
|
||||
|
||||
public ProxyProtocolClientConnectionFactory(ClientConnectionFactory connectionFactory, Supplier<Origin.Address> proxiedAddressSupplier)
|
||||
{
|
||||
this.connectionFactory = connectionFactory;
|
||||
this.proxiedAddressSupplier = proxiedAddressSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.jetty.io.Connection newConnection(EndPoint endPoint, Map<String, Object> context)
|
||||
{
|
||||
HttpDestination destination = (HttpDestination)context.get(HttpClientTransport.HTTP_DESTINATION_CONTEXT_KEY);
|
||||
Executor executor = destination.getHttpClient().getExecutor();
|
||||
ProxyProtocolConnection connection = new ProxyProtocolConnection(endPoint, executor, context);
|
||||
return customize(connection, context);
|
||||
}
|
||||
|
||||
private class ProxyProtocolConnection extends AbstractConnection implements Callback
|
||||
{
|
||||
private final Logger log = LoggerFactory.getLogger(ProxyProtocolConnection.class);
|
||||
private final Map<String, Object> context;
|
||||
|
||||
public ProxyProtocolConnection(EndPoint endPoint, Executor executor, Map<String, Object> context)
|
||||
{
|
||||
super(endPoint, executor);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen()
|
||||
{
|
||||
super.onOpen();
|
||||
writePROXYLine();
|
||||
}
|
||||
|
||||
// @checkstyle-disable-check : MethodNameCheck
|
||||
|
||||
protected void writePROXYLine()
|
||||
{
|
||||
Origin.Address proxiedAddress = proxiedAddressSupplier.get();
|
||||
if (proxiedAddress == null)
|
||||
{
|
||||
failed(new IllegalArgumentException("Missing proxied socket address"));
|
||||
return;
|
||||
}
|
||||
String proxiedIP = proxiedAddress.getHost();
|
||||
int proxiedPort = proxiedAddress.getPort();
|
||||
InetSocketAddress serverSocketAddress = getEndPoint().getRemoteAddress();
|
||||
InetAddress serverAddress = serverSocketAddress.getAddress();
|
||||
String serverIP = serverAddress.getHostAddress();
|
||||
int serverPort = serverSocketAddress.getPort();
|
||||
|
||||
boolean ipv6 = serverAddress instanceof Inet6Address;
|
||||
String line = String.format("PROXY %s %s %s %d %d\r\n", ipv6 ? "TCP6" : "TCP4", proxiedIP, serverIP, proxiedPort, serverPort);
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Writing PROXY line: {}", line.trim());
|
||||
ByteBuffer buffer = ByteBuffer.wrap(line.getBytes(StandardCharsets.US_ASCII));
|
||||
getEndPoint().write(this, buffer);
|
||||
}
|
||||
|
||||
// @checkstyle-enable-check : MethodNameCheck
|
||||
|
||||
@Override
|
||||
public void succeeded()
|
||||
{
|
||||
try
|
||||
{
|
||||
EndPoint endPoint = getEndPoint();
|
||||
org.eclipse.jetty.io.Connection connection = connectionFactory.newConnection(endPoint, context);
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Written PROXY line, upgrading to {}", connection);
|
||||
endPoint.upgrade(connection);
|
||||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
failed(x);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable x)
|
||||
{
|
||||
close();
|
||||
@SuppressWarnings("unchecked")
|
||||
Promise<Connection> promise = (Promise<Connection>)context.get(HttpClientTransport.HTTP_CONNECTION_PROMISE_CONTEXT_KEY);
|
||||
promise.failed(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InvocationType getInvocationType()
|
||||
{
|
||||
return InvocationType.NON_BLOCKING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFillable()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -356,8 +356,8 @@ public class HttpConnectionOverFCGI extends AbstractConnection implements IConne
|
|||
return String.format("%s@%x[l:%s<->r:%s]",
|
||||
getClass().getSimpleName(),
|
||||
hashCode(),
|
||||
getEndPoint().getLocalAddress(),
|
||||
getEndPoint().getRemoteAddress());
|
||||
getEndPoint().getLocalSocketAddress(),
|
||||
getEndPoint().getRemoteSocketAddress());
|
||||
}
|
||||
|
||||
private class Delegate extends HttpConnection
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.jetty.http2;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayDeque;
|
||||
|
@ -902,13 +903,31 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
|
|||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
{
|
||||
return endPoint.getLocalAddress();
|
||||
SocketAddress local = getLocalSocketAddress();
|
||||
if (local instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)local;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
return endPoint.getLocalSocketAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
return endPoint.getRemoteAddress();
|
||||
SocketAddress remote = getRemoteSocketAddress();
|
||||
if (remote instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)remote;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteSocketAddress()
|
||||
{
|
||||
return endPoint.getRemoteSocketAddress();
|
||||
}
|
||||
|
||||
@ManagedAttribute(value = "The flow control send window", readonly = true)
|
||||
|
@ -1190,8 +1209,8 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio
|
|||
return String.format("%s@%x{local:%s,remote:%s,sendWindow=%s,recvWindow=%s,%s}",
|
||||
getClass().getSimpleName(),
|
||||
hashCode(),
|
||||
getEndPoint().getLocalAddress(),
|
||||
getEndPoint().getRemoteAddress(),
|
||||
getEndPoint().getLocalSocketAddress(),
|
||||
getEndPoint().getRemoteSocketAddress(),
|
||||
sendWindow,
|
||||
recvWindow,
|
||||
streamsState
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.jetty.http2;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadPendingException;
|
||||
|
@ -57,13 +58,31 @@ public abstract class HTTP2StreamEndPoint implements EndPoint
|
|||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
{
|
||||
return stream.getSession().getLocalAddress();
|
||||
SocketAddress local = getLocalSocketAddress();
|
||||
if (local instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)local;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
return stream.getSession().getLocalSocketAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
return stream.getSession().getRemoteAddress();
|
||||
SocketAddress remote = getRemoteSocketAddress();
|
||||
if (remote instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)remote;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteSocketAddress()
|
||||
{
|
||||
return stream.getSession().getRemoteSocketAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.jetty.http2.api;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
@ -137,14 +138,36 @@ public interface Session
|
|||
/**
|
||||
* @return the local network address this session is bound to,
|
||||
* or {@code null} if this session is not bound to a network address
|
||||
* @deprecated use {@link #getLocalSocketAddress()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public InetSocketAddress getLocalAddress();
|
||||
|
||||
/**
|
||||
* @return the local network address this session is bound to,
|
||||
* or {@code null} if this session is not bound to a network address
|
||||
*/
|
||||
public default SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
return getLocalAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the remote network address this session is connected to,
|
||||
* or {@code null} if this session is not connected to a network address
|
||||
* @deprecated use {@link #getRemoteSocketAddress()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public InetSocketAddress getRemoteAddress();
|
||||
|
||||
/**
|
||||
* @return the remote network address this session is connected to,
|
||||
* or {@code null} if this session is not connected to a network address
|
||||
*/
|
||||
public InetSocketAddress getRemoteAddress();
|
||||
public default SocketAddress getRemoteSocketAddress()
|
||||
{
|
||||
return getRemoteAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>A {@link Listener} is the passive counterpart of a {@link Session} and
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.jetty.http2.client.http;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -118,7 +119,7 @@ public class HttpClientTransportOverHTTP2 extends AbstractHttpClientTransport
|
|||
}
|
||||
|
||||
@Override
|
||||
public void connect(InetSocketAddress address, Map<String, Object> context)
|
||||
public void connect(SocketAddress address, Map<String, Object> context)
|
||||
{
|
||||
HttpClient httpClient = getHttpClient();
|
||||
client.setConnectTimeout(httpClient.getConnectTimeout());
|
||||
|
@ -131,11 +132,22 @@ public class HttpClientTransportOverHTTP2 extends AbstractHttpClientTransport
|
|||
connect(address, destination.getClientConnectionFactory(), listenerPromise, listenerPromise, context);
|
||||
}
|
||||
|
||||
protected void connect(InetSocketAddress address, ClientConnectionFactory factory, Session.Listener listener, Promise<Session> promise, Map<String, Object> context)
|
||||
@Override
|
||||
public void connect(InetSocketAddress address, Map<String, Object> context)
|
||||
{
|
||||
connect((SocketAddress)address, context);
|
||||
}
|
||||
|
||||
protected void connect(SocketAddress address, ClientConnectionFactory factory, Session.Listener listener, Promise<Session> promise, Map<String, Object> context)
|
||||
{
|
||||
getHTTP2Client().connect(address, factory, listener, promise, context);
|
||||
}
|
||||
|
||||
protected void connect(InetSocketAddress address, ClientConnectionFactory factory, Session.Listener listener, Promise<Session> promise, Map<String, Object> context)
|
||||
{
|
||||
connect((SocketAddress)address, factory, listener, promise, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.eclipse.jetty.io.Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException
|
||||
{
|
||||
|
@ -144,7 +156,7 @@ public class HttpClientTransportOverHTTP2 extends AbstractHttpClientTransport
|
|||
ClientConnectionFactory factory = connectionFactory;
|
||||
HttpDestination destination = (HttpDestination)context.get(HTTP_DESTINATION_CONTEXT_KEY);
|
||||
ProxyConfiguration.Proxy proxy = destination.getProxy();
|
||||
boolean ssl = proxy == null ? HttpScheme.HTTPS.is(destination.getScheme()) : proxy.isSecure();
|
||||
boolean ssl = proxy == null ? destination.isSecure() : proxy.isSecure();
|
||||
if (ssl && isUseALPN())
|
||||
factory = new ALPNClientConnectionFactory(client.getExecutor(), factory, client.getProtocols());
|
||||
return factory.newConnection(endPoint, context);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
package org.eclipse.jetty.http2.client.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -179,7 +179,7 @@ public class MaxConcurrentStreamsTest extends AbstractTest
|
|||
client = new HttpClient(new HttpClientTransportOverHTTP2(new HTTP2Client())
|
||||
{
|
||||
@Override
|
||||
protected void connect(InetSocketAddress address, ClientConnectionFactory factory, Session.Listener listener, Promise<Session> promise, Map<String, Object> context)
|
||||
protected void connect(SocketAddress address, ClientConnectionFactory factory, Session.Listener listener, Promise<Session> promise, Map<String, Object> context)
|
||||
{
|
||||
super.connect(address, factory, new Wrapper(listener)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
package org.eclipse.jetty.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
@ -55,6 +57,36 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
|
|||
super(scheduler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
{
|
||||
SocketAddress local = getLocalSocketAddress();
|
||||
if (local instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)local;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
SocketAddress remote = getRemoteSocketAddress();
|
||||
if (remote instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)remote;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteSocketAddress()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected final void shutdownInput()
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
|
@ -470,8 +502,8 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
|
|||
return String.format("%s@%h{l=%s,r=%s,%s,fill=%s,flush=%s,to=%d/%d}",
|
||||
name,
|
||||
this,
|
||||
getLocalAddress(),
|
||||
getRemoteAddress(),
|
||||
getLocalSocketAddress(),
|
||||
getRemoteSocketAddress(),
|
||||
_state.get(),
|
||||
_fillInterest.toStateString(),
|
||||
_writeFlusher.toStateString(),
|
||||
|
|
|
@ -15,10 +15,9 @@ package org.eclipse.jetty.io;
|
|||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -39,29 +38,21 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
public class ByteArrayEndPoint extends AbstractEndPoint
|
||||
{
|
||||
static final Logger LOG = LoggerFactory.getLogger(ByteArrayEndPoint.class);
|
||||
static final InetAddress NOIP;
|
||||
static final InetSocketAddress NOIPPORT;
|
||||
private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 1024;
|
||||
|
||||
static
|
||||
private static SocketAddress noSocketAddress()
|
||||
{
|
||||
InetAddress noip = null;
|
||||
try
|
||||
{
|
||||
noip = Inet4Address.getByName("0.0.0.0");
|
||||
return new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 0);
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
catch (Throwable x)
|
||||
{
|
||||
LOG.warn("Unable to get IPv4 no-ip reference for 0.0.0.0", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
NOIP = noip;
|
||||
NOIPPORT = new InetSocketAddress(NOIP, 0);
|
||||
throw new RuntimeIOException(x);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ByteArrayEndPoint.class);
|
||||
private static final SocketAddress NO_SOCKET_ADDRESS = noSocketAddress();
|
||||
private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 1024;
|
||||
private static final ByteBuffer EOF = BufferUtil.allocate(0);
|
||||
|
||||
private final Runnable _runFillable = () -> getFillInterest().fillable();
|
||||
|
@ -121,6 +112,18 @@ public class ByteArrayEndPoint extends AbstractEndPoint
|
|||
onOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
return NO_SOCKET_ADDRESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteSocketAddress()
|
||||
{
|
||||
return NO_SOCKET_ADDRESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doShutdownOutput()
|
||||
{
|
||||
|
@ -141,18 +144,6 @@ public class ByteArrayEndPoint extends AbstractEndPoint
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
{
|
||||
return NOIPPORT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
return NOIPPORT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIncompleteFlush()
|
||||
{
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.eclipse.jetty.io;
|
|||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadPendingException;
|
||||
import java.nio.channels.WritePendingException;
|
||||
|
@ -100,17 +101,39 @@ public interface EndPoint extends Closeable
|
|||
}
|
||||
|
||||
/**
|
||||
* @return The local Inet address to which this {@code EndPoint} is bound, or {@code null}
|
||||
* if this {@code EndPoint} does not represent a network connection.
|
||||
* @return The local InetSocketAddress to which this {@code EndPoint} is bound, or {@code null}
|
||||
* if this {@code EndPoint} is not bound to a Socket address.
|
||||
* @deprecated use {@link #getLocalSocketAddress()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
InetSocketAddress getLocalAddress();
|
||||
|
||||
/**
|
||||
* @return The remote Inet address to which this {@code EndPoint} is bound, or {@code null}
|
||||
* if this {@code EndPoint} does not represent a network connection.
|
||||
* @return the local SocketAddress to which this {@code EndPoint} is bound or {@code null}
|
||||
* if this {@code EndPoint} is not bound to a Socket address.
|
||||
*/
|
||||
default SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
return getLocalAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The remote InetSocketAddress to which this {@code EndPoint} is connected, or {@code null}
|
||||
* if this {@code EndPoint} is not connected to a Socket address.
|
||||
* @deprecated use {@link #getRemoteSocketAddress()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
InetSocketAddress getRemoteAddress();
|
||||
|
||||
/**
|
||||
* @return The remote SocketAddress to which this {@code EndPoint} is connected, or {@code null}
|
||||
* if this {@code EndPoint} is not connected to a Socket address.
|
||||
*/
|
||||
default SocketAddress getRemoteSocketAddress()
|
||||
{
|
||||
return getRemoteAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this EndPoint is open
|
||||
*/
|
||||
|
|
|
@ -15,8 +15,8 @@ package org.eclipse.jetty.io;
|
|||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.CancelledKeyException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
|
@ -159,15 +159,29 @@ public class SocketChannelEndPoint extends AbstractEndPoint implements ManagedSe
|
|||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
public SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
return (InetSocketAddress)_channel.socket().getLocalSocketAddress();
|
||||
try
|
||||
{
|
||||
return _channel.getLocalAddress();
|
||||
}
|
||||
catch (IOException x)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
public SocketAddress getRemoteSocketAddress()
|
||||
{
|
||||
return (InetSocketAddress)_channel.socket().getRemoteSocketAddress();
|
||||
try
|
||||
{
|
||||
return _channel.getRemoteAddress();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -185,9 +199,10 @@ public class SocketChannelEndPoint extends AbstractEndPoint implements ManagedSe
|
|||
if (!socket.isOutputShutdown())
|
||||
socket.shutdownOutput();
|
||||
}
|
||||
catch (IOException e)
|
||||
catch (Throwable x)
|
||||
{
|
||||
LOG.debug("Could not shutdown output for {}", _channel, e);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Could not shutdown output for {}", _channel, x);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.jetty.io.ssl;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
|
@ -100,13 +101,21 @@ public class SslClientConnectionFactory implements ClientConnectionFactory
|
|||
@Override
|
||||
public org.eclipse.jetty.io.Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException
|
||||
{
|
||||
InetSocketAddress address = (InetSocketAddress)context.get(ClientConnector.REMOTE_SOCKET_ADDRESS_CONTEXT_KEY);
|
||||
String host = address.getHostString();
|
||||
int port = address.getPort();
|
||||
|
||||
SSLEngine engine = sslContextFactory instanceof SslEngineFactory
|
||||
SSLEngine engine;
|
||||
SocketAddress remote = (SocketAddress)context.get(ClientConnector.REMOTE_SOCKET_ADDRESS_CONTEXT_KEY);
|
||||
if (remote instanceof InetSocketAddress)
|
||||
{
|
||||
InetSocketAddress inetRemote = (InetSocketAddress)remote;
|
||||
String host = inetRemote.getHostString();
|
||||
int port = inetRemote.getPort();
|
||||
engine = sslContextFactory instanceof SslEngineFactory
|
||||
? ((SslEngineFactory)sslContextFactory).newSslEngine(host, port, context)
|
||||
: sslContextFactory.newSSLEngine(host, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
engine = sslContextFactory.newSSLEngine();
|
||||
}
|
||||
engine.setUseClientMode(true);
|
||||
context.put(SSL_ENGINE_CONTEXT_KEY, engine);
|
||||
|
||||
|
@ -176,8 +185,10 @@ public class SslClientConnectionFactory implements ClientConnectionFactory
|
|||
HostnameVerifier verifier = sslContextFactory.getHostnameVerifier();
|
||||
if (verifier != null)
|
||||
{
|
||||
InetSocketAddress address = (InetSocketAddress)context.get(ClientConnector.REMOTE_SOCKET_ADDRESS_CONTEXT_KEY);
|
||||
String host = address.getHostString();
|
||||
SocketAddress address = (SocketAddress)context.get(ClientConnector.REMOTE_SOCKET_ADDRESS_CONTEXT_KEY);
|
||||
if (address instanceof InetSocketAddress)
|
||||
{
|
||||
String host = ((InetSocketAddress)address).getHostString();
|
||||
try
|
||||
{
|
||||
if (!verifier.verify(host, event.getSSLEngine().getSession()))
|
||||
|
@ -194,4 +205,5 @@ public class SslClientConnectionFactory implements ClientConnectionFactory
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
package org.eclipse.jetty.io.ssl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -503,15 +503,15 @@ public class SslConnection extends AbstractConnection implements Connection.Upgr
|
|||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
public SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
return getEndPoint().getLocalAddress();
|
||||
return getEndPoint().getLocalSocketAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
public SocketAddress getRemoteSocketAddress()
|
||||
{
|
||||
return getEndPoint().getRemoteAddress();
|
||||
return getEndPoint().getRemoteSocketAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -79,11 +79,11 @@ public abstract class ProxyConnection extends AbstractConnection
|
|||
@Override
|
||||
public String toConnectionString()
|
||||
{
|
||||
return String.format("%s@%x[l:%d<=>r:%d]",
|
||||
return String.format("%s@%x[l:%s<=>r:%s]",
|
||||
getClass().getSimpleName(),
|
||||
hashCode(),
|
||||
getEndPoint().getLocalAddress().getPort(),
|
||||
getEndPoint().getRemoteAddress().getPort());
|
||||
getEndPoint().getLocalSocketAddress(),
|
||||
getEndPoint().getRemoteSocketAddress());
|
||||
}
|
||||
|
||||
private class ProxyIteratingCallback extends IteratingCallback
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.eclipse.jetty.server;
|
|||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -955,13 +956,15 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
@SuppressWarnings("unused")
|
||||
private static void logLocalHost(StringBuilder b, Request request, Response response)
|
||||
{
|
||||
append(b, request.getHttpChannel().getEndPoint().getLocalAddress().getAddress().getHostAddress());
|
||||
InetSocketAddress local = request.getHttpChannel().getLocalAddress();
|
||||
append(b, local == null ? null : local.getAddress().getHostAddress());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void logRemoteHost(StringBuilder b, Request request, Response response)
|
||||
{
|
||||
append(b, request.getHttpChannel().getEndPoint().getRemoteAddress().getAddress().getHostAddress());
|
||||
InetSocketAddress remote = request.getHttpChannel().getRemoteAddress();
|
||||
append(b, remote == null ? null : remote.getAddress().getHostAddress());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -979,13 +982,15 @@ public class CustomRequestLog extends ContainerLifeCycle implements RequestLog
|
|||
@SuppressWarnings("unused")
|
||||
private static void logLocalPort(StringBuilder b, Request request, Response response)
|
||||
{
|
||||
b.append(request.getHttpChannel().getEndPoint().getLocalAddress().getPort());
|
||||
InetSocketAddress local = request.getHttpChannel().getLocalAddress();
|
||||
append(b, local == null ? null : String.valueOf(local.getPort()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void logRemotePort(StringBuilder b, Request request, Response response)
|
||||
{
|
||||
b.append(request.getHttpChannel().getEndPoint().getRemoteAddress().getPort());
|
||||
InetSocketAddress remote = request.getHttpChannel().getRemoteAddress();
|
||||
append(b, remote == null ? null : String.valueOf(remote.getPort()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.jetty.server;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventListener;
|
||||
|
@ -183,7 +184,7 @@ public abstract class HttpChannel implements Runnable, HttpOutput.Interceptor
|
|||
* {@link TransientListeners} as an {@link AbstractConnector}
|
||||
* provided listener</p>
|
||||
* <p>Transient listeners are removed after every request cycle</p>
|
||||
* @param listener
|
||||
* @param listener the listener to add
|
||||
* @return true if the listener was added.
|
||||
*/
|
||||
@Deprecated
|
||||
|
@ -313,12 +314,18 @@ public abstract class HttpChannel implements Runnable, HttpOutput.Interceptor
|
|||
|
||||
public InetSocketAddress getLocalAddress()
|
||||
{
|
||||
return _endPoint.getLocalAddress();
|
||||
SocketAddress local = _endPoint.getLocalSocketAddress();
|
||||
if (local instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)local;
|
||||
return null;
|
||||
}
|
||||
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
return _endPoint.getRemoteAddress();
|
||||
SocketAddress remote = _endPoint.getRemoteSocketAddress();
|
||||
if (remote instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)remote;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.net.Inet4Address;
|
|||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadPendingException;
|
||||
import java.nio.channels.WritePendingException;
|
||||
|
@ -335,21 +336,23 @@ public class ProxyConnectionFactory extends DetectorConnectionFactory
|
|||
String dstPort = _fields[5];
|
||||
// If UNKNOWN, we must ignore the information sent, so use the EndPoint's.
|
||||
boolean unknown = "UNKNOWN".equalsIgnoreCase(_fields[1]);
|
||||
EndPoint proxyEndPoint;
|
||||
if (unknown)
|
||||
{
|
||||
srcIP = getEndPoint().getRemoteAddress().getAddress().getHostAddress();
|
||||
srcPort = String.valueOf(getEndPoint().getRemoteAddress().getPort());
|
||||
dstIP = getEndPoint().getLocalAddress().getAddress().getHostAddress();
|
||||
dstPort = String.valueOf(getEndPoint().getLocalAddress().getPort());
|
||||
EndPoint endPoint = getEndPoint();
|
||||
proxyEndPoint = new ProxyEndPoint(endPoint, endPoint.getLocalSocketAddress(), endPoint.getRemoteSocketAddress());
|
||||
}
|
||||
else
|
||||
{
|
||||
SocketAddress remote = new InetSocketAddress(srcIP, Integer.parseInt(srcPort));
|
||||
SocketAddress local = new InetSocketAddress(dstIP, Integer.parseInt(dstPort));
|
||||
proxyEndPoint = new ProxyEndPoint(getEndPoint(), local, remote);
|
||||
}
|
||||
InetSocketAddress remote = new InetSocketAddress(srcIP, Integer.parseInt(srcPort));
|
||||
InetSocketAddress local = new InetSocketAddress(dstIP, Integer.parseInt(dstPort));
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Proxy v1 next protocol '{}' for {} r={} l={}", _next, getEndPoint(), remote, local);
|
||||
LOG.debug("Proxy v1 next protocol '{}' for {} -> {}", _next, getEndPoint(), proxyEndPoint);
|
||||
|
||||
EndPoint endPoint = new ProxyEndPoint(getEndPoint(), remote, local);
|
||||
upgradeToConnectionFactory(_next, _connector, endPoint);
|
||||
upgradeToConnectionFactory(_next, _connector, proxyEndPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -565,49 +568,49 @@ public class ProxyConnectionFactory extends DetectorConnectionFactory
|
|||
LOG.debug("Proxy v2 body {} from {} for {}", _next, BufferUtil.toHexSummary(_buffer), this);
|
||||
|
||||
// Do we need to wrap the endpoint?
|
||||
ProxyEndPoint proxyEndPoint;
|
||||
EndPoint endPoint = getEndPoint();
|
||||
if (!_local)
|
||||
if (_local)
|
||||
{
|
||||
InetAddress src;
|
||||
InetAddress dst;
|
||||
int sp;
|
||||
int dp;
|
||||
|
||||
_buffer.position(_buffer.position() + _length);
|
||||
proxyEndPoint = new ProxyEndPoint(endPoint, endPoint.getLocalSocketAddress(), endPoint.getRemoteSocketAddress());
|
||||
}
|
||||
else
|
||||
{
|
||||
SocketAddress local;
|
||||
SocketAddress remote;
|
||||
switch (_family)
|
||||
{
|
||||
case INET:
|
||||
{
|
||||
byte[] addr = new byte[4];
|
||||
_buffer.get(addr);
|
||||
src = Inet4Address.getByAddress(addr);
|
||||
InetAddress src = Inet4Address.getByAddress(addr);
|
||||
_buffer.get(addr);
|
||||
dst = Inet4Address.getByAddress(addr);
|
||||
sp = _buffer.getChar();
|
||||
dp = _buffer.getChar();
|
||||
InetAddress dst = Inet4Address.getByAddress(addr);
|
||||
int sp = _buffer.getChar();
|
||||
int dp = _buffer.getChar();
|
||||
local = new InetSocketAddress(dst, dp);
|
||||
remote = new InetSocketAddress(src, sp);
|
||||
break;
|
||||
}
|
||||
|
||||
case INET6:
|
||||
{
|
||||
byte[] addr = new byte[16];
|
||||
_buffer.get(addr);
|
||||
src = Inet6Address.getByAddress(addr);
|
||||
InetAddress src = Inet6Address.getByAddress(addr);
|
||||
_buffer.get(addr);
|
||||
dst = Inet6Address.getByAddress(addr);
|
||||
sp = _buffer.getChar();
|
||||
dp = _buffer.getChar();
|
||||
InetAddress dst = Inet6Address.getByAddress(addr);
|
||||
int sp = _buffer.getChar();
|
||||
int dp = _buffer.getChar();
|
||||
local = new InetSocketAddress(dst, dp);
|
||||
remote = new InetSocketAddress(src, sp);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
// Extract Addresses
|
||||
InetSocketAddress remote = new InetSocketAddress(src, sp);
|
||||
InetSocketAddress local = new InetSocketAddress(dst, dp);
|
||||
ProxyEndPoint proxyEndPoint = new ProxyEndPoint(endPoint, remote, local);
|
||||
endPoint = proxyEndPoint;
|
||||
proxyEndPoint = new ProxyEndPoint(endPoint, local, remote);
|
||||
|
||||
// Any additional info?
|
||||
while (_buffer.remaining() > nonProxyRemaining)
|
||||
|
@ -648,16 +651,12 @@ public class ProxyConnectionFactory extends DetectorConnectionFactory
|
|||
}
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Proxy v2 {} {}", getEndPoint(), proxyEndPoint.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
_buffer.position(_buffer.position() + _length);
|
||||
LOG.debug("Proxy v2 {} {}", endPoint, proxyEndPoint);
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Proxy v2 parsing dynamic packet part is now done, upgrading to {}", _nextProtocol);
|
||||
upgradeToConnectionFactory(_next, _connector, endPoint);
|
||||
upgradeToConnectionFactory(_next, _connector, proxyEndPoint);
|
||||
}
|
||||
|
||||
private void parseHeader() throws IOException
|
||||
|
@ -751,15 +750,21 @@ public class ProxyConnectionFactory extends DetectorConnectionFactory
|
|||
private static final int PP2_SUBTYPE_SSL_VERSION = 0x21;
|
||||
|
||||
private final EndPoint _endPoint;
|
||||
private final InetSocketAddress _remote;
|
||||
private final InetSocketAddress _local;
|
||||
private final SocketAddress _local;
|
||||
private final SocketAddress _remote;
|
||||
private Map<Integer, byte[]> _tlvs;
|
||||
|
||||
@Deprecated
|
||||
public ProxyEndPoint(EndPoint endPoint, InetSocketAddress remote, InetSocketAddress local)
|
||||
{
|
||||
this(endPoint, (SocketAddress)local, remote);
|
||||
}
|
||||
|
||||
public ProxyEndPoint(EndPoint endPoint, SocketAddress local, SocketAddress remote)
|
||||
{
|
||||
_endPoint = endPoint;
|
||||
_remote = remote;
|
||||
_local = local;
|
||||
_remote = remote;
|
||||
}
|
||||
|
||||
public EndPoint unwrap()
|
||||
|
@ -847,12 +852,30 @@ public class ProxyConnectionFactory extends DetectorConnectionFactory
|
|||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
{
|
||||
SocketAddress local = getLocalSocketAddress();
|
||||
if (local instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)local;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
return _local;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
SocketAddress remote = getRemoteSocketAddress();
|
||||
if (remote instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)remote;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteSocketAddress()
|
||||
{
|
||||
return _remote;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.jetty.server;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.servlet.ServletRequest;
|
||||
|
@ -54,7 +55,7 @@ public class ProxyCustomizer implements HttpConfiguration.Customizer
|
|||
if (endPoint instanceof ProxyConnectionFactory.ProxyEndPoint)
|
||||
{
|
||||
EndPoint underlyingEndpoint = ((ProxyConnectionFactory.ProxyEndPoint)endPoint).unwrap();
|
||||
request.setAttributes(new ProxyAttributes(underlyingEndpoint.getRemoteAddress(), underlyingEndpoint.getLocalAddress(), request.getAttributes()));
|
||||
request.setAttributes(new ProxyAttributes(underlyingEndpoint.getLocalSocketAddress(), underlyingEndpoint.getRemoteSocketAddress(), request.getAttributes()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,13 +66,15 @@ public class ProxyCustomizer implements HttpConfiguration.Customizer
|
|||
private final int _remotePort;
|
||||
private final int _localPort;
|
||||
|
||||
private ProxyAttributes(InetSocketAddress remoteAddress, InetSocketAddress localAddress, Attributes attributes)
|
||||
private ProxyAttributes(SocketAddress local, SocketAddress remote, Attributes attributes)
|
||||
{
|
||||
super(attributes);
|
||||
_remoteAddress = remoteAddress.getAddress().getHostAddress();
|
||||
_localAddress = localAddress.getAddress().getHostAddress();
|
||||
_remotePort = remoteAddress.getPort();
|
||||
_localPort = localAddress.getPort();
|
||||
InetSocketAddress inetLocal = local instanceof InetSocketAddress ? (InetSocketAddress)local : null;
|
||||
InetSocketAddress inetRemote = remote instanceof InetSocketAddress ? (InetSocketAddress)remote : null;
|
||||
_localAddress = inetLocal == null ? null : inetLocal.getAddress().getHostAddress();
|
||||
_remoteAddress = inetRemote == null ? null : inetRemote.getAddress().getHostAddress();
|
||||
_localPort = inetLocal == null ? 0 : inetLocal.getPort();
|
||||
_remotePort = inetRemote == null ? 0 : inetRemote.getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
import javax.net.ssl.SSLSession;
|
||||
|
@ -142,7 +144,10 @@ public class SslConnectionFactory extends AbstractConnectionFactory implements C
|
|||
@Override
|
||||
public Connection newConnection(Connector connector, EndPoint endPoint)
|
||||
{
|
||||
SSLEngine engine = _sslContextFactory.newSSLEngine(endPoint.getRemoteAddress());
|
||||
SocketAddress remoteSocketAddress = endPoint.getRemoteSocketAddress();
|
||||
SSLEngine engine = remoteSocketAddress instanceof InetSocketAddress
|
||||
? _sslContextFactory.newSSLEngine((InetSocketAddress)remoteSocketAddress)
|
||||
: _sslContextFactory.newSSLEngine();
|
||||
engine.setUseClientMode(false);
|
||||
|
||||
SslConnection sslConnection = newSslConnection(connector, endPoint, engine);
|
||||
|
|
|
@ -22,15 +22,12 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http.pathmap.PathSpec;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.server.HttpChannel;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.util.IncludeExcludeSet;
|
||||
import org.eclipse.jetty.util.InetAddressPattern;
|
||||
import org.eclipse.jetty.util.InetAddressSet;
|
||||
import org.eclipse.jetty.util.component.DumpableCollection;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.eclipse.jetty.server.handler.InetAccessSet.AccessTuple;
|
||||
import static org.eclipse.jetty.server.handler.InetAccessSet.PatternTuple;
|
||||
|
@ -46,8 +43,6 @@ import static org.eclipse.jetty.server.handler.InetAccessSet.PatternTuple;
|
|||
*/
|
||||
public class InetAccessHandler extends HandlerWrapper
|
||||
{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(InetAccessHandler.class);
|
||||
|
||||
private final IncludeExcludeSet<PatternTuple, AccessTuple> _set = new IncludeExcludeSet<>(InetAccessSet.class);
|
||||
|
||||
/**
|
||||
|
@ -221,10 +216,7 @@ public class InetAccessHandler extends HandlerWrapper
|
|||
HttpChannel channel = baseRequest.getHttpChannel();
|
||||
if (channel != null)
|
||||
{
|
||||
EndPoint endp = channel.getEndPoint();
|
||||
if (endp != null)
|
||||
{
|
||||
InetSocketAddress address = endp.getRemoteAddress();
|
||||
InetSocketAddress address = channel.getRemoteAddress();
|
||||
if (address != null && !isAllowed(address.getAddress(), baseRequest, request))
|
||||
{
|
||||
response.sendError(HttpStatus.FORBIDDEN_403);
|
||||
|
@ -232,7 +224,6 @@ public class InetAccessHandler extends HandlerWrapper
|
|||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getHandler().handle(target, baseRequest, request, response);
|
||||
}
|
||||
|
|
|
@ -17,12 +17,10 @@ import java.io.IOException;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -49,8 +47,8 @@ import org.eclipse.jetty.http.HttpURI;
|
|||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.http.MetaData;
|
||||
import org.eclipse.jetty.http.MimeTypes;
|
||||
import org.eclipse.jetty.io.AbstractEndPoint;
|
||||
import org.eclipse.jetty.io.ByteArrayEndPoint;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ErrorHandler;
|
||||
|
@ -90,25 +88,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
// @checkstyle-disable-check : AvoidEscapedUnicodeCharactersCheck
|
||||
public class ResponseTest
|
||||
{
|
||||
static final InetSocketAddress LOCALADDRESS;
|
||||
|
||||
static
|
||||
{
|
||||
InetAddress ip = null;
|
||||
try
|
||||
{
|
||||
ip = Inet4Address.getByName("127.0.0.42");
|
||||
}
|
||||
catch (UnknownHostException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
LOCALADDRESS = new InetSocketAddress(ip, 8888);
|
||||
}
|
||||
}
|
||||
|
||||
private Server _server;
|
||||
private HttpChannel _channel;
|
||||
private ByteBuffer _content = BufferUtil.allocate(16 * 1024);
|
||||
|
@ -126,15 +105,16 @@ public class ResponseTest
|
|||
_server.setHandler(new DumpHandler());
|
||||
_server.start();
|
||||
|
||||
AbstractEndPoint endp = new ByteArrayEndPoint(scheduler, 5000)
|
||||
SocketAddress local = InetSocketAddress.createUnresolved("myhost", 8888);
|
||||
EndPoint endPoint = new ByteArrayEndPoint(scheduler, 5000)
|
||||
{
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
public SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
return LOCALADDRESS;
|
||||
return local;
|
||||
}
|
||||
};
|
||||
_channel = new HttpChannel(connector, new HttpConfiguration(), endp, new HttpTransport()
|
||||
_channel = new HttpChannel(connector, new HttpConfiguration(), endPoint, new HttpTransport()
|
||||
{
|
||||
private Throwable _channelError;
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
package org.eclipse.jetty.unixsocket.common;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.SelectionKey;
|
||||
|
||||
import jnr.unixsocket.UnixSocketChannel;
|
||||
|
@ -39,18 +38,6 @@ public class UnixSocketEndPoint extends SocketChannelEndPoint
|
|||
return (UnixSocketChannel)super.getChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doShutdownOutput()
|
||||
{
|
||||
|
|
|
@ -36,8 +36,8 @@ import org.slf4j.LoggerFactory;
|
|||
public interface SocketAddressResolver
|
||||
{
|
||||
/**
|
||||
* Resolves the given host and port, returning a {@link SocketAddress} through the given {@link Promise}
|
||||
* with the default timeout.
|
||||
* Resolves via DNS the given host and port, within the connect timeout,
|
||||
* returning a list of {@link InetSocketAddress} through the given {@link Promise}.
|
||||
*
|
||||
* @param host the host to resolve
|
||||
* @param port the port of the resulting socket address
|
||||
|
@ -46,7 +46,7 @@ public interface SocketAddressResolver
|
|||
public void resolve(String host, int port, Promise<List<InetSocketAddress>> promise);
|
||||
|
||||
/**
|
||||
* <p>Creates {@link SocketAddress} instances synchronously in the caller thread.</p>
|
||||
* <p>Creates {@link InetSocketAddress} instances synchronously in the caller thread.</p>
|
||||
*/
|
||||
@ManagedObject("The synchronous address resolver")
|
||||
public static class Sync implements SocketAddressResolver
|
||||
|
@ -77,7 +77,7 @@ public interface SocketAddressResolver
|
|||
}
|
||||
|
||||
/**
|
||||
* <p>Creates {@link SocketAddress} instances asynchronously in a different thread.</p>
|
||||
* <p>Creates {@link InetSocketAddress} instances asynchronously in a different thread.</p>
|
||||
* <p>{@link InetSocketAddress#InetSocketAddress(String, int)} attempts to perform a DNS
|
||||
* resolution of the host name, and this may block for several seconds.
|
||||
* This class creates the {@link InetSocketAddress} in a separate thread and provides the result
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.jetty.websocket.core.internal;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Objects;
|
||||
|
@ -142,14 +143,40 @@ public class WebSocketConnection extends AbstractConnection implements Connectio
|
|||
return parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the local InetSocketAddress
|
||||
* @deprecated use {@link #getLocalSocketAddress()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public InetSocketAddress getLocalAddress()
|
||||
{
|
||||
return getEndPoint().getLocalAddress();
|
||||
SocketAddress local = getLocalSocketAddress();
|
||||
if (local instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)local;
|
||||
return null;
|
||||
}
|
||||
|
||||
public SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
return getEndPoint().getLocalSocketAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the remote InetSocketAddress
|
||||
* @deprecated use {@link #getRemoteSocketAddress()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
return getEndPoint().getRemoteAddress();
|
||||
SocketAddress remote = getRemoteSocketAddress();
|
||||
if (remote instanceof InetSocketAddress)
|
||||
return (InetSocketAddress)remote;
|
||||
return null;
|
||||
}
|
||||
|
||||
public SocketAddress getRemoteSocketAddress()
|
||||
{
|
||||
return getEndPoint().getRemoteSocketAddress();
|
||||
}
|
||||
|
||||
public boolean isUseInputDirectByteBuffers()
|
||||
|
|
|
@ -175,12 +175,12 @@ public class WebSocketCoreSession implements IncomingFrames, CoreSession, Dumpab
|
|||
|
||||
public SocketAddress getLocalAddress()
|
||||
{
|
||||
return getConnection().getEndPoint().getLocalAddress();
|
||||
return getConnection().getEndPoint().getLocalSocketAddress();
|
||||
}
|
||||
|
||||
public SocketAddress getRemoteAddress()
|
||||
{
|
||||
return getConnection().getEndPoint().getRemoteAddress();
|
||||
return getConnection().getEndPoint().getRemoteSocketAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.jetty.websocket.core.internal;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadPendingException;
|
||||
import java.nio.channels.WritePendingException;
|
||||
|
@ -33,12 +34,24 @@ public class MockEndpoint implements EndPoint
|
|||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getLocalSocketAddress()
|
||||
{
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteSocketAddress()
|
||||
{
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue