@@ -27,6 +27,37 @@ class HttpRequestExecutionThread extends Thread {
2727 protected final Integer _redirectCount ;
2828 protected HttpURLConnection _connection ;
2929
30+ protected Socket _extractConnectionSocket () {
31+ Object httpConnectionHolder = null ;
32+ try {
33+ httpConnectionHolder = ((_connection instanceof HttpsURLConnection ) ? ReflectionUtil .getValue (_connection , "delegate" ) : _connection );
34+ final Object httpClient = ReflectionUtil .getValue (httpConnectionHolder , "http" );
35+ return ReflectionUtil .getValue (httpClient , "serverSocket" );
36+ }
37+ catch (final Exception exception1 ) {
38+ if (httpConnectionHolder == null ) {
39+ throw new RuntimeException ("Unable to obtain connection socket via reflection" , exception1 );
40+ }
41+ try {
42+ // unable to get standard http server socket, check for OkHttp implementation
43+ final Object httpEngine = ReflectionUtil .getValue (httpConnectionHolder , "httpEngine" );
44+ final Object streamAllocation = ReflectionUtil .getValue (httpEngine , "streamAllocation" );
45+ final Object realConnection = ReflectionUtil .getValue (streamAllocation , "connection" );
46+ return (Socket ) ReflectionUtil .getValue (realConnection , "socket" );
47+ }
48+ catch (final Exception exception2 ) {
49+ Logger .debug ("Unable to get connection socket (1/2)" , exception1 );
50+ Logger .debug ("Unable to get connection socket (2/2)" , exception2 );
51+ throw new RuntimeException ("Unable to obtain connection socket via reflection" );
52+ }
53+ }
54+ }
55+
56+ protected void _configureRequestForWebSocketUpgrade () {
57+ _httpRequest .setAllowWebSocketUpgrade (true );
58+ _httpRequest .setHeader ("Upgrade" , "websocket" );
59+ }
60+
3061 public HttpRequestExecutionThread (final String httpRequestUrl , final HttpRequest httpRequest , final HttpRequest .Callback callback , final Integer redirectCount ) {
3162 _httpRequestUrl = httpRequestUrl ;
3263 _httpRequest = httpRequest ;
@@ -194,37 +225,6 @@ public void run() {
194225 }
195226 }
196227
197- private Socket _extractConnectionSocket () {
198- Object httpConnectionHolder = null ;
199- try {
200- httpConnectionHolder = ((_connection instanceof HttpsURLConnection ) ? ReflectionUtil .getValue (_connection , "delegate" ) : _connection );
201- final Object httpClient = ReflectionUtil .getValue (httpConnectionHolder , "http" );
202- return ReflectionUtil .getValue (httpClient , "serverSocket" );
203- }
204- catch (final Exception exception1 ) {
205- if (httpConnectionHolder == null ) {
206- throw new RuntimeException ("Unable to obtain connection socket via reflection" , exception1 );
207- }
208- try {
209- // unable to get standard http server socket, check for OkHttp implementation
210- final Object httpEngine = ReflectionUtil .getValue (httpConnectionHolder , "httpEngine" );
211- final Object streamAllocation = ReflectionUtil .getValue (httpEngine , "streamAllocation" );
212- final Object realConnection = ReflectionUtil .getValue (streamAllocation , "connection" );
213- return (Socket ) ReflectionUtil .getValue (realConnection , "socket" );
214- }
215- catch (final Exception exception2 ) {
216- Logger .debug ("Unable to get connection socket (1/2)" , exception1 );
217- Logger .debug ("Unable to get connection socket (2/2)" , exception2 );
218- throw new RuntimeException ("Unable to obtain connection socket via reflection" );
219- }
220- }
221- }
222-
223- private void _configureRequestForWebSocketUpgrade () {
224- _httpRequest .setAllowWebSocketUpgrade (true );
225- _httpRequest .setHeader ("Upgrade" , "websocket" );
226- }
227-
228228 public void cancel () {
229229 final HttpURLConnection connection = _connection ;
230230 if (connection == null ) { return ; }
0 commit comments