File tree Expand file tree Collapse file tree 4 files changed +50
-2
lines changed
src/main/java/tech/httptoolkit/javaagent/advice/apacheclient
src/main/java/tech/httptoolkit/testapp Expand file tree Collapse file tree 4 files changed +50
-2
lines changed Original file line number Diff line number Diff line change 4
4
5
5
import javax .net .ssl .SSLContext ;
6
6
import java .lang .reflect .Field ;
7
- import java .security .NoSuchAlgorithmException ;
8
7
import java .util .Arrays ;
9
8
10
9
public class ApacheSetSslSocketFactoryAdvice {
@@ -17,7 +16,7 @@ public static void beforeCreateSocket(@Advice.This Object thisFactory) throws Ex
17
16
for (String factoryFieldName : Arrays .asList ("socketfactory" , "socketFactory" )) {
18
17
try {
19
18
// Detect which field(s) are present on this class
20
- Field field = thisFactory .getClass (). getDeclaredField ( factoryFieldName );
19
+ Field field = getDeclaredFieldInClassTree ( thisFactory .getClass (), factoryFieldName );
21
20
22
21
// Allow ourselves to change the socket factory value
23
22
field .setAccessible (true );
@@ -32,4 +31,14 @@ public static void beforeCreateSocket(@Advice.This Object thisFactory) throws Ex
32
31
throw new IllegalStateException ("Apache HttpClient interception setup failed" );
33
32
}
34
33
}
34
+
35
+ public static Field getDeclaredFieldInClassTree (Class <?> type , String fieldName ) throws NoSuchFieldException {
36
+ for (Class <?> clazz = type ; clazz != null ; clazz = clazz .getSuperclass ()) {
37
+ try {
38
+ return clazz .getDeclaredField (fieldName );
39
+ } catch (NoSuchFieldException ignored ) { }
40
+ }
41
+ throw new NoSuchFieldException ();
42
+ }
43
+
35
44
}
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ dependencies {
35
35
36
36
implementation group : ' io.vertx' , name : ' vertx-core' , version : ' 4.2.2'
37
37
implementation group : ' io.vertx' , name : ' vertx-web-client' , version : ' 4.2.2'
38
+
39
+ implementation group : ' org.jboss.resteasy' , name : ' resteasy-client' , version : ' 4.7.4.Final'
38
40
}
39
41
40
42
test {
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ public class Main {
17
17
private static final Map <String , ClientCase <?>> cases = Map .ofEntries (
18
18
entry ("apache-v3" , new ApacheHttpClientV3Case ()),
19
19
entry ("apache-v4" , new ApacheHttpClientV4Case ()),
20
+ entry ("rest-easy-with-apache-v4" , new RestEasyWithApacheHttpClientV4Case ()),
20
21
entry ("apache-v5" , new ApacheHttpClientV5Case ()),
21
22
entry ("apache-async-v4" , new ApacheHttpAsyncClientV4Case ()),
22
23
entry ("apache-async-v5" , new ApacheHttpAsyncClientV5Case ()),
Original file line number Diff line number Diff line change
1
+ package tech .httptoolkit .testapp .cases ;
2
+
3
+ import org .jboss .resteasy .client .jaxrs .ResteasyClient ;
4
+ import org .jboss .resteasy .client .jaxrs .engines .ClientHttpEngineBuilder43 ;
5
+ import org .jboss .resteasy .client .jaxrs .internal .ResteasyClientBuilderImpl ;
6
+
7
+ import javax .net .ssl .SSLContext ;
8
+ import java .io .IOException ;
9
+ import java .net .MalformedURLException ;
10
+ import java .net .URI ;
11
+ import java .security .NoSuchAlgorithmException ;
12
+
13
+ public class RestEasyWithApacheHttpClientV4Case extends ClientCase <ResteasyClient > {
14
+
15
+ @ Override
16
+ public ResteasyClient newClient (String url ) throws MalformedURLException {
17
+ ResteasyClientBuilderImpl resteasyClientBuilder = new ResteasyClientBuilderImpl ();
18
+ resteasyClientBuilder .sslContext (getSslContext ());
19
+ resteasyClientBuilder .httpEngine (new ClientHttpEngineBuilder43 ()
20
+ .resteasyClientBuilder (resteasyClientBuilder ).build ());
21
+ return resteasyClientBuilder .build ();
22
+ }
23
+
24
+ @ Override
25
+ public int test (String url , ResteasyClient resteasyClient ) throws IOException {
26
+ return resteasyClient .target (URI .create (url )).request ().get ().getStatus ();
27
+ }
28
+
29
+ private SSLContext getSslContext () {
30
+ try {
31
+ return SSLContext .getDefault ();
32
+ } catch (NoSuchAlgorithmException e ) {
33
+ throw new IllegalStateException (e );
34
+ }
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments