Example usage for java.net InetSocketAddress InetSocketAddress

List of usage examples for java.net InetSocketAddress InetSocketAddress

Introduction

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

Prototype

private InetSocketAddress(int port, String hostname) 

Source Link

Usage

From source file:com.liferay.portal.cache.memcached.MemcachedClientPoolableObjectFactory.java

public void setAddresses(List<String> addresses) {
    for (String address : addresses) {
        String[] hostAndPort = StringUtil.split(address, CharPool.COLON);

        String hostName = hostAndPort[0];

        int port = _DEFAULT_MEMCACHED_PORT;

        if (hostAndPort.length == 2) {
            port = GetterUtil.getInteger(hostAndPort[1]);
        }//ww  w .j  a v a 2  s  .co  m

        InetSocketAddress inetSocketAddress = new InetSocketAddress(hostName, port);

        _inetSocketAddresses.add(inetSocketAddress);
    }
}

From source file:com.difference.historybook.proxy.ProxyTest.java

@Test
public void testSmallFetch() {
    String body = "<html><head></head><body>Hello World!</body></html>";

    stubFor(get(urlEqualTo("/some/page"))
            .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/html").withBody(body)));

    Proxy proxy = getProxy().setPort(PROXY_PORT);
    try {//from w w  w  . jav a 2s .  c  o  m
        proxy.start();

        java.net.Proxy proxyServer = new java.net.Proxy(java.net.Proxy.Type.HTTP,
                new InetSocketAddress("127.0.0.1", PROXY_PORT));
        HttpURLConnection connection = (HttpURLConnection) new URL(
                "http://localhost:" + DUMMY_SERVER_PORT + "/some/page").openConnection(proxyServer);
        byte[] fetchedContent = IOUtils.toByteArray(connection.getInputStream());
        assertArrayEquals(body.getBytes(Charsets.UTF_8), fetchedContent);

        proxy.stop();
    } catch (Exception e) {
        fail(e.getLocalizedMessage());
    }

}

From source file:me.xingrz.prox.tcp.TcpProxySession.java

public TcpProxySession(Selector selector, int sourcePort, InetAddress remoteAddress, int remotePort) {
    super(selector, sourcePort, remoteAddress, remotePort);
    destination = new InetSocketAddress(remoteAddress, remotePort);
}

From source file:com.supernovapps.audio.jstreamsourcer.Icecast.java

public boolean start(Socket sock) {
    try {/*from  w  w w.  j  av  a 2s . com*/
        this.sock = sock;
        sock.connect(new InetSocketAddress(host, port), timeout);
        sock.setSendBufferSize(64 * 1024);
        out = sock.getOutputStream();

        PrintWriter output = new PrintWriter(out);
        output.println("SOURCE " + path + " HTTP/1.0");

        writeAuthentication(output);
        writeHeaders(output);

        output.println("");
        output.flush();

        InputStreamReader isr = new InputStreamReader(sock.getInputStream());
        BufferedReader in = new BufferedReader(isr);
        String line = in.readLine();

        if (line == null || !line.contains("HTTP") || !line.contains("OK")) {
            if (listener != null) {
                listener.onError("Connection / Authentification error");
            }
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();

        try {
            if (sock != null) {
                sock.close();
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        if (listener != null) {
            listener.onError("Connection / Authentification error");
        }

        return false;
    }
    started = true;

    if (listener != null) {
        listener.onConnected();
    }

    return true;
}

From source file:org.elasticsearch.client.RestClientIntegTests.java

@BeforeClass
public static void startHttpServer() throws Exception {
    httpServer = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
    httpServer.start();/*from  w ww  .j a v  a  2  s  .  c  o  m*/
    //returns a different status code depending on the path
    for (int statusCode : getAllStatusCodes()) {
        createStatusCodeContext(httpServer, statusCode);
    }
    int numHeaders = randomIntBetween(0, 5);
    defaultHeaders = generateHeaders("Header-default", "Header-array", numHeaders);
    restClient = RestClient
            .builder(new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort()))
            .setDefaultHeaders(defaultHeaders).build();
}

From source file:com.lithium.flow.shell.sshj.SshjTunnel.java

public SshjTunnel(@Nonnull Sshj ssh, @Nonnull Tunneling tunneling) throws IOException {
    checkNotNull(ssh);//  ww w.  ja  va  2s  . c o m
    this.tunneling = checkNotNull(tunneling);

    server = buildServerSocket(ssh.getRetries());
    server.bind(new InetSocketAddress(getHost(), tunneling.getListen()));

    connection = ssh.getConnection();

    start();
}

From source file:com.tda.sitefilm.allocine.AbstractAllocineAPI.java

/**
 *  bla/*from   ww w.  j  ava  2 s  . c  om*/
 *  @param proxyHost bla
 *  @param proxyPort bla
 */
public final void setProxy(String proxyHost, int proxyPort) {
    if (StringUtils.isNotBlank(proxyHost) && (proxyPort > -1)) {
        proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
    }
}

From source file:com.googlecode.jcimd.TcpNetConnectionFactory.java

@Override
public Connection getConnection() throws Exception {
    Socket socket = SocketFactory.getDefault().createSocket();
    if (logger.isDebugEnabled()) {
        logger.debug("Connecting to [" + host + ":" + port + "]...");
    }/*from  www  . j  av a2  s  .  co  m*/
    socket.connect(new InetSocketAddress(this.host, this.port), 2000);
    if (logger.isDebugEnabled()) {
        logger.debug("Connected to [" + host + ":" + port + "]");
    }
    if (this.timeout > 0) {
        socket.setSoTimeout(this.timeout);
    }
    PacketSerializer serializer = new PacketSerializer();
    serializer.setSequenceNumberGenerator(new ApplicationPacketSequenceNumberGenerator());
    TcpNetConnection newConnection = new TcpNetConnection(socket, serializer, this.username, this.password);
    this.executor.execute(newConnection);
    newConnection.login();
    return newConnection;
}

From source file:edu.umass.cs.gigapaxos.PaxosServer.java

PaxosServer(String myID, NodeConfig<String> nodeConfig, String[] args) throws IOException {
    this.messenger = (new JSONMessenger<String>((new MessageNIOTransport<String, JSONObject>(myID, nodeConfig,
            ReconfigurationConfig.getServerSSLMode()))));
    Replicable app = this.createApp(args);
    PaxosManager<String> pm = startPaxosManager(this.messenger, app,
            new InetSocketAddress(nodeConfig.getNodeAddress(myID), nodeConfig.getNodePort(myID)));

    // create default paxos group with same name as app class
    pm.createPaxosInstance(app.getClass().getSimpleName() + "0", nodeConfig.getNodeIDs(), null);
}

From source file:com.vmware.photon.controller.common.metrics.GraphiteConfig.java

public void enable() {
    Graphite graphite = new Graphite(new InetSocketAddress(host, port));
    GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(DefaultMetricRegistry.REGISTRY)
            .prefixedWith(prefix).convertDurationsTo(durationUnit).convertRatesTo(rateUnit)
            .filter(new GraphitePredicate()).build(graphite);
    graphiteReporter.start(frequency, frequencyUnit);
}