List of usage examples for java.net InetSocketAddress getPort
public final int getPort()
From source file:org.apache.hadoop.hbase.stargate.RegionsResource.java
@GET @Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF }) public Response get(final @Context UriInfo uriInfo) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("GET " + uriInfo.getAbsolutePath()); }/*from ww w. j av a2s . com*/ if (!servlet.userRequestLimit(user, 1)) { Response.status(509).build(); } servlet.getMetrics().incrementRequests(1); try { String name = user.isAdmin() ? actualTableName : tableName; TableInfoModel model = new TableInfoModel(name); Map<HRegionInfo, HServerAddress> regions = getTableRegions(); for (Map.Entry<HRegionInfo, HServerAddress> e : regions.entrySet()) { HRegionInfo hri = e.getKey(); if (user.isAdmin()) { HServerAddress addr = e.getValue(); InetSocketAddress sa = addr.getInetSocketAddress(); model.add(new TableRegionModel(name, hri.getRegionId(), hri.getStartKey(), hri.getEndKey(), sa.getHostName() + ":" + Integer.valueOf(sa.getPort()))); } else { model.add(new TableRegionModel(name, hri.getRegionId(), hri.getStartKey(), hri.getEndKey())); } } ResponseBuilder response = Response.ok(model); response.cacheControl(cacheControl); return response.build(); } catch (TableNotFoundException e) { throw new WebApplicationException(Response.Status.NOT_FOUND); } catch (IOException e) { throw new WebApplicationException(e, Response.Status.SERVICE_UNAVAILABLE); } }
From source file:org.wso2.carbon.inbound.endpoint.protocol.hl7.core.MultiIOHandler.java
@Override public void disconnected(IOSession session) { InetSocketAddress isa = (InetSocketAddress) session.getRemoteAddress(); InetSocketAddress localIsa = (InetSocketAddress) session.getLocalAddress(); if (isa == null) { return;/* w w w . ja va2 s .com*/ } MLLPSourceHandler handler = handlers.get(isa.getPort()); handler.disconnected(session); handlers.remove(handler); endpointSessions.remove(localIsa.getPort() + "-" + isa.getPort()); }
From source file:org.apache.hadoop.registry.server.services.MicroZookeeperService.java
/** * Get the connection string./*from w ww . ja va2 s . c o m*/ * @return the string * @throws IllegalStateException if the connection is not yet valid */ public String getConnectionString() { Preconditions.checkState(factory != null, "service not started"); InetSocketAddress addr = factory.getLocalAddress(); return String.format("%s:%d", addr.getHostName(), addr.getPort()); }
From source file:brooklyn.util.ResourceUtilsHttpTest.java
@BeforeClass(alwaysRun = true) public void setUp() throws Exception { utils = ResourceUtils.create(this, "mycontext"); BasicHttpProcessor httpProcessor = new BasicHttpProcessor(); httpProcessor.addInterceptor(new ResponseServer()); httpProcessor.addInterceptor(new ResponseContent()); httpProcessor.addInterceptor(new ResponseConnControl()); httpProcessor.addInterceptor(new RequestBasicAuth()); httpProcessor.addInterceptor(new ResponseBasicUnauthorized()); server = new LocalTestServer(httpProcessor, null); server.register("/simple", new SimpleResponseHandler("OK")); server.register("/empty", new SimpleResponseHandler(HttpStatus.SC_NO_CONTENT, "")); server.register("/missing", new SimpleResponseHandler(HttpStatus.SC_NOT_FOUND, "Missing")); server.register("/redirect", new SimpleResponseHandler(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect", new BasicHeader("Location", "/simple"))); server.register("/cycle", new SimpleResponseHandler(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect", new BasicHeader("Location", "/cycle"))); server.register("/secure", new SimpleResponseHandler(HttpStatus.SC_MOVED_TEMPORARILY, "Redirect", new BasicHeader("Location", "https://0.0.0.0/"))); server.register("/auth", new AuthHandler("test", "test", "OK")); server.register("/auth_escape", new AuthHandler("test@me:/", "test", "OK")); server.register("/auth_escape2", new AuthHandler("test@me:test", "", "OK")); server.register("/no_credentials", new CheckNoCredentials()); server.start();//from w w w . java 2 s .c o m InetSocketAddress addr = server.getServiceAddress(); baseUrl = "http://" + addr.getHostName() + ":" + addr.getPort(); }
From source file:org.hydracache.server.httpd.AsyncHttpLightServer.java
InetSocketAddress buildInetSocketAddress() { InetSocketAddress address = null; address = new InetSocketAddress(ip, portNumber); if (log.isDebugEnabled()) { log.debug("Server is listening on address [" + address.getAddress().getHostAddress() + ":" + address.getPort() + "]"); }//from w w w. ja v a 2 s. c o m return address; }
From source file:org.apache.hadoop.hdfs.server.namenode.Checkpointer.java
private URL getImageListenAddress() { InetSocketAddress httpSocAddr = backupNode.getHttpAddress(); int httpPort = httpSocAddr.getPort(); try {// www. j av a 2s. c o m return new URL(DFSUtil.getHttpClientScheme(conf) + "://" + infoBindAddress + ":" + httpPort); } catch (MalformedURLException e) { // Unreachable throw new RuntimeException(e); } }
From source file:io.github.bonigarcia.wdm.WdmHttpClient.java
private final HttpHost createProxyHttpHost(String proxyUrl) { Proxy proxy = createProxy(proxyUrl); if (proxy == null || proxy.address() == null) { return null; }//from w w w. j a v a2 s . co m if (!(proxy.address() instanceof InetSocketAddress)) { throw new RuntimeException( "Detect an unsupported subclass of SocketAddress. Please use the InetSocketAddress or subclass. Actual:" + proxy.address().getClass()); } InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address(); return new HttpHost(proxyAddress.getHostName(), proxyAddress.getPort()); }
From source file:org.opennms.smoketest.minion.DiscoveryTest.java
@Test public void canDiscoverRemoteNodes() throws ClientProtocolException, IOException { Date startOfTest = new Date(); final String tomcatIp = minionSystem.getContainerInfo(ContainerAlias.TOMCAT).networkSettings().ipAddress(); final InetSocketAddress opennmsHttp = minionSystem.getServiceAddress(ContainerAlias.OPENNMS, 8980); final HttpHost opennmsHttpHost = new HttpHost(opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort()); HttpClient instance = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()) // Ignore the 302 response to the POST .build();/*from w w w . ja v a2s .c o m*/ Executor executor = Executor.newInstance(instance).auth(opennmsHttpHost, "admin", "admin") .authPreemptive(opennmsHttpHost); // Configure Discovery with the specific address of our Tomcat server // No REST endpoint is currently available, so we resort to POSTin nasty form data executor.execute(Request .Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=AddSpecific", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())) .bodyForm(Form.form().add("specificipaddress", tomcatIp).add("specifictimeout", "2000") .add("specificretries", "1").add("initialsleeptime", "30000") .add("restartsleeptime", "86400000").add("foreignsource", "NODES").add("location", "MINION") .add("retries", "1").add("timeout", "2000").build())) .returnContent(); executor.execute(Request .Post(String.format("http://%s:%d/opennms/admin/discovery/actionDiscovery?action=SaveAndRestart", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())) .bodyForm(Form.form().add("initialsleeptime", "1").add("restartsleeptime", "86400000") .add("foreignsource", "NODES").add("location", "MINION").add("retries", "1") .add("timeout", "2000").build())) .returnContent(); InetSocketAddress pgsql = minionSystem.getServiceAddress(ContainerAlias.POSTGRES, 5432); HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql); EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class); // TODO: Match the Monitoring System ID when this becomes available in the event Criteria criteria = new CriteriaBuilder(OnmsEvent.class) .eq("eventUei", EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI).ge("eventTime", startOfTest) .toCriteria(); await().atMost(1, MINUTES).pollInterval(10, SECONDS) .until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0)); }
From source file:org.apache.flink.client.CliFrontendAddressConfigurationTest.java
@Test public void testInvalidConfigAndOption() { try {//from w w w . j a v a 2 s .c om CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getInvalidConfigDir()); CommandLineOptions options = mock(CommandLineOptions.class); when(options.getJobManagerAddress()).thenReturn("10.221.130.22:7788"); frontend.updateConfig(options); Configuration config = frontend.getConfiguration(); InetSocketAddress expectedAddress = new InetSocketAddress("10.221.130.22", 7788); checkJobManagerAddress(config, expectedAddress.getHostName(), expectedAddress.getPort()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
From source file:org.apache.hadoop.hdfs.qjournal.server.JournalNodeRpcServer.java
JournalNodeRpcServer(Configuration conf, JournalNode jn) throws IOException { this.jn = jn; Configuration confCopy = new Configuration(conf); // Ensure that nagling doesn't kick in, which could cause latency issues. confCopy.setBoolean("ipc.server.tcpnodelay", true); // reader threads will handle the RPC calls confCopy.setBoolean("ipc.direct.handling", true); // set the number of reader threads, should be at least the number of // served namenodes confCopy.setInt(Server.IPC_SERVER_RPC_READ_THREADS_KEY, confCopy.getInt( JournalConfigKeys.DFS_QJOURNAL_IPC_READER_KEY, JournalConfigKeys.DFS_QJOURNAL_IPC_READER_DEFAULT)); InetSocketAddress addr = getAddress(confCopy); this.server = RPC.getServer(this, addr.getAddress().getHostAddress(), addr.getPort(), HANDLER_COUNT, false, confCopy, false);/*from w ww . j a va 2 s.co m*/ this.conf = confCopy; }