< prev index next >

src/java.base/share/classes/java/net/HttpConnectSocketImpl.java

Print this page

        

*** 23,49 **** * questions. */ package java.net; import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import java.util.Set; /** * Basic SocketImpl that relies on the internal HTTP protocol handler * implementation to perform the HTTP tunneling and authentication. The * sockets impl is swapped out and replaced with the socket from the HTTP * handler after the tunnel is successfully setup. * * @since 1.8 */ ! /*package*/ class HttpConnectSocketImpl extends PlainSocketImpl { private static final String httpURLClazzStr = "sun.net.www.protocol.http.HttpURLConnection"; private static final String netClientClazzStr = "sun.net.NetworkClient"; private static final String doTunnelingStr = "doTunneling"; --- 23,54 ---- * questions. */ package java.net; + import java.io.FileDescriptor; import java.io.IOException; + import java.io.InputStream; + import java.io.OutputStream; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import java.util.Set; + import sun.nio.ch.NioSocketImpl; + /** * Basic SocketImpl that relies on the internal HTTP protocol handler * implementation to perform the HTTP tunneling and authentication. The * sockets impl is swapped out and replaced with the socket from the HTTP * handler after the tunnel is successfully setup. * * @since 1.8 */ ! /*package*/ class HttpConnectSocketImpl extends DelegatingSocketImpl { private static final String httpURLClazzStr = "sun.net.www.protocol.http.HttpURLConnection"; private static final String netClientClazzStr = "sun.net.NetworkClient"; private static final String doTunnelingStr = "doTunneling";
*** 73,99 **** }); } catch (ReflectiveOperationException x) { throw new InternalError("Should not reach here", x); } } ! ! HttpConnectSocketImpl(String server, int port) { ! this.server = server; ! this.port = port; } ! HttpConnectSocketImpl(Proxy proxy) { SocketAddress a = proxy.address(); if ( !(a instanceof InetSocketAddress) ) throw new IllegalArgumentException("Unsupported address type"); InetSocketAddress ad = (InetSocketAddress) a; server = ad.getHostString(); port = ad.getPort(); } @Override protected void connect(SocketAddress endpoint, int timeout) throws IOException { if (endpoint == null || !(endpoint instanceof InetSocketAddress)) throw new IllegalArgumentException("Unsupported address type"); --- 78,126 ---- }); } catch (ReflectiveOperationException x) { throw new InternalError("Should not reach here", x); } } ! HttpConnectSocketImpl(SocketImpl delegate) { ! super(delegate); ! this.server = null; ! throw new InternalError(); } ! HttpConnectSocketImpl(Proxy proxy, SocketImpl delegate) { ! super(delegate); SocketAddress a = proxy.address(); if ( !(a instanceof InetSocketAddress) ) throw new IllegalArgumentException("Unsupported address type"); InetSocketAddress ad = (InetSocketAddress) a; server = ad.getHostString(); port = ad.getPort(); } @Override + protected void connect(String host, int port) throws IOException { + connect(new InetSocketAddress(host, port), 0); + } + + @Override + protected void connect(InetAddress address, int port) throws IOException { + connect(new InetSocketAddress(address, port), 0); + } + + @Override + void setSocket(Socket socket) { + delegate.socket = socket; + super.setSocket(socket); + } + + @Override + void setServerSocket(ServerSocket socket) { + throw new InternalError("should not get here"); + } + + @Override protected void connect(SocketAddress endpoint, int timeout) throws IOException { if (endpoint == null || !(endpoint instanceof InetSocketAddress)) throw new IllegalArgumentException("Unsupported address type");
*** 115,139 **** // close the original socket impl and release its descriptor close(); // update the Sockets impl to the impl from the http Socket ! AbstractPlainSocketImpl psi = (AbstractPlainSocketImpl) httpSocket.impl; ! this.getSocket().impl = psi; // best effort is made to try and reset options previously set Set<Map.Entry<Integer,Object>> options = optionsMap.entrySet(); try { for(Map.Entry<Integer,Object> entry : options) { ! psi.setOption(entry.getKey(), entry.getValue()); } } catch (IOException x) { /* gulp! */ } } @Override public void setOption(int opt, Object val) throws SocketException { ! super.setOption(opt, val); if (external_address != null) return; // we're connected, just return // store options so that they can be re-applied to the impl after connect --- 142,182 ---- // close the original socket impl and release its descriptor close(); // update the Sockets impl to the impl from the http Socket ! SocketImpl si = httpSocket.impl; ! ((SocketImpl) this).getSocket().setImpl(si); // best effort is made to try and reset options previously set Set<Map.Entry<Integer,Object>> options = optionsMap.entrySet(); try { for(Map.Entry<Integer,Object> entry : options) { ! si.setOption(entry.getKey(), entry.getValue()); } } catch (IOException x) { /* gulp! */ } } + + @Override + protected void listen(int backlog) { + throw new InternalError("should not get here"); + } + + @Override + protected void accept(SocketImpl s) { + throw new InternalError("should not get here"); + } + + @Override + void reset() throws IOException { + delegate.reset(); + } + @Override public void setOption(int opt, Object val) throws SocketException { ! delegate.setOption(opt, val); if (external_address != null) return; // we're connected, just return // store options so that they can be re-applied to the impl after connect
*** 161,171 **** { Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(server, port)); URL destURL = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) destURL.openConnection(proxy); conn.setConnectTimeout(connectTimeout); ! conn.setReadTimeout(this.timeout); conn.connect(); doTunneling(conn); try { Object httpClient = httpField.get(conn); return (Socket) serverSocketField.get(httpClient); --- 204,217 ---- { Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(server, port)); URL destURL = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) destURL.openConnection(proxy); conn.setConnectTimeout(connectTimeout); ! int timeout = (int) getOption(SocketOptions.SO_TIMEOUT); ! if (timeout > 0) { ! conn.setReadTimeout(timeout); ! } conn.connect(); doTunneling(conn); try { Object httpClient = httpField.get(conn); return (Socket) serverSocketField.get(httpClient);
*** 185,200 **** @Override protected InetAddress getInetAddress() { if (external_address != null) return external_address.getAddress(); else ! return super.getInetAddress(); } @Override protected int getPort() { if (external_address != null) return external_address.getPort(); else ! return super.getPort(); } } --- 231,246 ---- @Override protected InetAddress getInetAddress() { if (external_address != null) return external_address.getAddress(); else ! return delegate.getInetAddress(); } @Override protected int getPort() { if (external_address != null) return external_address.getPort(); else ! return delegate.getPort(); } }
< prev index next >