List of usage examples for java.net InetSocketAddress getHostName
public final String getHostName()
From source file:github.popeen.dsub.service.ssl.SSLSocketFactory.java
/** * @since 4.1// w ww . j a v a2s. com */ public Socket connectSocket(final Socket sock, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (remoteAddress == null) { throw new IllegalArgumentException("Remote address may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } SSLSocket sslsock = (SSLSocket) (sock != null ? sock : createSocket()); if (localAddress != null) { // sslsock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params)); sslsock.bind(localAddress); } setHostName(sslsock, remoteAddress.getHostName()); int connTimeout = HttpConnectionParams.getConnectionTimeout(params); int soTimeout = HttpConnectionParams.getSoTimeout(params); try { sslsock.connect(remoteAddress, connTimeout); } catch (SocketTimeoutException ex) { throw new ConnectTimeoutException( "Connect to " + remoteAddress.getHostName() + "/" + remoteAddress.getAddress() + " timed out"); } sslsock.setSoTimeout(soTimeout); if (this.hostnameVerifier != null) { try { this.hostnameVerifier.verify(remoteAddress.getHostName(), sslsock); // verifyHostName() didn't blowup - good! } catch (IOException iox) { // close the socket before re-throwing the exception try { sslsock.close(); } catch (Exception x) { /*ignore*/ } throw iox; } } return sslsock; }
From source file:org.apache.hadoop.ha.SshFenceByTcpPort.java
private boolean doFence(Session session, InetSocketAddress serviceAddr) throws JSchException { int port = serviceAddr.getPort(); try {// w w w . ja v a2 s .c o m LOG.info("Looking for process running on port " + port); int rc = execCommand(session, "PATH=$PATH:/sbin:/usr/sbin fuser -v -k -n tcp " + port); if (rc == 0) { LOG.info("Successfully killed process that was " + "listening on port " + port); // exit code 0 indicates the process was successfully killed. return true; } else if (rc == 1) { // exit code 1 indicates either that the process was not running // or that fuser didn't have root privileges in order to find it // (eg running as a different user) LOG.info("Indeterminate response from trying to kill service. " + "Verifying whether it is running using nc..."); rc = execCommand(session, "nc -z " + serviceAddr.getHostName() + " " + serviceAddr.getPort()); if (rc == 0) { // the service is still listening - we are unable to fence LOG.warn("Unable to fence - it is running but we cannot kill it"); return false; } else { LOG.info("Verified that the service is down."); return true; } } else { // other } LOG.info("rc: " + rc); return rc == 0; } catch (InterruptedException e) { LOG.warn("Interrupted while trying to fence via ssh", e); return false; } catch (IOException e) { LOG.warn("Unknown failure while trying to fence via ssh", e); return false; } }
From source file:org.apache.hama.http.HttpServer.java
/** * Configure an ssl listener on the server. * //w ww .j ava 2s.co m * @param addr address to listen on * @param sslConf conf to retrieve ssl options * @param needClientAuth whether client authentication is required */ public void addSslListener(InetSocketAddress addr, Configuration sslConf, boolean needClientAuth) throws IOException { if (webServer.isStarted()) { throw new IOException("Failed to add ssl listener"); } if (needClientAuth) { // setting up SSL truststore for authenticating clients System.setProperty("javax.net.ssl.trustStore", sslConf.get("ssl.server.truststore.location", "")); System.setProperty("javax.net.ssl.trustStorePassword", sslConf.get("ssl.server.truststore.password", "")); System.setProperty("javax.net.ssl.trustStoreType", sslConf.get("ssl.server.truststore.type", "jks")); } SslSocketConnector sslListener = new SslSocketConnector(); sslListener.setHost(addr.getHostName()); sslListener.setPort(addr.getPort()); sslListener.setKeystore(sslConf.get("ssl.server.keystore.location")); sslListener.setPassword(sslConf.get("ssl.server.keystore.password", "")); sslListener.setKeyPassword(sslConf.get("ssl.server.keystore.keypassword", "")); sslListener.setKeystoreType(sslConf.get("ssl.server.keystore.type", "jks")); sslListener.setNeedClientAuth(needClientAuth); webServer.addConnector(sslListener); }
From source file:org.apache.hadoop.hdfs.server.datanode.CachingDataNode.java
private void reconfigureIpcServer(final Configuration conf) throws IOException { this.dataNode.ipcServer.stop(); final InetSocketAddress ipcAddr = NetUtils.createSocketAddr(conf.get(DFS_DATANODE_IPC_ADDRESS_KEY)); // Add all the RPC protocols that the Datanode implements RPC.setProtocolEngine(conf, ClientDatanodeProtocolPB.class, ProtobufRpcEngine.class); final ClientDatanodeProtocolServerSideTranslatorPB clientDatanodeProtocolXlator = new ClientDatanodeProtocolServerSideTranslatorPB( this); BlockingService service = ClientDatanodeProtocolService .newReflectiveBlockingService(clientDatanodeProtocolXlator); final boolean oldVal = DefaultMetricsSystem.inMiniClusterMode(); DefaultMetricsSystem.setMiniClusterMode(true); this.dataNode.ipcServer = RPC.getServer(ClientDatanodeProtocolPB.class, service, ipcAddr.getHostName(), ipcAddr.getPort(), conf.getInt(DFS_DATANODE_HANDLER_COUNT_KEY, DFS_DATANODE_HANDLER_COUNT_DEFAULT), false, conf, this.dataNode.blockPoolTokenSecretManager); DefaultMetricsSystem.setMiniClusterMode(oldVal); final InterDatanodeProtocolServerSideTranslatorPB interDatanodeProtocolXlator = new InterDatanodeProtocolServerSideTranslatorPB( this); service = InterDatanodeProtocolService.newReflectiveBlockingService(interDatanodeProtocolXlator); DFSUtil.addPBProtocol(conf, InterDatanodeProtocolPB.class, service, this.dataNode.ipcServer); LOG.info("Opened IPC server at " + this.dataNode.ipcServer.getListenerAddress()); // set service-level authorization security policy if (conf.getBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, false)) { this.dataNode.ipcServer.refreshServiceAcl(conf, new HDFSPolicyProvider()); }/*from ww w . j a v a 2s . c o m*/ }
From source file:org.apache.hadoop.hdfs.DFSUtil.java
public static URI getInfoServer(InetSocketAddress namenodeAddr, Configuration conf, String scheme) throws IOException { String[] suffixes = null;/*from ww w .j a v a 2 s. co m*/ if (namenodeAddr != null) { // if non-default namenode, try reverse look up // the nameServiceID if it is available suffixes = getSuffixIDs(conf, namenodeAddr, DFSConfigKeys.DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY, DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY); } String authority; if ("http".equals(scheme)) { authority = getSuffixedConf(conf, DFS_NAMENODE_HTTP_ADDRESS_KEY, DFS_NAMENODE_HTTP_ADDRESS_DEFAULT, suffixes); } else if ("https".equals(scheme)) { authority = getSuffixedConf(conf, DFS_NAMENODE_HTTPS_ADDRESS_KEY, DFS_NAMENODE_HTTPS_ADDRESS_DEFAULT, suffixes); } else { throw new IllegalArgumentException("Invalid scheme:" + scheme); } if (namenodeAddr != null) { authority = substituteForWildcardAddress(authority, namenodeAddr.getHostName()); } return URI.create(scheme + "://" + authority); }
From source file:common.NameNode.java
private void startHttpServer(Configuration conf) throws IOException { InetSocketAddress infoSocAddr = getHttpServerAddress(conf); String infoHost = infoSocAddr.getHostName(); int infoPort = infoSocAddr.getPort(); this.httpServer = new HttpServer("hdfs", infoHost, infoPort, infoPort == 0, conf); if (conf.getBoolean("dfs.https.enable", false)) { boolean needClientAuth = conf.getBoolean(DFSConfigKeys.DFS_CLIENT_HTTPS_NEED_AUTH_KEY, DFSConfigKeys.DFS_CLIENT_HTTPS_NEED_AUTH_DEFAULT); InetSocketAddress secInfoSocAddr = NetUtils .createSocketAddr(conf.get(DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_KEY, infoHost + ":" + 0)); Configuration sslConf = new HdfsConfiguration(false); sslConf.addResource(conf.get("dfs.https.server.keystore.resource", "ssl-server.xml")); this.httpServer.addSslListener(secInfoSocAddr, sslConf, needClientAuth); // assume same ssl port for all datanodes InetSocketAddress datanodeSslPort = NetUtils .createSocketAddr(conf.get("dfs.datanode.https.address", infoHost + ":" + 50475)); this.httpServer.setAttribute("datanode.https.port", datanodeSslPort.getPort()); }/*from w w w . j a v a 2 s.c om*/ this.httpServer.setAttribute("name.node", this); this.httpServer.setAttribute("name.node.address", getNameNodeAddress()); this.httpServer.setAttribute("name.system.image", getFSImage()); this.httpServer.setAttribute("name.conf", conf); this.httpServer.addInternalServlet("getDelegationToken", DelegationTokenServlet.PATH_SPEC, DelegationTokenServlet.class); this.httpServer.addInternalServlet("fsck", "/fsck", FsckServlet.class); this.httpServer.addInternalServlet("getimage", "/getimage", GetImageServlet.class); this.httpServer.addInternalServlet("listPaths", "/listPaths/*", ListPathsServlet.class); this.httpServer.addInternalServlet("data", "/data/*", FileDataServlet.class); this.httpServer.addInternalServlet("checksum", "/fileChecksum/*", FileChecksumServlets.RedirectServlet.class); this.httpServer.addInternalServlet("contentSummary", "/contentSummary/*", ContentSummaryServlet.class); this.httpServer.start(); // The web-server port can be ephemeral... ensure we have the correct info infoPort = this.httpServer.getPort(); this.httpAddress = new InetSocketAddress(infoHost, infoPort); setHttpServerAddress(conf); LOG.info(getRole() + " Web-server up at: " + httpAddress); }
From source file:com.eviware.soapui.impl.wsdl.support.http.SoapUISSLSocketFactory.java
/** * @since 4.1//from w w w. j a v a 2s .c o m */ @Override public Socket connectSocket(final Socket socket, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (remoteAddress == null) { throw new IllegalArgumentException("Remote address may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } Socket sock = socket != null ? socket : new Socket(); if (localAddress != null) { sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params)); sock.bind(localAddress); } int connTimeout = HttpConnectionParams.getConnectionTimeout(params); int soTimeout = HttpConnectionParams.getSoTimeout(params); try { sock.setSoTimeout(soTimeout); sock.connect(remoteAddress, connTimeout); } catch (SocketTimeoutException ex) { throw new ConnectTimeoutException( "Connect to " + remoteAddress.getHostName() + "/" + remoteAddress.getAddress() + " timed out"); } SSLSocket sslsock; // Setup SSL layering if necessary if (sock instanceof SSLSocket) { sslsock = (SSLSocket) sock; } else { sslsock = (SSLSocket) getSocketFactory().createSocket(sock, remoteAddress.getHostName(), remoteAddress.getPort(), true); sslsock = enableSocket(sslsock); } // do we need it? trust all hosts // if( getHostnameVerifier() != null ) // { // try // { // getHostnameVerifier().verify( remoteAddress.getHostName(), sslsock ); // // verifyHostName() didn't blowup - good! // } // catch( IOException iox ) // { // // close the socket before re-throwing the exception // try // { // sslsock.close(); // } // catch( Exception x ) // { /* ignore */ // } // throw iox; // } // } return sslsock; }
From source file:com.chinamobile.bcbsp.http.HttpServer.java
/** * Configure an ssl listener on the server. * @param addr//from ww w .ja va2 s .c om * address to listen on * @param sslConf * conf to retrieve ssl options * @param needClientAuth * whether client authentication is required */ public void addSslListener(InetSocketAddress addr, Configuration sslConf, boolean needClientAuth) throws IOException { if (webServer.isStarted()) { throw new IOException("Failed to add ssl listener"); } if (needClientAuth) { /** Set up SSL truststore for authenticating clients */ System.setProperty("javax.net.ssl.trustStore", sslConf.get("ssl.server.truststore.location", "")); System.setProperty("javax.net.ssl.trustStorePassword", sslConf.get("ssl.server.truststore.password", "")); System.setProperty("javax.net.ssl.trustStoreType", sslConf.get("ssl.server.truststore.type", "jks")); } SslSocketConnector sslListener = new SslSocketConnector(); sslListener.setHost(addr.getHostName()); sslListener.setPort(addr.getPort()); sslListener.setKeystore(sslConf.get("ssl.server.keystore.location")); sslListener.setPassword(sslConf.get("ssl.server.keystore.password", "")); sslListener.setKeyPassword(sslConf.get("ssl.server.keystore.keypassword", "")); sslListener.setKeystoreType(sslConf.get("ssl.server.keystore.type", "jks")); sslListener.setNeedClientAuth(needClientAuth); webServer.addConnector(sslListener); }
From source file:org.eclipse.ecf.internal.provider.filetransfer.httpclient4.ECFHttpClientSecureProtocolSocketFactory.java
public Socket connectSocket(final Socket socket, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (remoteAddress == null) { throw new IllegalArgumentException("Remote address must not be null"); //$NON-NLS-1$ }//from w ww .ja va 2s . c om if (params == null) { throw new IllegalArgumentException("HTTP parameters must not be null"); //$NON-NLS-1$ } if (socket == null) { SSLSocket sslSocket = (SSLSocket) this.sslSocketFactory.createSocket(); performConnection(sslSocket, remoteAddress, localAddress, params); return wrapSocket(sslSocket); } else if (socket instanceof SSLSocket) { performConnection(socket, remoteAddress, localAddress, params); return wrapSocket(socket); } // If we were given a unconnected socket, we need to connect it first if (!socket.isConnected()) { performConnection(socket, remoteAddress, localAddress, params); } Socket layeredSocket = this.sslSocketFactory.createSocket(socket, remoteAddress.getHostName(), remoteAddress.getPort(), true); return wrapSocket(layeredSocket); }
From source file:org.apache.hadoop.conf.TestConfiguration.java
public void testUpdateSocketAddress() throws IOException { InetSocketAddress addr = NetUtils.createSocketAddrForHost("host", 1); InetSocketAddress connectAddr = conf.updateConnectAddr("myAddress", addr); assertEquals(connectAddr.getHostName(), addr.getHostName()); addr = new InetSocketAddress(1); connectAddr = conf.updateConnectAddr("myAddress", addr); assertEquals(connectAddr.getHostName(), InetAddress.getLocalHost().getHostName()); }