Example usage for java.net InetSocketAddress getPort

List of usage examples for java.net InetSocketAddress getPort

Introduction

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

Prototype

public final int getPort() 

Source Link

Document

Gets the port number.

Usage

From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient3Connector.java

/**
 * Create the {@link HttpClient} object/*w  ww .  ja v  a 2  s .  c  o m*/
 */
private void createClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setConnectionTimeout(TIMEOUT_MS);
    params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS);
    params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    httpClient = new HttpClient(connectionManager);
    configureCredentials();
    if (StringUtils.isNotBlank(System.getProperty("http.proxyHost"))) {
        log.debug("A HTTP Proxy is configured");
        System.setProperty("java.net.useSystemProxies", "true");
        Proxy proxy = chooseProxy();
        if (proxy.type() == Type.HTTP && proxy.address() instanceof InetSocketAddress) {
            // convert the socket address to an ProxyHost
            final InetSocketAddress isa = (InetSocketAddress) proxy.address();
            // assume default scheme (http)
            ProxyHost proxyHost = new ProxyHost(getHost(isa), isa.getPort());
            httpClient.getHostConfiguration().setProxyHost(proxyHost);
            if (StringUtils.isNotBlank(System.getProperty("http.proxyUser"))) {
                String user = System.getProperty("http.proxyUser");
                String password = System.getProperty("http.proxyPassword");
                httpClient.getState().setProxyCredentials(new AuthScope(getHost(isa), isa.getPort()),
                        new UsernamePasswordCredentials(user, password));
            }
        }
    }
}

From source file:org.graylog2.jersey.container.netty.NettyContainerTest.java

private int bindJerseyServer(Inflector<ContainerRequestContext, ChunkedOutput<?>> inflector,
        ServerBootstrap bootstrap, Class... classes) throws URISyntaxException {
    final Resource resource = getResource(inflector);
    final NettyContainer jerseyHandler = getNettyContainer(resource, classes);
    setChunkedHttpPipeline(bootstrap, jerseyHandler);

    final Channel bind = bootstrap.bind(new InetSocketAddress(0));

    InetSocketAddress socketAddress = (InetSocketAddress) bind.getLocalAddress();
    return socketAddress.getPort();
}

From source file:com.googlecode.gmail4j.http.HttpProxyAwareSslSocketFactory.java

@Override
public Socket createSocket() throws IOException {
    //FIXME won't work..
    log.debug("Creating socket! with proxy: " + proxy.address());
    InetSocketAddress addr = (InetSocketAddress) proxy.address();
    ProxyClient proxyClient = new ProxyClient();
    proxyClient.getHostConfiguration().setHost("imap.gmail.com", 993);
    proxyClient.getHostConfiguration().setProxy(addr.getHostName(), addr.getPort());
    if (proxyCredentials != null) {
        proxyClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(
                proxyCredentials.getUsername(), new String(proxyCredentials.getPasword())));
    }/*  ww w  .j av  a2  s  .co  m*/
    log.debug("Trying to connect to proxy");
    ProxyClient.ConnectResponse resp = proxyClient.connect();
    if (resp.getConnectMethod().getStatusCode() != HttpStatus.SC_OK) {
        log.error("Failed to connect. " + resp.getConnectMethod().getStatusLine());
        throw new GmailException(
                "Failed connecting to IMAP through proxy: " + resp.getConnectMethod().getStatusLine());
    }
    log.debug("Connected, returning socket");
    return resp.getSocket();
}

From source file:io.crate.integrationtests.BlobSslEnabledITest.java

