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.googlecode.jmxtrans.model.output.StatsDWriterFactory.java

public StatsDWriterFactory(@JsonProperty("typeNames") ImmutableList<String> typeNames,
        @JsonProperty("rootPrefix") String rootPrefix, @JsonProperty("bucketType") String bucketType,
        @JsonProperty("stringValuesAsKey") boolean stringsValuesAsKey,
        @JsonProperty("stringValueDefaultCount") Long stringValueDefaultCount,
        @JsonProperty("host") String host, @JsonProperty("port") Integer port,
        @JsonProperty("flushStrategy") String flushStrategy,
        @JsonProperty("flushDelayInSeconds") Integer flushDelayInSeconds,
        @JsonProperty("poolSize") Integer poolSize) {
    this.typeNames = firstNonNull(typeNames, ImmutableList.<String>of());
    this.rootPrefix = firstNonNull(rootPrefix, "servers");
    this.stringsValuesAsKey = stringsValuesAsKey;
    this.bucketType = firstNonNull(bucketType, "c");
    this.stringValueDefaultCount = firstNonNull(stringValueDefaultCount, 1L);
    this.server = new InetSocketAddress(checkNotNull(host, "Host cannot be null."),
            checkNotNull(port, "Port cannot be null."));
    this.flushStrategy = createFlushStrategy(flushStrategy, flushDelayInSeconds);
    this.poolSize = firstNonNull(poolSize, 1);
}

From source file:com.linkedin.mitm.proxy.connectionflow.ConnectionFlowProcessor.java

/**
 * Resolve remote address/* w  w  w . j  a  v a2s.  co  m*/
 * */
private static InetSocketAddress getRemoteAddress(HttpRequest httpRequest) {
    String uri = httpRequest.getUri();
    String uriWithoutProtocol;
    if (HTTP_PREFIX.matcher(uri).matches()) {
        uriWithoutProtocol = StringUtils.substringAfter(uri, "://");
    } else {
        uriWithoutProtocol = uri;
    }
    String hostAndPort;
    if (uriWithoutProtocol.contains("/")) {
        hostAndPort = uriWithoutProtocol.substring(0, uriWithoutProtocol.indexOf("/"));
    } else {
        hostAndPort = uriWithoutProtocol;
    }
    String hostName;
    int port;
    if (hostAndPort.contains(":")) {
        int index = hostAndPort.indexOf(":");
        hostName = hostAndPort.substring(0, index);
        port = Integer.parseInt(hostAndPort.substring(index + 1));
    } else {
        hostName = hostAndPort;
        port = 80;
    }
    return new InetSocketAddress(hostName, port);
}

From source file:com.kurento.kmf.connector.ThriftConnectorJsonRpcHandler.java

@PostConstruct
private void init() {

    LOG.info("Handler Address: {}", config.getHandlerAddress());
    LOG.info("Handler Port: {}", config.getHandlerPort());

    server = (ThriftServer) ctx.getBean("mediaHandlerServer", this.processor,
            new InetSocketAddress(config.getHandlerAddress(), config.getHandlerPort()));
    server.start();//  w  w  w. ja  v a  2s .  co  m
}

From source file:com.xiovr.unibot.bot.BotManagerTest.java

@SuppressWarnings("deprecation")
private @NonNull BotEnvironment createBotEnvironment() {
    BotEnvironment botEnv = new BotEnvironmentImpl();
    botEnv.setPortRangeMin(10000);/*from   w  ww. ja  v  a  2s  .c  o  m*/
    botEnv.setPortRangeMax(11000);
    botEnv.setProxy(true);
    botEnv.setRawData(true);
    botEnv.setUpdateInterval(100);
    botEnv.setNextBotConnectionInterval(10);
    InetSocketAddress isaS = new InetSocketAddress("localhost", 8889);
    List<InetSocketAddress> lisaS = new ArrayList<InetSocketAddress>();
    lisaS.add(isaS);
    botEnv.setServerAddresses(lisaS);
    InetSocketAddress isaC = new InetSocketAddress("localhost", 8000);
    List<InetSocketAddress> lisaC = new ArrayList<InetSocketAddress>();
    lisaC.add(isaC);
    botEnv.setClientAddresses(lisaC);
    return botEnv;

}

From source file:com.lithium.flow.vault.AgentVault.java

@Nullable
private String readAgent() {
    String agentPort = store.getValue("vault.agent.port");
    String agentPassword = store.getValue("vault.agent.password");
    if (agentPort == null || agentPassword == null) {
        return null;
    }/*from   www . jav  a2s  . c om*/

    try {
        int port = Integer.parseInt(agentPort);
        Socket socket = new Socket();
        socket.connect(new InetSocketAddress("localhost", port), 5000);

        @SuppressWarnings("unchecked")
        Map<String, String> map = mapper.readValue(socket.getInputStream(), Map.class);

        Store agentStore = new MemoryStore(map);
        Vault agentVault = new SecureVault(Configs.empty(), agentStore);
        agentVault.unlock(agentPassword);
        return agentVault.getValue("password");
    } catch (Exception e) {
        log.debug("failed to read from agent", e);
        return null;
    }
}

