List of usage examples for java.net InetSocketAddress getAddress
public final InetAddress getAddress()
From source file:org.springframework.cloud.gateway.handler.predicate.RemoteAddrRoutePredicate.java
@Override public Predicate<ServerWebExchange> apply(String... args) { validate(1, args);/*from w w w.j a v a2s . co m*/ List<SubnetUtils> sources = new ArrayList<>(); if (args != null) { for (String arg : args) { addSource(sources, arg); } } return exchange -> { ReactorServerHttpRequest request = (ReactorServerHttpRequest) exchange.getRequest(); InetSocketAddress remoteAddress = request.getReactorRequest().remoteAddress(); String hostAddress = remoteAddress.getAddress().getHostAddress(); String host = exchange.getRequest().getURI().getHost(); if (!hostAddress.equals(host)) { log.warn("Remote addresses didn't match " + hostAddress + " != " + host); } for (SubnetUtils source : sources) { if (source.getInfo().isInRange(hostAddress)) { return true; } } return false; }; }
From source file:io.netlibs.bgp.config.nodes.ClientPortConfigurationDecorator.java
@Override public InetSocketAddress getRemoteAddress() { InetSocketAddress sockAddr = decorated.getRemoteAddress(); if (sockAddr.getPort() == 0) sockAddr = new InetSocketAddress(sockAddr.getAddress(), getDefaultPort()); return sockAddr; }
From source file:io.netlibs.bgp.config.nodes.ServerPortConfigurationDecorator.java
@Override public InetSocketAddress getListenAddress() { InetSocketAddress sockAddr = decorated.getListenAddress(); if (sockAddr.getPort() == 0) sockAddr = new InetSocketAddress(sockAddr.getAddress(), getDefaultPort()); return sockAddr; }
From source file:com.chiralBehaviors.slp.hive.hardtack.configuration.PushConfiguration.java
@Override public Engine construct() throws IOException { NetworkInterface intf = getNetworkInterface(); InetAddress address = Utils.getAddress(intf, ipv4); DatagramSocket p2pSocket = new DatagramSocket(new InetSocketAddress(address, Utils.allocatePort(address))); int i = 0;/* w w w .j av a2 s . co m*/ for (InetSocketAddress aggregator : aggregators) { log.info(String.format("Adding aggregator: %s", aggregator)); if (aggregator.getAddress().isAnyLocalAddress()) { aggregators.set(i++, new InetSocketAddress(address, aggregator.getPort())); } } return new PushEngine(p2pSocket, getMac(), Generators.timeBasedGenerator(), aggregators, heartbeatPeriod, heartbeatUnit, Executors.newSingleThreadScheduledExecutor()); }
From source file:com.phei.netty.protocol.netty.server.LoginAuthRespHandler.java
/** * Calls {@link ChannelHandlerContext#fireChannelRead(Object)} to forward to * the next {@link ChannelHandler} in the {@link ChannelPipeline}. * <p>//w w w . jav a2 s .c om * Sub-classes may override this method to change behavior. */ @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { NettyMessage message = (NettyMessage) msg; // ????? if (message.getHeader() != null && message.getHeader().getType() == MessageType.LOGIN_REQ.value()) { String nodeIndex = ctx.channel().remoteAddress().toString(); NettyMessage loginResp = null; // ??? if (nodeCheck.containsKey(nodeIndex)) { loginResp = buildResponse((byte) -1); } else { InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress(); String ip = address.getAddress().getHostAddress(); boolean isOK = false; for (String WIP : whitekList) { if (WIP.equals(ip)) { isOK = true; break; } } loginResp = isOK ? buildResponse((byte) 0) : buildResponse((byte) -1); if (isOK) nodeCheck.put(nodeIndex, true); } LOG.info("The login response is : " + loginResp + " body [" + loginResp.getBody() + "]"); ctx.writeAndFlush(loginResp); } else { ctx.fireChannelRead(msg); } }
From source file:com.spartasystems.holdmail.smtp.SMTPHandler.java
public SMTPHandler(MessageContext ctx) { InetSocketAddress hostAddr = (InetSocketAddress) ctx.getRemoteAddress(); this.senderHost = hostAddr.getAddress().getHostAddress(); }
From source file:org.shelloid.netverif.NetVerifSocketImpl.java
public void setRemoteAddr(InetSocketAddress addr) { this.address = addr.getAddress(); this.port = addr.getPort(); }
From source file:org.apache.tajo.master.cluster.WorkerListener.java
public WorkerListener(final MasterContext context) throws Exception { super(WorkerListener.class.getName()); this.context = context; String confMasterAddr = context.getConf().getVar(ConfVars.TASKRUNNER_LISTENER_ADDRESS); InetSocketAddress initIsa = NetUtils.createSocketAddr(confMasterAddr); if (initIsa.getAddress() == null) { throw new IllegalArgumentException("Failed resolve of " + initIsa); }// www . j a v a2 s . co m try { this.rpcServer = new ProtoAsyncRpcServer(MasterWorkerProtocol.class, this, initIsa); } catch (Exception e) { LOG.error(e); } this.rpcServer.start(); this.bindAddr = rpcServer.getBindAddress(); this.addr = bindAddr.getHostName() + ":" + bindAddr.getPort(); // Setup RPC server // Get the master address LOG.info(WorkerListener.class.getSimpleName() + " is bind to " + addr); context.getConf().setVar(TajoConf.ConfVars.TASKRUNNER_LISTENER_ADDRESS, addr); }
From source file:org.eclipse.mylyn.commons.net.WebUtil.java
private static void configureHttpClientProxy(HttpClient client, HostConfiguration hostConfiguration, AbstractWebLocation location) {/*from w w w. j av a 2s. com*/ String host = WebUtil.getHost(location.getUrl()); Proxy proxy; if (WebUtil.isRepositoryHttps(location.getUrl())) { proxy = location.getProxyForHost(host, IProxyData.HTTPS_PROXY_TYPE); } else { proxy = location.getProxyForHost(host, IProxyData.HTTP_PROXY_TYPE); } if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) { InetSocketAddress address = (InetSocketAddress) proxy.address(); hostConfiguration.setProxy(address.getHostName(), address.getPort()); if (proxy instanceof AuthenticatedProxy) { AuthenticatedProxy authProxy = (AuthenticatedProxy) proxy; Credentials credentials = getCredentials(authProxy.getUserName(), authProxy.getPassword(), address.getAddress()); AuthScope proxyAuthScope = new AuthScope(address.getHostName(), address.getPort(), AuthScope.ANY_REALM); client.getState().setProxyCredentials(proxyAuthScope, credentials); } } else { hostConfiguration.setProxyHost(null); } }
From source file:be.vlaanderen.sesam.monitor.internal.ClientConnectionServiceImpl.java
public ChannelFuture createClientChannel(SimpleChannelUpstreamHandler handler, InetSocketAddress addr, long readTimeoutMillis) { log.debug("Setting up client connection to: {} timeout: {} millis.", addr.getAddress().toString(), readTimeoutMillis);/*from w w w .j a v a 2 s. co m*/ log.debug("building bootstrap"); ClientBootstrap cb = new ClientBootstrap(FACTORY); // cb.setOption("tcpNoDelay", true); cb.getPipeline().addLast("codec", new HttpClientCodec()); cb.getPipeline().addLast("aggregator", new HttpChunkAggregator(MAX_RESPONSE_SIZE)); cb.getPipeline().addLast("inflater", new HttpContentDecompressor()); // not used atm. // cb.getPipeline().addLast("chunkedWriter", new ChunkedWriteHandler()); cb.getPipeline().addLast("timeout", new ReadTimeoutHandler(timer, readTimeoutMillis, TimeUnit.MILLISECONDS)); cb.getPipeline().addLast("handler", handler); log.debug("connecting"); return cb.connect(addr); }