@Test
public void testGetBlob() throws Exception {
    // this test verifies that the non-zero-copy code path in the HttpBlobHandler works
    String digest = uploadSmallBlob();
    String blobUri = blobUri(digest);

    // can't follow redirects because ssl isn't really enabled
    // -> figure out the node that really has the blob

    CloseableHttpClient client = HttpClients.custom().disableRedirectHandling().build();
    List<String> redirectLocations = getRedirectLocations(client, blobUri, address);
    InetSocketAddress correctAddress;
    if (redirectLocations.isEmpty()) {
        correctAddress = address;/*from   w  w w  .java  2 s  .c o m*/
    } else {
        correctAddress = address2;
    }

    HttpGet httpGet = new HttpGet(String.format(Locale.ENGLISH, "http://%s:%s/_blobs/%s",
            correctAddress.getHostName(), correctAddress.getPort(), blobUri));

    CloseableHttpResponse response = client.execute(httpGet);
    assertEquals(1500, response.getEntity().getContentLength());
}

From source file:com.github.mrstampy.kitchensync.message.KiSyMessage.java

/**
 * The Constructor.//from  w  w w.  j  a va 2s  . com
 *
 * @param originator
 *          the originator of the message
 * @param types
 *          the types applicable for this message
 */
public KiSyMessage(InetSocketAddress originator, KiSyMessageType... types) {
    this(originator.getAddress(), originator.getPort(), types);
}

From source file:org.apache.hadoop.hdfs.server.datanode.AvatarDataNode.java

/**
 * Returns the IP:port address of the avatar node
 *//*w w w. jav a2  s. c o  m*/
private static List<InetSocketAddress> getAvatarNodeAddresses(String suffix, Configuration conf,
        Collection<String> serviceIds) throws IOException {
    List<InetSocketAddress> namenodeAddresses = DFSUtil.getRPCAddresses(suffix, conf, serviceIds,
            FSConstants.DFS_NAMENODE_RPC_ADDRESS_KEY);
    List<InetSocketAddress> avatarnodeAddresses = new ArrayList<InetSocketAddress>(namenodeAddresses.size());
    for (InetSocketAddress namenodeAddress : namenodeAddresses) {
        avatarnodeAddresses.add(new InetSocketAddress(namenodeAddress.getAddress(),
                conf.getInt("dfs.avatarnode.port", namenodeAddress.getPort() + 1)));
    }
    return avatarnodeAddresses;
}

From source file:org.apache.hadoop.ipc.RpcSSLEngineAbstr.java

private String getRemoteHost() {
    try {/*from w  w w .ja v a  2s  .  c o  m*/
        SocketAddress remoteAddress = socketChannel.getRemoteAddress();
        if (remoteAddress == null) {
            return "unknown";
        }
        if (remoteAddress instanceof InetSocketAddress) {
            InetSocketAddress inetRemoteAddress = (InetSocketAddress) remoteAddress;
            return inetRemoteAddress.getHostString() + ":" + inetRemoteAddress.getPort();
        }
        return "unknown";
    } catch (IOException ex) {
        return "unknown";
    }
}

From source file:com.spotify.helios.ZooKeeperClusterTestManager.java

private List<String> endpoints(final Iterable<InetSocketAddress> addresses) {
    return ImmutableList.copyOf(transform(addresses, new Function<InetSocketAddress, String>() {
        @Override//from   ww w  .  ja  v  a 2  s. co  m
        public String apply(final InetSocketAddress addr) {
            return addr.getHostString() + ":" + addr.getPort();
        }
    }));
}

From source file:org.apache.hadoop.hdfs.server.namenode.NameNodeHttpServer.java

