@@ -63,21 +63,29 @@ public <T> T create(Class<T> clientInterface) {
63
63
if (apiProvider != null ) {
64
64
return apiProvider .provide (this );
65
65
}
66
- String implClassName = clientImplementationClassName (clientInterface );
67
66
try {
68
- Class <?> serviceClass = Class .forName (implClassName );
69
- Constructor <?> constructor = serviceClass .getConstructor (HttpClientContext .class );
70
- Object service = constructor .newInstance (this );
71
- return (T ) service ;
67
+ Class <?> implementationClass = implementationClass (clientInterface );
68
+ Constructor <?> constructor = implementationClass .getConstructor (HttpClientContext .class );
69
+ return (T ) constructor .newInstance (this );
72
70
} catch (Exception e ) {
73
- throw new IllegalStateException ("Failed to create http client service " + implClassName , e );
71
+ String cn = implementationClassName (clientInterface , "HttpClient" );
72
+ throw new IllegalStateException ("Failed to create http client service " + cn , e );
74
73
}
75
74
}
76
75
77
- private <T > String clientImplementationClassName (Class <T > clientInterface ) {
76
+ private Class <?> implementationClass (Class <?> clientInterface ) throws ClassNotFoundException {
77
+ try {
78
+ return Class .forName (implementationClassName (clientInterface , "HttpClient" ));
79
+ } catch (ClassNotFoundException e ) {
80
+ // try the older generated client suffix
81
+ return Class .forName (implementationClassName (clientInterface , "$HttpClient" ));
82
+ }
83
+ }
84
+
85
+ private <T > String implementationClassName (Class <T > clientInterface , String suffix ) {
78
86
String packageName = clientInterface .getPackageName ();
79
87
String simpleName = clientInterface .getSimpleName ();
80
- return packageName + ".httpclient." + simpleName + "$HttpClient" ;
88
+ return packageName + ".httpclient." + simpleName + suffix ;
81
89
}
82
90
83
91
@ Override
0 commit comments