@@ -63,21 +63,29 @@ public <T> T create(Class<T> clientInterface) {
6363 if (apiProvider != null ) {
6464 return apiProvider .provide (this );
6565 }
66- String implClassName = clientImplementationClassName (clientInterface );
6766 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 );
7270 } 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 );
7473 }
7574 }
7675
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 ) {
7886 String packageName = clientInterface .getPackageName ();
7987 String simpleName = clientInterface .getSimpleName ();
80- return packageName + ".httpclient." + simpleName + "$HttpClient" ;
88+ return packageName + ".httpclient." + simpleName + suffix ;
8189 }
8290
8391 @ Override
0 commit comments