List of usage examples for java.net InetSocketAddress InetSocketAddress
private InetSocketAddress(int port, String hostname)
From source file:com.vmware.aurora.vc.vcservice.TlsSocketFactory.java
@Override public Socket createSocket(String host, int port, InetAddress localAddress, int localPort, HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (params == null) { throw new IllegalArgumentException("Parameters may not be null"); }//from ww w . ja v a 2 s . c o m int timeout = params.getConnectionTimeout(); SocketFactory socketfactory = getSSLContext().getSocketFactory(); if (timeout == 0) { return socketfactory.createSocket(host, port, localAddress, localPort); } else { Socket socket = socketfactory.createSocket(); socket.bind(new InetSocketAddress(localAddress, localPort)); socket.connect(new InetSocketAddress(host, port), timeout); return socket; } }
From source file:com.gsf.dowload.nfe.HSProtocolSocketFactory.java
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort, HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (params == null) { throw new IllegalArgumentException("Parameters may not be null"); }/*from w w w .j ava 2s. c o m*/ int timeout = params.getConnectionTimeout(); SocketFactory socketfactory = getSSLContext().getSocketFactory(); if (timeout == 0) { return socketfactory.createSocket(host, port, localAddress, localPort); } Socket socket = socketfactory.createSocket(); SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); SocketAddress remoteaddr = new InetSocketAddress(host, port); socket.bind(localaddr); try { socket.connect(remoteaddr, timeout); } catch (Throwable t) { Logger.getLogger(HSProtocolSocketFactory.class.getName()).log(Level.SEVERE, null, t); throw new ConnectTimeoutException("Erro na conexao", t); } return socket; }
From source file:org.olat.core.util.httpclient.EasySSLSocketFactory.java
@Override public Socket connectSocket(int connectTimeout, Socket sock, HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context) throws IOException { SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket()); int localPort = 0; if (localAddress != null) { // we need to bind explicitly if (localAddress.getPort() < 0) { localPort = 0; // indicates "any" }/*from w w w. java 2 s. c o m*/ InetSocketAddress isa = new InetSocketAddress(localAddress.getAddress(), localPort); sslsock.bind(isa); } sslsock.connect(remoteAddress, 10000); sslsock.setSoTimeout(10000); return sslsock; }
From source file:com.googlecode.jmxtrans.model.output.TCollectorUDPWriterFactory.java
@JsonCreator public TCollectorUDPWriterFactory(@JsonProperty("typeNames") ImmutableList<String> typeNames, @JsonProperty("booleanAsNumber") boolean booleanAsNumber, @JsonProperty("host") String host, @JsonProperty("port") Integer port, @JsonProperty("tags") Map<String, String> tags, @JsonProperty("tagName") String tagName, @JsonProperty("mergeTypeNamesTags") Boolean mergeTypeNamesTags, @JsonProperty("metricNamingExpression") String metricNamingExpression, @JsonProperty("addHostnameTag") Boolean addHostnameTag, @JsonProperty("flushStrategy") String flushStrategy, @JsonProperty("flushDelayInSeconds") Integer flushDelayInSeconds, @JsonProperty("poolSize") Integer poolSize) throws LifecycleException, UnknownHostException { this.booleanAsNumber = booleanAsNumber; this.server = new InetSocketAddress(firstNonNull(host, "localhost"), firstNonNull(port, 3030)); ImmutableMap<String, String> immutableTags = tags == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(tags); messageFormatter = new OpenTSDBMessageFormatter(typeNames, immutableTags, tagName, metricNamingExpression, mergeTypeNamesTags, addHostnameTag); this.flushStrategy = createFlushStrategy(flushStrategy, flushDelayInSeconds); this.poolSize = firstNonNull(poolSize, 1); }
From source file:net.kungfoo.grizzly.proxy.impl.ProxyAdapter.java
/** * {@inheritDoc}/* ww w .ja v a 2s . co m*/ */ public void service(Request request, Response response) throws Exception { String uri = request.unparsedURI().toString(); final MessageBytes method = request.method(); logURIAndMethod(uri, method); if (maxForwards(request, response, method)) return; String targetHost = request.serverName().toString(); int targetPort = request.getServerPort(); ProxyProcessingInfo proxyTask = new ProxyProcessingInfo(); // TODO: think of it. synchronized (proxyTask) { // from connected // Initialize connection state proxyTask.setTarget(new HttpHost(targetHost, targetPort)); proxyTask.setRequest(convert(method.getString(), uri, request)); proxyTask.setOriginalRequest(request); Runnable completion = (Runnable) request.getAttribute(CALLBACK_KEY); proxyTask.setCompletion(completion); proxyTask.setResponse(response); InetSocketAddress address = new InetSocketAddress(targetHost, targetPort); if (!IOReactorStatus.ACTIVE.equals(connectingIOReactor.getStatus())) { System.err.println("Connecting reactor not running."); response.setStatus(500); response.setMessage("Internal Booo"); // complete request. ExecutorService executorService = Executors.newFixedThreadPool(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r, "EmergencyService"); //To change body of implemented methods use File | Settings | File Templates. } }); executorService.submit(completion); return; } else { connectingIOReactor.connect(address, null, proxyTask, null); } // from requestReceived try { System.out.println(request + " [client->proxy] >> " + request.unparsedURI().toString()); // Update connection state proxyTask.setClientState(ConnState.REQUEST_RECEIVED); if (request.getContentLength() != 0) { proxyTask.setClientState(ConnState.REQUEST_BODY_DONE); } // See if the client expects a 100-Continue if (isExpectContinue(request)) { response.setStatus(HttpStatus.SC_CONTINUE); response.sendHeaders(); } } catch (IOException ignore) { System.out.println("err " + ignore.getMessage()); } } // handle "Via", TODO: should go after we have headers from target server. response.setHeader(Via.name(), request.protocol() + " antares");// TODO hostname, and Via from response }
From source file:com.rowoerowanie.endoexporttokml.ExportKml.java
private InputStream loadData(String url) throws MalformedURLException, IOException { System.out.println("czenie z " + url); HttpURLConnection connection; if (StringUtils.isNotBlank(this.proxyHost)) { Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(this.proxyHost, proxyPort)); connection = (HttpURLConnection) new URL(url).openConnection(proxy); } else {//from w w w . j a va 2s. c om connection = (HttpURLConnection) new URL(url).openConnection(); } return connection.getInputStream(); }
From source file:com.couchbase.client.ViewNodeTest.java
/** * This test tries to retrieve unresponsive node by establishing an HTTP * connection to a single Couchbase node. * * @pre Build a connection manager and socket address using the server * configurations. Pass these to ViewNode to retrieve its new instance. * Call writeOp to request for connection. * @post Asserts false if its not able to get connection. *//*from w w w. j a v a 2s . c o m*/ @Test public void testUnresponsiveViewNode() throws IOReactorException { AsyncConnectionManager mgr = createConMgr(TestConfig.IPV4_ADDR, 8091); InetSocketAddress addr = new InetSocketAddress(TestConfig.IPV4_ADDR, 8091); ViewNode viewNode = new ViewNode(addr, mgr, 0, 0, 0, "", ""); assertFalse("View node has write ops.", viewNode.hasWriteOps()); HttpOperation operation = createHttpOperation(); viewNode.writeOp(operation); }
From source file:com.linkedin.d2.discovery.stores.glu.TrustingSocketFactory.java
public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort, final HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (params == null) { throw new IllegalArgumentException("Parameters may not be null"); }/*from ww w . jav a2s . c o m*/ int timeout = params.getConnectionTimeout(); SocketFactory socketfactory = getSSLContext().getSocketFactory(); if (timeout == 0) { return socketfactory.createSocket(host, port, localAddress, localPort); } else { Socket socket = socketfactory.createSocket(); SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); SocketAddress remoteaddr = new InetSocketAddress(host, port); socket.bind(localaddr); socket.connect(remoteaddr, timeout); return socket; } }
From source file:com.googlecode.jmxtrans.model.output.GraphiteWriterFactory.java
@JsonCreator public GraphiteWriterFactory(@JsonProperty("typeNames") ImmutableList<String> typeNames, @JsonProperty("booleanAsNumber") boolean booleanAsNumber, @JsonProperty("rootPrefix") String rootPrefix, @JsonProperty("host") String host, @JsonProperty("port") Integer port, @JsonProperty("flushStrategy") String flushStrategy, @JsonProperty("flushDelayInSeconds") Integer flushDelayInSeconds, @JsonProperty("poolSize") Integer poolSize) { this.typeNames = typeNames; this.booleanAsNumber = booleanAsNumber; this.rootPrefix = firstNonNull(rootPrefix, DEFAULT_ROOT_PREFIX); this.graphiteServer = 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.pinot.server.request.ScheduledRequestHandlerTest.java
@BeforeTest public void setupTestMethod() { serverMetrics = new ServerMetrics(new MetricsRegistry()); channelHandlerContext = mock(ChannelHandlerContext.class, RETURNS_DEEP_STUBS); when(channelHandlerContext.channel().remoteAddress()).thenAnswer(new Answer<InetSocketAddress>() { @Override//from w w w .j a va 2 s . c om public InetSocketAddress answer(InvocationOnMock invocationOnMock) throws Throwable { return new InetSocketAddress("localhost", 60000); } }); queryScheduler = mock(QueryScheduler.class); queryExecutor = new ServerQueryExecutorV1Impl(); resourceManager = new UnboundedResourceManager(new PropertiesConfiguration()); }