test/jdk/java/net/Socket/HttpProxy.java
changeset 58108 5302477c8285
parent 54811 9db7c0f561a6
equal deleted inserted replaced
58106:79186d82463e 58108:5302477c8285
   158     void startSimpleWriter(String threadName, final OutputStream os, final int start) {
   158     void startSimpleWriter(String threadName, final OutputStream os, final int start) {
   159         (new Thread(new Runnable() {
   159         (new Thread(new Runnable() {
   160             public void run() {
   160             public void run() {
   161                 try { simpleWrite(os, start); }
   161                 try { simpleWrite(os, start); }
   162                 catch (Exception e) {unexpected(e); }
   162                 catch (Exception e) {unexpected(e); }
       
   163                 finally { out.println(threadName + ": done"); }
   163             }}, threadName)).start();
   164             }}, threadName)).start();
   164     }
   165     }
   165 
   166 
   166     void simpleWrite(OutputStream os, int start) throws Exception {
   167     void simpleWrite(OutputStream os, int start) throws Exception {
   167         byte b[] = new byte[2];
   168         byte b[] = new byte[2];
   168         for (int i=start; i<start+100; i++) {
   169         for (int i=start; i<start+100; i++) {
   169             b[0] = (byte) (i / 256);
   170             b[0] = (byte) (i / 256);
   170             b[1] = (byte) (i % 256);
   171             b[1] = (byte) (i % 256);
   171             os.write(b);
   172             os.write(b);
   172         }
   173         }
       
   174         out.println("Wrote " + start + " -> " + (start + 100));
   173     }
   175     }
   174 
   176 
   175     void simpleRead(InputStream is, int start) throws Exception {
   177     void simpleRead(InputStream is, int start) throws Exception {
   176         byte b[] = new byte [2];
   178         byte b[] = new byte [2];
   177         for (int i=start; i<start+100; i++) {
   179         for (int i=start; i<start+100; i++) {
   182                 throw new Exception("read error");
   184                 throw new Exception("read error");
   183             int r = bytes(b[0], b[1]);
   185             int r = bytes(b[0], b[1]);
   184             if (r != i)
   186             if (r != i)
   185                 throw new Exception("read " + r + " expected " +i);
   187                 throw new Exception("read " + r + " expected " +i);
   186         }
   188         }
       
   189         out.println("Read " + start + " -> " + (start + 100));
   187     }
   190     }
   188 
   191 
   189     int bytes(byte b1, byte b2) {
   192     int bytes(byte b1, byte b2) {
   190         int i1 = (int)b1 & 0xFF;
   193         int i1 = (int)b1 & 0xFF;
   191         int i2 = (int)b2 & 0xFF;
   194         int i2 = (int)b2 & 0xFF;
   247                 return;
   250                 return;
   248             }
   251             }
   249 
   252 
   250             // retrieve the host and port info from the status-line
   253             // retrieve the host and port info from the status-line
   251             InetSocketAddress serverAddr = getConnectInfo(statusLine);
   254             InetSocketAddress serverAddr = getConnectInfo(statusLine);
       
   255             out.println("Proxy serving CONNECT request to " + serverAddr);
   252 
   256 
   253             //open socket to the server
   257             //open socket to the server
   254             try (Socket serverSocket = new Socket(serverAddr.getAddress(),
   258             try (Socket serverSocket = new Socket(serverAddr.getAddress(),
   255                                                   serverAddr.getPort())) {
   259                                                   serverAddr.getPort())) {
   256                 Forwarder clientFW = new Forwarder(clientSocket.getInputStream(),
   260                 Forwarder clientFW = new Forwarder(clientSocket.getInputStream(),