List of usage examples for javax.net SocketFactory getDefault
public static SocketFactory getDefault()
From source file:jp.go.nict.langrid.management.logic.service.HttpClientUtil.java
/** * // w ww . j a va 2 s . com * */ public static HttpClient createHttpClientWithHostConfig(URL url) { HttpClient client = new HttpClient(); int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); if (port == -1) { port = 80; } } if ((url.getProtocol().equalsIgnoreCase("https")) && (sslSocketFactory != null)) { Protocol https = new Protocol("https", (ProtocolSocketFactory) new SSLSocketFactorySSLProtocolSocketFactory(sslSocketFactory), port); client.getHostConfiguration().setHost(url.getHost(), url.getPort(), https); } else { Protocol http = new Protocol("http", new SocketFactoryProtocolSocketFactory(SocketFactory.getDefault()), port); client.getHostConfiguration().setHost(url.getHost(), url.getPort(), http); } try { List<Proxy> proxies = ProxySelector.getDefault().select(url.toURI()); for (Proxy p : proxies) { if (p.equals(Proxy.NO_PROXY)) continue; if (!p.type().equals(Proxy.Type.HTTP)) continue; InetSocketAddress addr = (InetSocketAddress) p.address(); client.getHostConfiguration().setProxy(addr.getHostName(), addr.getPort()); break; } } catch (URISyntaxException e) { e.printStackTrace(); } return client; }
From source file:org.mariotaku.twidere.util.net.HostResolvedSocketFactory.java
public HostResolvedSocketFactory(HostAddressResolver resolver) { defaultFactory = SocketFactory.getDefault(); this.resolver = resolver; }
From source file:eu.stratosphere.nephele.net.NetUtils.java
public static SocketFactory getDefaultSocketFactory() { return SocketFactory.getDefault(); }
From source file:net.javacrumbs.mocksocket.SampleTest.java
@Test public void testResponse() throws Exception { byte[] mockData = new byte[] { 1, 2, 3, 4 }; expectCall().andReturn(data(mockData)); Socket socket = SocketFactory.getDefault().createSocket("example.org", 1234); byte[] data = IOUtils.toByteArray(socket.getInputStream()); socket.close();/*from w w w. java 2 s . co m*/ assertThat(data, is(mockData)); }
From source file:jp.go.nict.langrid.servicesupervisor.invocationprocessor.executor.intragrid.HttpClientUtil.java
/** * //from w ww .ja v a 2 s .c o m * */ public static HttpClient createHttpClientWithHostConfig(URL url) { HttpClient client = new HttpClient(); int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); if (port == -1) { port = 80; } } if ((url.getProtocol().equalsIgnoreCase("https")) && (sslSocketFactory != null)) { Protocol https = new Protocol("https", (ProtocolSocketFactory) new SSLSocketFactorySSLProtocolSocketFactory(sslSocketFactory), port); client.getHostConfiguration().setHost(url.getHost(), url.getPort(), https); } else { Protocol http = new Protocol("http", new SocketFactoryProtocolSocketFactory(SocketFactory.getDefault()), port); client.getHostConfiguration().setHost(url.getHost(), url.getPort(), http); } try { List<Proxy> proxies = ProxySelector.getDefault().select(url.toURI()); for (Proxy p : proxies) { if (p.equals(Proxy.NO_PROXY)) continue; if (!p.type().equals(Proxy.Type.HTTP)) continue; InetSocketAddress addr = (InetSocketAddress) p.address(); client.getHostConfiguration().setProxy(addr.getHostName(), addr.getPort()); client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials("", "")); break; } } catch (URISyntaxException e) { e.printStackTrace(); } return client; }
From source file:com.asksunny.tool.RemoteDataStreamer.java
public void send() throws Exception { try (Socket client = SocketFactory.getDefault().createSocket(getHost(), getPort()); OutputStream out = client.getOutputStream(); FileInputStream fin = new FileInputStream(getFilePath())) { StreamCopier.copy(fin, out);/* www.j a va 2 s . com*/ } }
From source file:com.googlecode.jcimd.TcpNetConnectionFactory.java
@Override public Connection getConnection() throws Exception { Socket socket = SocketFactory.getDefault().createSocket(); if (logger.isDebugEnabled()) { logger.debug("Connecting to [" + host + ":" + port + "]..."); }/*from w w w . j ava 2s. co m*/ socket.connect(new InetSocketAddress(this.host, this.port), 2000); if (logger.isDebugEnabled()) { logger.debug("Connected to [" + host + ":" + port + "]"); } if (this.timeout > 0) { socket.setSoTimeout(this.timeout); } PacketSerializer serializer = new PacketSerializer(); serializer.setSequenceNumberGenerator(new ApplicationPacketSequenceNumberGenerator()); TcpNetConnection newConnection = new TcpNetConnection(socket, serializer, this.username, this.password); this.executor.execute(newConnection); newConnection.login(); return newConnection; }
From source file:net.javacrumbs.mocksocket.SampleTest.java
@Test public void testMultiple() throws Exception { byte[] mockData1 = new byte[] { 1, 2, 3, 4 }; byte[] mockData2 = new byte[] { 1, 2, 3, 4 }; expectCall().andReturn(data(mockData1)).andReturn(data(mockData2)); Socket socket1 = SocketFactory.getDefault().createSocket("example.org", 1234); byte[] data1 = IOUtils.toByteArray(socket1.getInputStream()); socket1.close();/*from w w w .j a v a2s . c o m*/ assertThat(data1, is(mockData1)); Socket socket2 = SocketFactory.getDefault().createSocket("example.org", 1234); byte[] data2 = IOUtils.toByteArray(socket2.getInputStream()); socket2.close(); assertThat(data2, is(mockData2)); }
From source file:com.asksunny.tool.RemoteDataStreamer.java
public void sendCompress() throws Exception { try (Socket client = SocketFactory.getDefault().createSocket(getHost(), getPort()); OutputStream out = client.getOutputStream(); GZIPOutputStream gout = new GZIPOutputStream(out); FileInputStream fin = new FileInputStream(getFilePath())) { StreamCopier.copy(fin, gout);/* w w w .ja v a 2s . c om*/ } }
From source file:org.eclipse.thym.core.engine.internal.cordova.NpmBasedEngineRepoProvider.java
private InputStream getRemoteJSonStream(String url) throws IOException { try {//ww w . ja va 2s . c o m // SSLSocketFactory to patch HTTPClient's that are earlier than 4.3.2 // to enable SNI support. SSLSocketFactory factory = new SSLSocketFactory(SSLContext.getDefault()) { @Override public Socket createSocket() throws IOException { return SocketFactory.getDefault().createSocket(); } @Override public Socket createSocket(HttpParams params) throws IOException { return SocketFactory.getDefault().createSocket(); } }; DefaultHttpClient client = new DefaultHttpClient(); HttpUtil.setupProxy(client); client.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, factory)); HttpGet get = new HttpGet(url); HttpResponse response = client.execute(get); HttpEntity entity = response.getEntity(); return entity.getContent(); } catch (NoSuchAlgorithmException e) { HybridCore.log(IStatus.ERROR, "Error creating the SSL Factory ", e); } return null; }