public void start() throws IOException {
    final String infoHost = bindAddress.getHostName();
    int infoPort = bindAddress.getPort();

    httpServer = new HttpServer("hdfs", infoHost, infoPort, infoPort == 0, conf,
            new AccessControlList(conf.get(DFS_ADMIN, " "))) {
        {//from   w w  w.j a v a2  s  . c om
            // Add SPNEGO support to NameNode
            if (UserGroupInformation.isSecurityEnabled()) {
                initSpnego(conf, DFSConfigKeys.DFS_NAMENODE_INTERNAL_SPNEGO_USER_NAME_KEY,
                        DFSConfigKeys.DFS_NAMENODE_KEYTAB_FILE_KEY);
            }
            if (WebHdfsFileSystem.isEnabled(conf, LOG)) {
                //add SPNEGO authentication filter for webhdfs
                final String name = "SPNEGO";
                final String classname = AuthFilter.class.getName();
                final String pathSpec = WebHdfsFileSystem.PATH_PREFIX + "/*";
                Map<String, String> params = getAuthFilterParams(conf);
                defineFilter(webAppContext, name, classname, params, new String[] { pathSpec });
                LOG.info("Added filter '" + name + "' (class=" + classname + ")");

                // add webhdfs packages
                addJerseyResourcePackage(NamenodeWebHdfsMethods.class.getPackage().getName() + ";"
                        + Param.class.getPackage().getName(), pathSpec);
            }
        }

        private Map<String, String> getAuthFilterParams(Configuration conf) throws IOException {
            Map<String, String> params = new HashMap<String, String>();
            String principalInConf = conf.get(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY);
            if (principalInConf != null && !principalInConf.isEmpty()) {
                params.put(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL_KEY,
                        SecurityUtil.getServerPrincipal(principalInConf, bindAddress.getHostName()));
            }
            String httpKeytab = conf.get(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_KEYTAB_KEY);
            if (httpKeytab != null && !httpKeytab.isEmpty()) {
                params.put(DFSConfigKeys.DFS_WEB_AUTHENTICATION_KERBEROS_KEYTAB_KEY, httpKeytab);
            }
            return params;
        }
    };

    boolean certSSL = conf.getBoolean("dfs.https.enable", false);
    if (certSSL) {
        boolean needClientAuth = conf.getBoolean("dfs.https.need.client.auth", false);
        InetSocketAddress secInfoSocAddr = NetUtils
                .createSocketAddr(infoHost + ":" + conf.get("dfs.https.port", infoHost + ":" + 0));
        Configuration sslConf = new Configuration(false);
        if (certSSL) {
            sslConf.addResource(conf.get("dfs.https.server.keystore.resource", "ssl-server.xml"));
        }
        httpServer.addSslListener(secInfoSocAddr, sslConf, needClientAuth);
        // assume same ssl port for all datanodes
        InetSocketAddress datanodeSslPort = NetUtils
                .createSocketAddr(conf.get("dfs.datanode.https.address", infoHost + ":" + 50475));
        httpServer.setAttribute("datanode.https.port", datanodeSslPort.getPort());
    }
    httpServer.setAttribute(NAMENODE_ATTRIBUTE_KEY, nn);
    httpServer.setAttribute(NAMENODE_ADDRESS_ATTRIBUTE_KEY, nn.getNameNodeAddress());
    httpServer.setAttribute(FSIMAGE_ATTRIBUTE_KEY, nn.getFSImage());
    httpServer.setAttribute(JspHelper.CURRENT_CONF, conf);
    setupServlets(httpServer, conf);
    httpServer.start();
    httpAddress = new InetSocketAddress(bindAddress.getAddress(), httpServer.getPort());
}

From source file:com.kixeye.chassis.support.test.eureka.ChassisEurekaTestConfiguration.java

@Order(0)
@Bean(initMethod = "start", destroyMethod = "stop")
public Server httpServer(@Value("${http.hostname}") String hostname, @Value("${http.port}") int port,
        ConfigurableWebApplicationContext webApplicationContext) {

    // set up servlets
    ServletHandler servlets = new ServletHandler();
    ServletContextHandler context = new ServletContextHandler(
            ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);/*from   ww w .  j ava 2s  . c om*/
    context.setWelcomeFiles(new String[] { "/" });

    // set up spring with the servlet context
    setServletContext(context.getServletContext());

    // configure the spring mvc dispatcher
    DispatcherServlet dispatcher = new DispatcherServlet(webApplicationContext);

    // map application servlets
    context.addServlet(new ServletHolder(dispatcher), "/");

    servlets.setHandler(context);

    // create the server
    InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port)
            : new InetSocketAddress(hostname, port);
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setHost(address.getHostName());
    connector.setPort(address.getPort());
    server.setConnectors(new Connector[] { connector });
    server.setHandler(servlets);

    return server;
}