use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class TransactionCallBackTest method doTest.
public void doTest() throws TransactionFailure {
ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(habitat.<NetworkListeners>getService(NetworkListeners.class));
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("name", "funky-listener");
ConfigSupport.createAndSet(serviceBean, NetworkListener.class, configChanges, new TransactionCallBack<WriteableView>() {
@SuppressWarnings({ "unchecked" })
public void performOn(WriteableView param) throws TransactionFailure {
// if you know the type...
NetworkListener listener = param.getProxy(NetworkListener.class);
listener.setName("Aleksey");
// if you don't know the type
Method m;
try {
m = param.getProxyType().getMethod("setAddress", String.class);
m.invoke(param.getProxy(param.getProxyType()), "localhost");
} catch (NoSuchMethodException e) {
throw new TransactionFailure("Cannot find getProperty method", e);
} catch (IllegalAccessException e) {
throw new TransactionFailure("Cannot call getProperty method", e);
} catch (InvocationTargetException e) {
throw new TransactionFailure("Cannot call getProperty method", e);
}
}
});
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class ReferenceConstrainClusterTest method clusterServerRefInvalid.
@Test
public void clusterServerRefInvalid() throws TransactionFailure {
Cluster cluster = habitat.getService(Cluster.class, "clusterA");
assertNotNull(cluster);
ServerRef sref = cluster.getServerRef().get(0);
ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(sref);
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("ref", "server-nonexist");
changes.put(serverConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
fail("Can not reach this point");
} catch (TransactionFailure tf) {
ConstraintViolationException cv = findConstrViolation(tf);
assertNotNull(cv);
}
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class ReferenceConstrainTest method jmxConnectorAuthRealmRefInvalid.
@Test
public void jmxConnectorAuthRealmRefInvalid() throws TransactionFailure {
JmxConnector jmxConnector = habitat.getService(JmxConnector.class, "system");
assertNotNull(jmxConnector);
ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(jmxConnector);
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("auth-realm-name", "realm-not-exist");
changes.put(serverConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
fail("Can not reach this point");
} catch (TransactionFailure tf) {
ConstraintViolationException cv = findConstrViolation(tf);
assertNotNull(cv);
}
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class ReferenceConstrainTest method serverConfigRefInvalid.
@Test
public void serverConfigRefInvalid() throws TransactionFailure {
Server server = habitat.getService(Server.class, "server");
assertNotNull(server);
ConfigBean serverConfig = (ConfigBean) ConfigBean.unwrap(server);
Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
Map<String, String> configChanges = new HashMap<String, String>();
configChanges.put("config-ref", "server-config-nonexist");
changes.put(serverConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
fail("Can not reach this point");
} catch (TransactionFailure tf) {
ConstraintViolationException cv = findConstrViolation(tf);
assertNotNull(cv);
}
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class ResourceUtil method getMethodMetaData2.
public static MethodMetaData getMethodMetaData2(Dom parent, ConfigModel childModel, int parameterType) {
MethodMetaData methodMetaData = new MethodMetaData();
List<Class<?>> interfaces = new ArrayList<Class<?>>();
Map<String, ParameterMetaData> params = new HashMap<String, ParameterMetaData>();
try {
Class<? extends ConfigBeanProxy> configBeanProxy = (Class<? extends ConfigBeanProxy>) childModel.classLoaderHolder.loadClass(childModel.targetTypeName);
getInterfaces(configBeanProxy, interfaces);
Set<String> attributeNames = childModel.getAttributeNames();
for (String attributeName : attributeNames) {
String methodName = ResourceUtil.getAttributeMethodName(attributeName);
// camelCase the attributeName before passing out
attributeName = Util.eleminateHypen(attributeName);
ParameterMetaData parameterMetaData = params.get(attributeName);
if (parameterMetaData == null) {
parameterMetaData = new ParameterMetaData();
params.put(attributeName, parameterMetaData);
}
// Check parent interfaces
for (int i = interfaces.size() - 1; i >= 0; i--) {
Class<?> intf = interfaces.get(i);
try {
Method method = intf.getMethod(methodName);
Attribute attribute = method.getAnnotation(Attribute.class);
if (attribute != null) {
ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
}
} catch (NoSuchMethodException e) {
}
}
// Check ConfigBean
try {
Method method = configBeanProxy.getMethod(methodName);
Attribute attribute = method.getAnnotation(Attribute.class);
if (attribute != null) {
ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
}
} catch (NoSuchMethodException e) {
}
methodMetaData.putParameterMetaData(attributeName, parameterMetaData);
}
} catch (MultiException cnfe) {
throw new RuntimeException(cnfe);
}
return methodMetaData;
}
Aggregations