2323import java .lang .annotation .Annotation ;
2424import java .lang .reflect .InvocationTargetException ;
2525import java .lang .reflect .Method ;
26+ import java .net .MalformedURLException ;
27+ import java .net .URL ;
2628import java .nio .file .Files ;
2729import java .nio .file .Path ;
2830import java .nio .file .Paths ;
@@ -444,11 +446,25 @@ public void setWaitStrategy(WaitStrategy waitStrategy) {
444446 * Configures the application container with the supplied MicroProfile REST Client class that
445447 * will reference the supplied {@code hostUrl}
446448 *
447- * @param restClientClass The MicroProfile REST Client class
449+ * @param restClientClass The MicroProfile REST Client interface, which must be annotated with
450+ * <code>@RegisterRestClient</code>
448451 * @param hostUrl The URL that the {@code restClientClass} will act as a REST client for
452+ * @throws IllegalArgumentException If the provided restClientClass is not an interface or not
453+ * annotated with <code>@RegisterRestClient</code>
454+ * @throws IllegalArgumentException If hostUrl is not a valid URL
449455 * @return the current instance
450456 */
451457 public ApplicationContainer withMpRestClient (Class <?> restClientClass , String hostUrl ) {
458+ Objects .requireNonNull (restClientClass , "restClientClass must be non-null" );
459+ Objects .requireNonNull (hostUrl , "hostUrl must be non-null" );
460+ if (!restClientClass .isInterface ()) {
461+ throw new IllegalArgumentException ("Provided restClientClass " + restClientClass .getCanonicalName () + " must be an interface" );
462+ }
463+ try {
464+ new URL (hostUrl );
465+ } catch (MalformedURLException e ) {
466+ throw new IllegalArgumentException (e );
467+ }
452468 String configToken = readMpRestClientConfigKey (restClientClass );
453469 if (configToken == null || configToken .isEmpty ())
454470 configToken = restClientClass .getCanonicalName ();
@@ -467,9 +483,8 @@ private String readMpRestClientConfigKey(Class<?> restClientClass) {
467483 false ,
468484 getClass ().getClassLoader ());
469485 } catch (ClassNotFoundException | LinkageError notFound ) {
470- return null ;
486+ throw new ExtensionConfigurationException ( "Unable to load @RegisterRestClient" , notFound ) ;
471487 }
472-
473488 Method getConfigKey = null ;
474489 try {
475490 getConfigKey = RegisterRestClient .getMethod ("configKey" );
@@ -479,14 +494,16 @@ private String readMpRestClientConfigKey(Class<?> restClientClass) {
479494 }
480495
481496 Optional <Annotation > foundAnno = (Optional <Annotation >) AnnotationSupport .findAnnotation (restClientClass , RegisterRestClient );
482- if (!foundAnno .isPresent ())
483- return null ;
497+ if (!foundAnno .isPresent ()) {
498+ throw new IllegalArgumentException ("Provided restClientClass " + restClientClass + " must be annotated with "
499+ + RegisterRestClient .getSimpleName ());
500+ }
484501
485502 Annotation anno = foundAnno .get ();
486503 try {
487504 return (String ) getConfigKey .invoke (anno );
488505 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
489- return null ;
506+ throw new IllegalArgumentException ( "Unable to obtain configKey from " + anno + " found on " + restClientClass . getCanonicalName ()) ;
490507 }
491508 }
492509
@@ -496,6 +513,7 @@ private String readMpRestClientConfigKey(Class<?> restClientClass) {
496513 *
497514 * @param restClientClass The MicroProfile REST Client class
498515 * @param hostUrl The URL that the {@code restClientClass} will act as a REST client for
516+ * @throws IllegalArgumentException If hostUrl is not a valid URL
499517 * @return the current instance
500518 */
501519 public ApplicationContainer withMpRestClient (String restClientClass , String hostUrl ) {
@@ -506,6 +524,11 @@ public ApplicationContainer withMpRestClient(String restClientClass, String host
506524 } else {
507525 restClientClass += "/mp-rest/url" ;
508526 }
527+ try {
528+ new URL (hostUrl );
529+ } catch (MalformedURLException e ) {
530+ throw new IllegalArgumentException (e );
531+ }
509532 return withEnv (restClientClass , hostUrl );
510533 }
511534
0 commit comments