@@ -99,75 +99,33 @@ private void handleSession(Connection CONNECTION, CurrentConnections CONNECTIONS
9999
100100 if (BUFFER .length () == 0 ) return ;
101101
102- // 2. Spawn per-session telnet subprocess, forward request, stream response back
103- ProcessBuilder PER_PB = new ProcessBuilder (WebExpress .TELNET_PROXY_SERVER_ARGS );
104- Process PER_PROC = PER_PB .start ();
105-
106- try
102+ // 2. Send a sample HTTP GET to tacobell.phd:80 and stream the reply back to the client
103+ try (java .net .Socket proxy = new java .net .Socket ())
107104 {
108- java .io .OutputStream PER_OUT = PER_PROC .getOutputStream ();
109-
110- byte [] REQUEST_BYTES = BUFFER .toString ().getBytes ();
105+ proxy .connect (new java .net .InetSocketAddress (WebExpress .REMOTE_SITE , Integer .parseInt (WebExpress .REMOTE_PORT )), PROXY_READ_TIMEOUT_MS );
106+ proxy .setSoTimeout (PROXY_READ_TIMEOUT_MS );
111107
112- PER_OUT .write (REQUEST_BYTES );
113- PER_OUT .write ('\n' );
114- PER_OUT .flush ();
108+ java .io .OutputStream proxyOut = proxy .getOutputStream ();
109+ String httpRequest = "GET / HTTP/1.0\r \n Host: " + WebExpress .REMOTE_SITE + "\r \n Connection: close\r \n \r \n " ;
110+ proxyOut .write (httpRequest .getBytes ());
111+ proxyOut .flush ();
115112
116113 CommonRails .printSystemComponent (this , this .hashCode (),
117- "WebExpress SessionHandler >> forwarded [" + REQUEST_BYTES .length + " bytes] to telnet backend." );
118-
119- java .io .InputStream PER_IN = PER_PROC .getInputStream ();
120- java .io .OutputStream CLIENT_OUT = CONNECTION .SOCKET .getOutputStream ();
121-
122- java .util .concurrent .atomic .AtomicLong LAST_READ = new java .util .concurrent .atomic .AtomicLong (-1 );
123- java .util .concurrent .atomic .AtomicBoolean FIRST_BYTE = new java .util .concurrent .atomic .AtomicBoolean (false );
124-
125- java .util .concurrent .ExecutorService EXEC = java .util .concurrent .Executors .newSingleThreadExecutor ();
126-
127- java .util .concurrent .Future <?> FUTURE = EXEC .submit (() ->
128- {
129- byte [] CHUNK = new byte [4096 ];
130- int READ ;
131-
132- try
133- {
134- while ((READ = PER_IN .read (CHUNK )) != -1 )
135- {
136- CLIENT_OUT .write (CHUNK , 0 , READ );
137- CLIENT_OUT .flush ();
138- FIRST_BYTE .set (true );
139- LAST_READ .set (System .currentTimeMillis ());
140-
141- CommonRails .printSystemComponent (this , this .hashCode (),
142- "WebExpress SessionHandler >> proxied [" + READ + " bytes] to client." );
143- }
144- }
145- catch (Exception ignored ) {}
146- });
114+ "WebExpress SessionHandler >> forwarded HTTP GET to " + WebExpress .REMOTE_SITE + ":" + WebExpress .REMOTE_PORT + "." );
147115
148- long WALL = System .currentTimeMillis () + PROXY_WALL_TIMEOUT_MS ;
116+ java .io .OutputStream clientOut = CONNECTION .SOCKET .getOutputStream ();
117+ byte [] chunk = new byte [4096 ];
118+ int read ;
119+ long deadline = System .currentTimeMillis () + PROXY_WALL_TIMEOUT_MS ;
149120
150- while (System .currentTimeMillis () < WALL )
121+ while (System .currentTimeMillis () < deadline && ( read = proxy . getInputStream (). read ( chunk )) != - 1 )
151122 {
152- if (FUTURE .isDone ()) break ;
153-
154- if (FIRST_BYTE .get ()
155- && System .currentTimeMillis () - LAST_READ .get () > PROXY_READ_TIMEOUT_MS )
156- break ;
123+ clientOut .write (chunk , 0 , read );
124+ clientOut .flush ();
157125
158- Thread .sleep (100 );
126+ CommonRails .printSystemComponent (this , this .hashCode (),
127+ "WebExpress SessionHandler >> proxied [" + read + " bytes] to client." );
159128 }
160-
161- FUTURE .cancel (true );
162- EXEC .shutdownNow ();
163-
164- CommonRails .printSystemComponent (this , this .hashCode (),
165- "WebExpress SessionHandler >> proxy read window closed for ["
166- + CONNECTION .SOCKET .getRemoteSocketAddress () + "]." );
167- }
168- finally
169- {
170- try { PER_PROC .destroyForcibly (); } catch (Exception ignored ) {}
171129 }
172130
173131 // Enqueue for MessageQueueSorter audit trail
0 commit comments