Example usage for java.net InetSocketAddress getHostName

List of usage examples for java.net InetSocketAddress getHostName

Introduction

In this page you can find the example usage for java.net InetSocketAddress getHostName.

Prototype

public final String getHostName() 

Source Link

Document

Gets the hostname .

Usage

From source file:com.amazonaws.http.conn.ssl.SdkTLSSocketFactory.java

/**
 * Invalidates all SSL/TLS sessions in {@code sessionContext} associated with {@code remoteAddress}.
 * @param sessionContext collection of SSL/TLS sessions to be (potentially) invalidated
 * @param remoteAddress associated with sessions to invalidate
 *//*from  w  w  w.ja  va  2 s . c  o m*/
private void clearSessionCache(final SSLSessionContext sessionContext, final InetSocketAddress remoteAddress) {
    final String hostName = remoteAddress.getHostName();
    final int port = remoteAddress.getPort();
    final Enumeration<byte[]> ids = sessionContext.getIds();

    if (ids == null) {
        return;
    }

    while (ids.hasMoreElements()) {
        final byte[] id = ids.nextElement();
        final SSLSession session = sessionContext.getSession(id);
        if (session != null && session.getPeerHost() != null && session.getPeerHost().equalsIgnoreCase(hostName)
                && session.getPeerPort() == port) {
            session.invalidate();
            if (log.isDebugEnabled()) {
                log.debug("Invalidated session " + session);
            }
        }
    }
}

From source file:org.apache.accumulo.trace.instrument.receivers.zipkin.ZipkinSpanReceiver.java

@Override
protected Client createDestination(InetSocketAddress destination) throws Exception {
    if (destination == null)
        return null;

    log.debug("Connecting to " + destination.getHostName() + ":" + destination.getPort());
    TTransport transport = new TFramedTransport(new TSocket(destination.getHostName(), destination.getPort()));
    try {/*from www .ja v a  2  s .c o  m*/
        transport.open();
    } catch (TTransportException e) {
        e.printStackTrace();
    }
    TProtocol protocol = protocolFactory.getProtocol(transport);
    return new Scribe.Client(protocol);
}

From source file:org.apache.hadoop.mapred.tools.MRZKFailoverController.java

@Override
public void loginAsFCUser() throws IOException {
    InetSocketAddress socAddr = NetUtils.createSocketAddr(conf.get(HAUtil.MR_JOBTRACKER_RPC_ADDRESS_KEY));
    SecurityUtil.login(conf, JobTracker.JT_KEYTAB_FILE, JobTracker.JT_USER_NAME, socAddr.getHostName());
}

From source file:org.apache.hadoop.hdfsproxy.ProxyHttpServer.java

/** {@inheritDoc} */
public Connector createBaseListener(Configuration conf) throws IOException {
    final String sAddr;
    if (null == (sAddr = conf.get("proxy.http.test.listener.addr"))) {
        SslSocketConnector sslListener = new SslSocketConnector();
        sslListener.setKeystore(conf.get("ssl.server.keystore.location"));
        sslListener.setPassword(conf.get("ssl.server.keystore.password", ""));
        sslListener.setKeyPassword(conf.get("ssl.server.keystore.keypassword", ""));
        sslListener.setKeystoreType(conf.get("ssl.server.keystore.type", "jks"));
        sslListener.setNeedClientAuth(true);
        System.setProperty("javax.net.ssl.trustStore", conf.get("ssl.server.truststore.location", ""));
        System.setProperty("javax.net.ssl.trustStorePassword", conf.get("ssl.server.truststore.password", ""));
        System.setProperty("javax.net.ssl.trustStoreType", conf.get("ssl.server.truststore.type", "jks"));
        return sslListener;
    }//from w  w w.j a  v  a2  s .c  om
    // unit test
    InetSocketAddress proxyAddr = NetUtils.createSocketAddr(sAddr);
    SelectChannelConnector testlistener = new SelectChannelConnector();
    testlistener.setUseDirectBuffers(false);
    testlistener.setHost(proxyAddr.getHostName());
    testlistener.setPort(proxyAddr.getPort());
    return testlistener;
}