From source file:org.echocat.jemoni.carbon.spring.WriterDefinitionParser.java

@Nonnull
protected InetSocketAddress toSocketAddress(@Nullable String plain) {
    final InetSocketAddress address;
    if (plain != null) {
        final String trimmedText = plain.trim();
        if (!trimmedText.isEmpty()) {
            final int lastDoubleDot = trimmedText.lastIndexOf(':');
            if (lastDoubleDot > 0 && lastDoubleDot + 1 < trimmedText.length()) {
                final String host = trimmedText.substring(0, lastDoubleDot).trim();
                final String plainPort = trimmedText.substring(lastDoubleDot + 1).trim();
                final int port;
                try {
                    port = Integer.parseInt(plainPort);
                } catch (NumberFormatException ignored) {
                    throw new IllegalArgumentException("Illegal port: " + plainPort);
                }/*from   www  . j  a  v a  2  s . com*/
                address = new InetSocketAddress(host, port);
            } else {
                throw new IllegalArgumentException("Port missing");
            }
        } else {
            address = null;
        }
    } else {
        address = null;
    }
    if (address == null) {
        throw new IllegalArgumentException("Could not interpret '" + plain + "' as network socket address.");
    }
    return address;
}

From source file:at.bitfire.davdroid.webdav.TlsSniSocketFactoryTest.java

public void testHostnameNotInCertificate() throws IOException {
    try {//from  w ww  .  java2 s  . co  m
        // host with certificate that doesn't match host name
        // use the IP address as host name because IP addresses are usually not in the certificate subject
        final String ipHostname = sampleTlsEndpoint.getAddress().getHostAddress();
        InetSocketAddress host = new InetSocketAddress(ipHostname, 443);
        @Cleanup
        Socket socket = factory.connectSocket(0, null, new HttpHost(ipHostname), host, null, null);
        fail();
    } catch (SSLException e) {
        Log.i(TAG, "Expected exception", e);
        assertFalse(ExceptionUtils.indexOfType(e, SSLException.class) == -1);
    }
}

From source file:com.vmware.photon.controller.clustermanager.utils.HostUtils.java

/**
 * Added as part off VCS work.//  w  ww  .  j  av a  2 s .c om
 * 
 * @param service
 * @return
 */
public static CloudStoreHelper createCloudStoreHelper(Service service) {
    return new CloudStoreHelper(new StaticServerSet(new InetSocketAddress("127.0.0.1", 19000)));
}

From source file:com.microsoft.tfs.core.config.httpclient.internal.DefaultSSLProtocolSocketFactory.java

/**
 * {@inheritDoc}/*  ww  w .  java 2  s  .c  om*/
 */
@Override
public Socket createSocket(final String host, final int port, final InetAddress localAddress,
        final int localPort, final HttpConnectionParams params)
        throws IOException, UnknownHostException, ConnectTimeoutException {
    Check.notNull(params, "params"); //$NON-NLS-1$

    final int timeout = params.getConnectionTimeout();

    final Socket socket = getSocketFactory(params).createSocket();
    configureSNI(socket, host);
    socket.bind(new InetSocketAddress(localAddress, localPort));
    socket.connect(new InetSocketAddress(host, port), timeout);
    return socket;
}

From source file:com.canoo.cog.sonar.SonarService.java

String callSonarAuth(String path, String userName, String password) throws SonarException {
    URL url;/*from  w w w .j a v a  2 s .co  m*/
    try {
        url = new URL(baseUrl + path);
    } catch (MalformedURLException e) {
        throw new SonarException("Error in Calling Sonar Service.", e);
    }

    try {
        String authPropertyKey;
        HttpURLConnection connection;
        String encoding = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));

        if (isProxyUsed()) {
            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("webproxy.balgroupit.com", 3128));
            authPropertyKey = "Proxy-Authorization";
            connection = (HttpURLConnection) url.openConnection(proxy);
        } else {
            authPropertyKey = "Authorization";
            connection = (HttpURLConnection) url.openConnection();
        }

        connection.setRequestMethod("GET");
        connection.setDoOutput(true);
        connection.setRequestProperty(authPropertyKey, "Basic " + encoding);
        InputStream content = connection.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(content));

        if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
            throw new SonarException("HTTP Get call to " + url.getPath() + " was not successful.");
        }

        return IOUtils.toString(in);
    } catch (ProtocolException e) {
        throw new SonarException("Error in Calling Sonar Service.", e);
    } catch (IOException e) {
        throw new SonarException("Error in Calling Sonar Service.", e);
    }
}