use of java.net.SocketAddress in project databus by linkedin.
the class HttpRequestLoggingHandler method channelConnected.
@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
SocketAddress remoteAddress = ctx.getChannel().getRemoteAddress();
if (remoteAddress instanceof InetSocketAddress) {
InetSocketAddress inetAddress = (InetSocketAddress) remoteAddress;
_peerIp = inetAddress.getAddress().getHostAddress();
} else {
_peerIp = remoteAddress.toString();
}
_peerId = _peerIp;
_connStartNano = System.nanoTime();
_connBytes = 0;
logConnectionStart();
super.channelConnected(ctx, e);
}
use of java.net.SocketAddress in project hazelcast by hazelcast.
the class TcpIpConnection method toString.
@Override
public String toString() {
Socket socket = socketChannel.socket();
SocketAddress localSocketAddress = socket != null ? socket.getLocalSocketAddress() : null;
SocketAddress remoteSocketAddress = socket != null ? socket.getRemoteSocketAddress() : null;
return "Connection[id=" + connectionId + ", " + localSocketAddress + "->" + remoteSocketAddress + ", endpoint=" + endPoint + ", alive=" + alive + ", type=" + type + "]";
}
use of java.net.SocketAddress in project hazelcast by hazelcast.
the class InitConnectionTask method bindSocket.
private void bindSocket(SocketChannel socketChannel) throws IOException {
InetAddress inetAddress = getInetAddress();
Socket socket = socketChannel.socket();
if (connectionManager.useAnyOutboundPort()) {
SocketAddress socketAddress = new InetSocketAddress(inetAddress, 0);
socket.bind(socketAddress);
} else {
IOException ex = null;
int retryCount = connectionManager.getOutboundPortCount() * 2;
for (int i = 0; i < retryCount; i++) {
int port = connectionManager.acquireOutboundPort();
SocketAddress socketAddress = new InetSocketAddress(inetAddress, port);
try {
socket.bind(socketAddress);
return;
} catch (IOException e) {
ex = e;
logger.finest("Could not bind port[ " + port + "]: " + e.getMessage());
}
}
throw ex;
}
}
use of java.net.SocketAddress in project gitblit by gitblit.
the class SshServerSessionFactory method createSession.
@Override
protected AbstractSession createSession(final IoSession io) throws Exception {
log.info("creating ssh session from {}", io.getRemoteAddress());
if (io instanceof MinaSession) {
if (((MinaSession) io).getSession().getConfig() instanceof SocketSessionConfig) {
((SocketSessionConfig) ((MinaSession) io).getSession().getConfig()).setKeepAlive(true);
}
}
final SshServerSession session = (SshServerSession) super.createSession(io);
SocketAddress peer = io.getRemoteAddress();
SshDaemonClient client = new SshDaemonClient(peer);
session.setAttribute(SshDaemonClient.KEY, client);
// TODO(davido): Log a session close without authentication as a
// failure.
session.addCloseSessionListener(new SshFutureListener<CloseFuture>() {
@Override
public void operationComplete(CloseFuture future) {
log.info("closed ssh session from {}", io.getRemoteAddress());
}
});
return session;
}
use of java.net.SocketAddress in project zaproxy by zaproxy.
the class RelaxedX509TrustManager method createSocket.
/**
* Attempts to get a new socket connection to the given host within the
* given time limit.
*
* @param host
* the host name/IP
* @param port
* the port on the host
* @param localAddress
* the local host name/IP to bind the socket to
* @param localPort
* the port on the local machine
* @param params
* {@link HttpConnectionParams Http connection parameters}
*
* @return Socket a new socket
*
* @throws IOException
* if an I/O error occurs while creating the socket
* @throws UnknownHostException
* if the IP address of the host cannot be determined
* @throws ConnectTimeoutException
*/
@Override
public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort, final HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null");
}
int timeout = params.getConnectionTimeout();
if (timeout == 0) {
InetAddress hostAddress = getCachedMisconfiguredHost(host, port);
if (hostAddress != null) {
return clientSSLSockFactory.createSocket(hostAddress, port, localAddress, localPort);
}
try {
SSLSocket sslSocket = (SSLSocket) clientSSLSockFactory.createSocket(host, port, localAddress, localPort);
sslSocket.startHandshake();
return sslSocket;
} catch (SSLException e) {
if (!e.getMessage().contains(CONTENTS_UNRECOGNIZED_NAME_EXCEPTION)) {
throw e;
}
hostAddress = InetAddress.getByName(host);
cacheMisconfiguredHost(host, port, hostAddress);
return clientSSLSockFactory.createSocket(hostAddress, port, localAddress, localPort);
}
}
Socket socket = clientSSLSockFactory.createSocket();
SocketAddress localAddr = new InetSocketAddress(localAddress, localPort);
socket.bind(localAddr);
SocketAddress remoteAddr = new InetSocketAddress(host, port);
socket.connect(remoteAddr, timeout);
return socket;
}
Aggregations