From source file:ch.cyberduck.core.socket.HttpProxyAwareSocket.java

@Override
public void connect(final SocketAddress endpoint, final int timeout) throws IOException {
    if (proxy.type() == Proxy.Type.HTTP) {
        super.connect(proxy.address(), timeout);
        final InetSocketAddress address = (InetSocketAddress) endpoint;
        final OutputStream out = this.getOutputStream();
        IOUtils.write(String.format("CONNECT %s:%d HTTP/1.0\n\n", address.getHostName(), address.getPort()),
                out, Charset.defaultCharset());
        final InputStream in = this.getInputStream();
        final String response = new LineNumberReader(new InputStreamReader(in)).readLine();
        if (null == response) {
            throw new SocketException(String.format("Empty response from HTTP proxy %s",
                    ((InetSocketAddress) proxy.address()).getHostName()));
        }/*from  w w  w. ja  v  a  2  s .c  o  m*/
        if (response.contains("200")) {
            in.skip(in.available());
        } else {
            throw new SocketException(String.format("Invalid response %s from HTTP proxy %s", response,
                    ((InetSocketAddress) proxy.address()).getHostName()));
        }
    } else {
        super.connect(endpoint, timeout);
    }
}

From source file:org.jactr.eclipse.runtime.launching.iterative.IterativeACTRLaunchConfiguration.java

@Override
protected AbstractSession startSession(ILaunch launch, ILaunchConfigurationWorkingCopy configuration,
        String mode) throws CoreException {
    IterativeSession session = new IterativeSession(launch, configuration);

    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Created session " + session);

    /*/*w w  w.j  a  v a 2  s . c  o  m*/
     * we must start before we do much of anything else
     */
    session.start();

    InetSocketAddress addr = session.getConnectionAddress();

    configuration.setAttribute(ACTRLaunchConstants.ATTR_DEBUG_PORT, addr.getPort());

    configuration.setAttribute(ACTRLaunchConstants.ATTR_DEBUG_ADDRESS, addr.getHostName());

    configuration.setAttribute(ACTRLaunchConstants.ATTR_CREDENTIALS, session.getCredentials().toString());

    return session;
}

From source file:eu.stratosphere.sopremo.server.SopremoServer.java

private void startServer() throws IOException {
    final int handlerCount = this.configuration.getInteger(SopremoConstants.SOPREMO_SERVER_HANDLER_COUNT_KEY,
            1);//from   w  w  w.ja  v a  2  s.c  o  m
    InetSocketAddress rpcServerAddress = getServerAddress();
    this.server = RPC.getServer(this, rpcServerAddress.getHostName(), rpcServerAddress.getPort(), handlerCount);
    this.server.start();
}

From source file:org.apache.hadoop.mapred.JobHistoryServer.java

public void start() throws IOException {
    if (!isEmbedded(conf)) {
        historyServer.start();// w  ww  .j a v a2 s  . c  o m
    }

    InetSocketAddress infoSocAddr = NetUtils.createSocketAddr(historyInfoAddr);
    conf.set(MAPRED_HISTORY_SERVER_HTTP_ADDRESS, infoSocAddr.getHostName() + ":" + historyServer.getPort());
    LOG.info("Started job history server at: " + getAddress(conf));
}

From source file:org.spout.vanilla.plugin.protocol.VanillaProtocol.java

@Override
public Message getIntroductionMessage(String playerName, InetSocketAddress addr) {
    return new PlayerHandshakeMessage((byte) VanillaPlugin.MINECRAFT_PROTOCOL_ID, playerName,
            addr.getHostName(), addr.getPort());
}

From source file:edu.tsinghua.lumaqq.qq.net.HttpProxy.java

@Override
public void setRemoteAddress(InetSocketAddress serverAddress) {
    super.setRemoteAddress(serverAddress);
    String s = serverAddress.getHostName() + ':' + QQ.QQ_PORT_HTTP;
    this.remoteAddress = s.getBytes();
}