use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class ReferenceConstrainTest method serverConfigRefValid.
@Test
public void serverConfigRefValid() 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");
changes.put(serverConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
} catch (TransactionFailure tf) {
fail("Can not reach this point");
}
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class ReferenceConstrainTest method jmxConnectorAuthRealmRefValid.
@Test
public void jmxConnectorAuthRealmRefValid() 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", "file");
changes.put(serverConfig, configChanges);
try {
ConfigSupport cs = getHabitat().getService(ConfigSupport.class);
cs.apply(changes);
} catch (TransactionFailure tf) {
fail("Can not reach this point");
}
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class CommandResourceMetaData method getRestRedirectPointToBean.
@SuppressWarnings("unchecked")
public static List<CommandResourceMetaData> getRestRedirectPointToBean(String beanName) {
synchronized (restRedirects) {
if (restRedirects.isEmpty()) {
final ServiceLocator habitat = Globals.getDefaultHabitat();
processConfigBeans(habitat);
List<ActiveDescriptor<?>> iter = habitat.getDescriptors(BuilderHelper.createContractFilter(AdminCommand.class.getName()));
for (ActiveDescriptor<?> ad : iter) {
if (!(ad.getQualifiers().contains(RestEndpoints.class.getName()))) {
continue;
}
if (!ad.isReified()) {
try {
habitat.reifyDescriptor(ad);
} catch (MultiException me) {
// If we can't see the command, forget it
continue;
}
}
final Class<? extends AdminCommand> clazz = (Class<? extends AdminCommand>) ad.getImplementationClass();
RestEndpoints endpoints = clazz.getAnnotation(RestEndpoints.class);
if (endpoints != null) {
RestEndpoint[] list = endpoints.value();
if ((list != null) && (list.length > 0)) {
for (RestEndpoint endpoint : list) {
Service service = clazz.getAnnotation(Service.class);
String configBean = endpoint.configBean().getSimpleName();
CommandResourceMetaData metaData = new CommandResourceMetaData();
metaData.command = service.name();
metaData.httpMethod = endpoint.opType().name();
metaData.resourcePath = endpoint.path().isEmpty() ? service.name() : endpoint.path();
metaData.displayName = endpoint.description().isEmpty() ? metaData.resourcePath : endpoint.description();
metaData.commandParams = new ParameterMetaData[endpoint.params().length];
int index = 0;
for (RestParam param : endpoint.params()) {
ParameterMetaData currentParam = new ParameterMetaData();
metaData.commandParams[index] = currentParam;
currentParam.name = param.name();
currentParam.value = param.value();
index++;
}
addCommandMetaData(configBean, metaData);
}
}
}
}
}
}
return restRedirects.get(beanName);
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class TemplateRestResource method setBeanByKey.
/*
* This method is called by the ASM generated code change very carefully
*/
public void setBeanByKey(List<Dom> parentList, String id, String tag) {
this.tagName = tag;
try {
childID = URLDecoder.decode(id, "UTF-8");
} catch (UnsupportedEncodingException ex) {
childID = id;
}
if (parentList != null) {
// Believe it or not, this can happen
for (Dom c : parentList) {
String keyAttributeName = null;
ConfigModel model = c.model;
if (model.key == null) {
try {
for (String s : model.getAttributeNames()) {
// no key, by default use the name attr
if (s.equals("name")) {
keyAttributeName = s;
}
}
if (keyAttributeName == null) {
// nothing, so pick the first one
keyAttributeName = model.getAttributeNames().iterator().next();
}
} catch (Exception e) {
// no attr choice fo a key!!! Error!!!
keyAttributeName = "ThisIsAModelBug:NoKeyAttr";
}
// firstone
} else {
keyAttributeName = model.key.substring(1, model.key.length());
}
String keyvalue = c.attribute(keyAttributeName.toLowerCase(Locale.US));
if (keyvalue != null && keyvalue.equals(childID)) {
setEntity((ConfigBean) c);
}
}
}
}
use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.
the class TemplateRestResource method setParentAndTagName.
public void setParentAndTagName(Dom parent, String tagName) {
if (parent == null) {
// prevent https://glassfish.dev.java.net/issues/show_bug.cgi?id=14125
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
this.parent = parent;
this.tagName = tagName;
synchronized (parent) {
entity = parent.nodeElement(tagName);
}
if (entity == null) {
// In some cases, the tagName requested is not found in the DOM tree. This is true,
// for example, for the various ZeroConf elements (e.g., transaction-service). If
// the zero conf element is not in domain.xml, then it won't be in the Dom tree
// returned by HK2. If that's the case, we can use ConfigModularityUtils.getOwningObject()
// to find the ConfigBean matching the path requested, which will add the node to
// the Dom tree. Once that's done, we can return that node and proceed as normal
String location = buildPath(parent) + "/" + tagName;
if (location.startsWith("domain/configs")) {
final ConfigModularityUtils cmu = locatorBridge.getRemoteLocator().<ConfigModularityUtils>getService(ConfigModularityUtils.class);
ConfigBeanProxy cbp = cmu.getOwningObject(location);
if (cbp == null) {
cbp = cmu.getConfigBeanInstanceFor(cmu.getOwningClassForLocation(location));
}
if (cbp != null) {
entity = Dom.unwrap(cbp);
childModel = entity.model;
}
}
// throw new WebApplicationException(new Exception("Trying to create an entity using generic create"),Response.Status.INTERNAL_SERVER_ERROR);
} else {
childModel = entity.model;
}
}
Aggregations