List of usage examples for java.net InetSocketAddress getPort
public final int getPort()
From source file:com.googlecode.fascinator.common.BasicHttpClient.java
/** * Gets an HTTP client. If authentication is required, the authenticate() * method must be called prior to this method. * /* ww w . j a v a 2 s .c om*/ * @param auth set true to use authentication, false to skip authentication * @return an HTTP client */ public HttpClient getHttpClient(boolean auth) { HttpClient client = new HttpClient(); try { URL url = new URL(baseUrl); Proxy proxy = ProxySelector.getDefault().select(url.toURI()).get(0); if (!proxy.type().equals(Proxy.Type.DIRECT)) { InetSocketAddress address = (InetSocketAddress) proxy.address(); String proxyHost = address.getHostName(); int proxyPort = address.getPort(); client.getHostConfiguration().setProxy(proxyHost, proxyPort); log.trace("Using proxy {}:{}", proxyHost, proxyPort); } } catch (Exception e) { log.warn("Failed to get proxy settings: " + e.getMessage()); } if (auth && credentials != null) { client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, credentials); log.trace("Credentials: username={}", credentials.getUserName()); } return client; }
From source file:org.apache.flink.client.cli.CliFrontend.java
/** * Writes the given job manager address to the associated configuration object. * * @param address Address to write to the configuration * @param config The configuration to write to *//*from w w w .ja v a2 s . c o m*/ static void setJobManagerAddressInConfig(Configuration config, InetSocketAddress address) { config.setString(JobManagerOptions.ADDRESS, address.getHostString()); config.setInteger(JobManagerOptions.PORT, address.getPort()); config.setString(RestOptions.ADDRESS, address.getHostString()); config.setInteger(RestOptions.PORT, address.getPort()); }
From source file:com.datatorrent.stram.engine.StreamContext.java
public InetSocketAddress getBufferServerAddress() { InetSocketAddress isa = get(BUFFER_SERVER_ADDRESS); return new InetSocketAddress(isa.getHostName(), isa.getPort()); }
From source file:com.sonian.elasticsearch.http.jetty.HttpClient.java
public HttpClient(TransportAddress transportAddress, String username, String password) { InetSocketAddress address = ((InetSocketTransportAddress) transportAddress).address(); try {/* w w w . jav a 2s .c o m*/ baseUrl = new URL("http", address.getHostName(), address.getPort(), "/"); } catch (MalformedURLException e) { throw new ElasticsearchException("", e); } if (username != null) { BASE64Encoder enc = new BASE64Encoder(); String userPassword = username + ":" + password; encodedAuthorization = enc.encode(userPassword.getBytes()); } else { encodedAuthorization = null; } }
From source file:org.apache.hadoop.hdfs.tools.DFSZKFailoverController.java
@Override protected byte[] targetToData(HAServiceTarget target) { InetSocketAddress addr = target.getAddress(); return ActiveNodeInfo.newBuilder().setHostname(addr.getHostName()).setPort(addr.getPort()) .setZkfcPort(target.getZKFCAddress().getPort()).setNameserviceId(localNNTarget.getNameServiceId()) .setNamenodeId(localNNTarget.getNameNodeId()).build().toByteArray(); }
From source file:org.wso2.carbon.inbound.endpoint.protocol.hl7.core.MultiIOHandler.java
@Override public void timeout(IOSession session) { InetSocketAddress isa = (InetSocketAddress) session.getRemoteAddress(); InetSocketAddress localIsa = (InetSocketAddress) session.getLocalAddress(); MLLPSourceHandler handler = handlers.get(isa.getPort()); handler.timeout(session);/*from w w w. j a va 2s . c o m*/ handlers.remove(handler); endpointSessions.remove(localIsa.getPort() + "-" + isa.getPort()); }
From source file:au.com.redboxresearchdata.harvester.httpclient.BasicHttpClient.java
/** * Gets an HTTP client. If authentication is required, the authenticate() * method must be called prior to this method. * //from ww w. jav a2s. c o m * @param auth set true to use authentication, false to skip authentication * @return an HTTP client */ public HttpClient getHttpClient(boolean auth) { HttpClient client = new HttpClient(); try { URL url = new URL(baseUrl); // log.info(baseUrl + "----------------------------1111------------"); Proxy proxy = ProxySelector.getDefault().select(url.toURI()).get(0); if (!proxy.type().equals(Proxy.Type.DIRECT)) { InetSocketAddress address = (InetSocketAddress) proxy.address(); String proxyHost = address.getHostName(); int proxyPort = address.getPort(); client.getHostConfiguration().setProxy(proxyHost, proxyPort); // log.trace("Using proxy {}:{}", proxyHost, proxyPort); } } catch (Exception e) { // log.warn("Failed to get proxy settings: " + e.getMessage()); } if (auth && credentials != null) { client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, credentials); // log.trace("Credentials: username={}", credentials.getUserName()); } return client; }
From source file:cpcc.com.services.CommunicationServiceTest.java
@BeforeMethod public void setUp() throws Exception { content = null;//from w ww.ja v a2 s .com throwHttpException = false; handler = mock(HttpRequestHandler.class); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); request = (BasicHttpEntityEnclosingRequest) args[0]; HttpResponse response = (HttpResponse) args[1]; // HttpContext context = (HttpContext) args[2]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(request.getEntity().getContent(), baos); content = baos.toByteArray(); if (throwHttpException) { throw new HttpException("HttpException thrown on purpose!"); } final int statusCode = response.getStatusLine().getStatusCode(); final String reasonPhrase = response.getStatusLine().getReasonPhrase(); final ProtocolVersion protocolVersion = response.getProtocolVersion(); response.setStatusLine(new MyStatusLine(protocolVersion, statusCode, reasonPhrase)); HttpEntity entity = EntityBuilder.create().setContentType(ContentType.TEXT_PLAIN) .setText(REASON_PHRASE).build(); response.setEntity(entity); return null; } }).when(handler).handle(any(HttpRequest.class), any(HttpResponse.class), any(HttpContext.class)); server = new LocalTestServer(null, null); server.register("/*", handler); server.start(); InetSocketAddress addr = server.getServiceAddress(); String serverUrl = "http://" + addr.getHostString() + ":" + addr.getPort(); realVehicle = mock(RealVehicle.class); when(realVehicle.getUrl()).thenReturn(serverUrl + "/rv001"); com = new CommunicationServiceImpl(); }
From source file:org.apache.hadoop.mapred.JTAddress.java
/** * Construct an instance from an {@link InetSocketAddress}. * @param address InetSocketAddress of server *//*from w w w . ja v a2s. c o m*/ public JTAddress(InetSocketAddress address) { this.address = address; this.stringValue = address.getAddress().getHostName() + ":" + address.getPort(); checkBindAddressCanBeResolved(); }
From source file:com.buaa.cfs.common.oncrpc.RpcProgram.java
public boolean doPortMonitoring(SocketAddress remoteAddress) { if (!allowInsecurePorts) { if (LOG.isTraceEnabled()) { LOG.trace("Will not allow connections from unprivileged ports. " + "Checking for valid client port..."); }/* w w w . j a v a 2s .c o m*/ if (remoteAddress instanceof InetSocketAddress) { InetSocketAddress inetRemoteAddress = (InetSocketAddress) remoteAddress; if (inetRemoteAddress.getPort() > 1023) { LOG.warn("Connection attempted from '" + inetRemoteAddress + "' " + "which is an unprivileged port. Rejecting connection."); return false; } } else { LOG.warn("Could not determine remote port of socket address '" + remoteAddress + "'. Rejecting connection."); return false; } } return true; }