use of org.jboss.as.model.test.ChildFirstClassLoaderBuilder in project wildfly by wildfly.
the class ClientCompatibilityUnitTestCase method createClient.
protected static ModelControllerClient createClient(final String artifact, final String version, final String host, final int port) throws Exception {
final ChildFirstClassLoaderBuilder classLoaderBuilder = new ChildFirstClassLoaderBuilder(false);
classLoaderBuilder.addRecursiveMavenResourceURL(artifact + ":" + version, excludes);
classLoaderBuilder.addParentFirstClassPattern("org.jboss.as.controller.client.ModelControllerClientConfiguration");
classLoaderBuilder.addParentFirstClassPattern("org.jboss.as.controller.client.ModelControllerClient");
classLoaderBuilder.addParentFirstClassPattern("org.jboss.as.controller.client.OperationMessageHandler");
classLoaderBuilder.addParentFirstClassPattern("org.jboss.as.controller.client.Operation");
classLoaderBuilder.addParentFirstClassPattern("org.jboss.as.controller.client.OperationResponse*");
final ClassLoader classLoader = classLoaderBuilder.build();
final Class<?> factoryClass = classLoader.loadClass("org.jboss.as.controller.client.ModelControllerClient$Factory");
final Method factory = factoryClass.getMethod("create", String.class, int.class);
try {
final Object client = factory.invoke(null, host, port);
final InvocationHandler invocationHandler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return method.invoke(client, args);
}
};
final Class<?>[] interfaces = new Class<?>[] { ModelControllerClient.class };
return (ModelControllerClient) Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
} catch (InvocationTargetException e) {
Throwable t = e.getCause();
if (t == null) {
throw e;
}
throw t instanceof Exception ? (Exception) t : new RuntimeException(t);
}
}
Aggregations