List of usage examples for java.net InetSocketAddress getAddress
public final InetAddress getAddress()
From source file:com.all.networking.PeerNetworkingService.java
@Override public void sessionClosed(IoSession session) throws Exception { log.info("Session to " + session.getRemoteAddress() + " was closed."); InetSocketAddress remoteSocketAddress = (InetSocketAddress) session.getRemoteAddress(); String remoteAddress = remoteSocketAddress.getAddress().getHostAddress(); int remotePort = remoteSocketAddress.getPort(); IoSession removed = currentSessions.remove(createSessionKey(remoteAddress, remotePort)); if (removed != null) { log.info("Removing " + remoteAddress + " from current sessions."); }//from ww w .j av a 2 s. co m }
From source file:edu.umass.cs.reconfiguration.deprecated.ReconfigurableClientCreateTester.java
private InetSocketAddress getRandomRCReplica() { int index = (int) (this.getReconfigurators().size() * Math.random()); InetSocketAddress address = (InetSocketAddress) (this.getReconfigurators().toArray()[index]); return new InetSocketAddress(address.getAddress(), ActiveReplica.getClientFacingPort(address.getPort())); }
From source file:org.wso2.andes.server.cluster.HazelcastClusterAgent.java
/** * Gets address of all the members in the cluster. i.e address:port * * @return A list of address of the nodes in a cluster *///from w w w .j av a2s .co m public List<String> getAllClusterNodeAddresses() { List<String> addresses = new ArrayList<>(); if (AndesContext.getInstance().isClusteringEnabled()) { for (Member member : hazelcastInstance.getCluster().getMembers()) { InetSocketAddress socket = member.getSocketAddress(); addresses.add( getIdOfNode(member) + "," + socket.getAddress().getHostAddress() + "," + socket.getPort()); } } return addresses; }
From source file:com.amazonaws.http.conn.ssl.SdkTLSSocketFactory.java
@Override public Socket connectSocket(final Socket socket, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (log.isDebugEnabled()) log.debug("connecting to " + remoteAddress.getAddress() + ":" + remoteAddress.getPort()); try {//w ww .j ava 2s . c o m verifyMasterSecret(super.connectSocket(socket, remoteAddress, localAddress, params)); } catch (final SSLException sslEx) { // clear any related sessions from our cache if (log.isDebugEnabled()) { log.debug("connection failed due to SSL error, clearing TLS session cache", sslEx); } clearSessionCache(sslContext.getClientSessionContext(), remoteAddress); throw sslEx; } if (socket instanceof SSLSocket) return new SdkSSLSocket((SSLSocket) socket); return new SdkSocket(socket); }
From source file:org.jolokia.jvmagent.JolokiaHttpHandler.java
@SuppressWarnings({ "PMD.AvoidCatchingThrowable", "PMD.AvoidInstanceofChecksInCatchClause" }) public void doHandle(HttpExchange pExchange) throws IOException { if (requestHandler == null) { throw new IllegalStateException("Handler not yet started"); }//from w w w . ja v a 2 s .c o m JSONAware json = null; URI uri = pExchange.getRequestURI(); ParsedUri parsedUri = new ParsedUri(uri, context); try { // Check access policy InetSocketAddress address = pExchange.getRemoteAddress(); requestHandler.checkAccess(address.getHostName(), address.getAddress().getHostAddress(), extractOriginOrReferer(pExchange)); String method = pExchange.getRequestMethod(); // Dispatch for the proper HTTP request method if ("GET".equalsIgnoreCase(method)) { setHeaders(pExchange); json = executeGetRequest(parsedUri); } else if ("POST".equalsIgnoreCase(method)) { setHeaders(pExchange); json = executePostRequest(pExchange, parsedUri); } else if ("OPTIONS".equalsIgnoreCase(method)) { performCorsPreflightCheck(pExchange); } else { throw new IllegalArgumentException("HTTP Method " + method + " is not supported."); } } catch (Throwable exp) { json = requestHandler.handleThrowable( exp instanceof RuntimeMBeanException ? ((RuntimeMBeanException) exp).getTargetException() : exp); } finally { sendResponse(pExchange, parsedUri, json); } }
From source file:com.devoteam.srit.xmlloader.http.bio.BIOSocketServerListener.java
public void run() { try {//w w w . java2s . c om while (true) { // // Set up HTTP connection // GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "SocketServerListener secure=", secure, "waiting for a connection on socket"); Socket socket = serverSocket.accept(); GlobalLogger.instance().getApplicationLogger().debug(TextEvent.Topic.PROTOCOL, "SocketServerListener secure=", secure, "got a connection"); DefaultHttpServerConnection serverConnection = new DefaultHttpServerConnection(); HttpParams params = new BasicHttpParams(); serverConnection.bind(socket, params); InetSocketAddress remoteInetSocketAddress = (InetSocketAddress) socket.getRemoteSocketAddress(); InetSocketAddress localInetSocketAddress = (InetSocketAddress) socket.getLocalSocketAddress(); String connectionName = "HTTPServerConnection" + Stack.nextTransactionId(); String remoteHost = remoteInetSocketAddress.getAddress().getHostAddress(); String remotePort = Integer.toString(remoteInetSocketAddress.getPort()); String localHost = localInetSocketAddress.getAddress().getHostAddress(); String localPort = Integer.toString(localInetSocketAddress.getPort()); BIOChannelHttp connHttp = new BIOChannelHttp(connectionName, localHost, localPort, remoteHost, remotePort, StackFactory.PROTOCOL_HTTP, secure); // // Start Server thread // BIOSocketServerHttp socketServerHttp = new BIOSocketServerHttp(serverConnection, connHttp); connHttp.setSocketServerHttp(socketServerHttp); StackFactory.getStack(StackFactory.PROTOCOL_HTTP).openChannel(connHttp); } } catch (Exception e) { GlobalLogger.instance().getApplicationLogger().error(TextEvent.Topic.PROTOCOL, e, "Exception in SocketServerListener secure=" + secure); } GlobalLogger.instance().getApplicationLogger().warn(TextEvent.Topic.PROTOCOL, "SocketServerListener secure=", secure, "stopped"); }
From source file:org.limewire.mojito.routing.impl.LocalContact.java
/** * Sets the local Node's Contact (external) Port. *///ww w . j a v a2 s. c o m public synchronized void setExternalPort(int port) { InetSocketAddress addr = (InetSocketAddress) getContactAddress(); setContactAddress(new InetSocketAddress(addr.getAddress(), port)); }
From source file:org.jolokia.jvmagent.handler.JolokiaHttpHandlerTest.java
@Test public void restrictorWithNoReverseDnsLookup() throws URISyntaxException, IOException, ParseException { Configuration config = getConfig(ConfigKey.RESTRICTOR_CLASS, TestReverseDnsLookupRestrictor.class.getName(), ConfigKey.ALLOW_DNS_REVERSE_LOOKUP, "false"); InetSocketAddress address = new InetSocketAddress(8080); TestReverseDnsLookupRestrictor.expectedRemoteHostsToCheck = new String[] { address.getAddress().getHostAddress() }; JSONObject resp = simpleMemoryGetReadRequest(config); assertFalse(resp.containsKey("error")); }
From source file:org.commoncrawl.io.internal.NIOClientTCPSocket.java
public NIOClientTCPSocket(InetSocketAddress localAddress, NIOClientSocketListener socketListener) throws IOException { _socketType = SocketType.Outgoing;//from www. j ava2 s . com _channel = SocketChannel.open(); if (localAddress != null) { InetSocketAddress modifiedLocalAddress = new InetSocketAddress(localAddress.getAddress(), 0); // System.out.println("Binding To Local Address:" + modifiedLocalAddress.getAddress()); // LOG.info(this + "Binding To Local Address:" + modifiedLocalAddress.getAddress()); _channel.socket().bind(modifiedLocalAddress); } _localAddress = (InetSocketAddress) _channel.socket().getLocalSocketAddress(); setClientSocketOptions(_channel); _listener = socketListener; }