use of org.jvnet.hk2.config.Attribute in project Payara by payara.
the class WebContainer method updateHost.
/**
* Updates a virtual-server element.
*
* @param vsBean the virtual-server config bean.
*/
public void updateHost(com.sun.enterprise.config.serverbeans.VirtualServer vsBean) throws LifecycleException {
if (org.glassfish.api.web.Constants.ADMIN_VS.equals(vsBean.getId())) {
return;
}
final VirtualServer vs = (VirtualServer) getEngine().findChild(vsBean.getId());
if (vs == null) {
logger.log(Level.WARNING, LogFacade.CANNOT_UPDATE_NON_EXISTENCE_VS, vsBean.getId());
return;
}
boolean updateListeners = false;
// Only update connectors if virtual-server.http-listeners is changed dynamically
if (vs.getNetworkListeners() == null) {
if (vsBean.getNetworkListeners() == null) {
updateListeners = false;
} else {
updateListeners = true;
}
} else if (vs.getNetworkListeners().equals(vsBean.getNetworkListeners())) {
updateListeners = false;
} else {
List<String> vsList = StringUtils.parseStringList(vs.getNetworkListeners(), ",");
List<String> vsBeanList = StringUtils.parseStringList(vsBean.getNetworkListeners(), ",");
for (String vsBeanName : vsBeanList) {
if (!vsList.contains(vsBeanName)) {
updateListeners = true;
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogFacade.UPDATE_LISTENER, new Object[] { vsBeanName, vs.getNetworkListeners() });
}
break;
}
}
}
// Must retrieve the old default-web-module before updating the
// virtual server with the new vsBean, because default-web-module is
// read from vsBean
String oldDefaultWebModule = vs.getDefaultWebModuleID();
vs.setBean(vsBean);
String vsLogFile = vsBean.getLogFile();
vs.setLogFile(vsLogFile, logLevel, logServiceFile);
vs.configureState();
vs.clearAliases();
vs.configureAliases();
// support both docroot property and attribute
String docroot = vsBean.getPropertyValue("docroot");
if (docroot == null) {
docroot = vsBean.getDocroot();
}
if (docroot != null) {
// Only update docroot if it is modified
if (!vs.getDocRoot().getAbsolutePath().equals(docroot)) {
updateDocroot(docroot, vs, vsBean);
}
}
List<Property> props = vs.getProperties();
for (Property prop : props) {
updateHostProperties(vsBean, prop.getName(), prop.getValue(), securityService, vs);
}
vs.configureSingleSignOn(globalSSOEnabled, webContainerFeatureFactory, isSsoFailoverEnabled());
vs.reconfigureAccessLog(globalAccessLogBufferSize, globalAccessLogWriteInterval, habitat, domain, globalAccessLoggingEnabled);
// old listener names
List<String> oldListenerList = StringUtils.parseStringList(vsBean.getNetworkListeners(), ",");
String[] oldListeners = (oldListenerList != null) ? oldListenerList.toArray(new String[oldListenerList.size()]) : new String[0];
// new listener config
HashSet<NetworkListener> networkListeners = new HashSet<NetworkListener>();
if (oldListenerList != null) {
for (String listener : oldListeners) {
boolean found = false;
for (NetworkListener httpListener : serverConfig.getNetworkConfig().getNetworkListeners().getNetworkListener()) {
if (httpListener.getName().equals(listener)) {
networkListeners.add(httpListener);
found = true;
break;
}
}
if (!found) {
String msg = rb.getString(LogFacade.LISTENER_REFERENCED_BY_HOST_NOT_EXIST);
msg = MessageFormat.format(msg, listener, vs.getName());
logger.log(Level.SEVERE, msg);
}
}
// Update the port numbers with which the virtual server is
// associated
configureHostPortNumbers(vs, networkListeners);
} else {
// The virtual server is not associated with any http listeners
vs.setNetworkListenerNames(new String[0]);
}
// have been removed from its http-listeners attribute
for (String oldListener : oldListeners) {
boolean found = false;
for (NetworkListener httpListener : networkListeners) {
if (httpListener.getName().equals(oldListener)) {
found = true;
}
}
if (!found) {
// http listener was removed
Connector[] connectors = _embedded.findConnectors();
for (Connector connector : connectors) {
WebConnector conn = (WebConnector) connector;
if (oldListener.equals(conn.getName())) {
try {
conn.getMapperListener().unregisterHost(vs.getJmxName());
} catch (Exception e) {
throw new LifecycleException(e);
}
}
}
}
}
// have been added to its http-listeners attribute
for (NetworkListener httpListener : networkListeners) {
boolean found = false;
for (String oldListener : oldListeners) {
if (httpListener.getName().equals(oldListener)) {
found = true;
}
}
if (!found) {
// http listener was added
Connector[] connectors = _embedded.findConnectors();
for (Connector connector : connectors) {
WebConnector conn = (WebConnector) connector;
if (httpListener.getName().equals(conn.getName())) {
if (!conn.isAvailable()) {
conn.start();
}
try {
conn.getMapperListener().registerHost(vs);
} catch (Exception e) {
throw new LifecycleException(e);
}
}
}
}
}
// passing in "null" as the default context path
if (oldDefaultWebModule != null) {
updateDefaultWebModule(vs, oldListeners, null);
}
/*
* Add default web module if one has been configured for the
* virtual server. If the module declared as the default web module
* has already been deployed at the root context, we don't have
* to do anything.
*/
WebModuleConfig wmInfo = vs.getDefaultWebModule(domain, habitat.<WebArchivist>getService(WebArchivist.class), appRegistry);
if ((wmInfo != null) && (wmInfo.getContextPath() != null) && !"".equals(wmInfo.getContextPath()) && !"/".equals(wmInfo.getContextPath())) {
// Remove dummy context that was created off of docroot, if such
// a context exists
removeDummyModule(vs);
updateDefaultWebModule(vs, vs.getNetworkListenerNames(), wmInfo);
} else {
WebModuleConfig wmc = vs.createSystemDefaultWebModuleIfNecessary(habitat.<WebArchivist>getService(WebArchivist.class));
if (wmc != null) {
loadStandaloneWebModule(vs, wmc);
}
}
if (updateListeners) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogFacade.VS_UPDATED_NETWORK_LISTENERS, new Object[] { vs.getName(), vs.getNetworkListeners(), vsBean.getNetworkListeners() });
}
/*
* Need to update connector and mapper restart is required
* when virtual-server.http-listeners is changed dynamically
*/
List<NetworkListener> httpListeners = serverConfig.getNetworkConfig().getNetworkListeners().getNetworkListener();
if (httpListeners != null) {
for (NetworkListener httpListener : httpListeners) {
updateConnector(httpListener, habitat.<HttpService>getService(HttpService.class));
}
}
}
}
use of org.jvnet.hk2.config.Attribute in project Payara by payara.
the class CompositeUtil method analyzeInterface.
private void analyzeInterface(Class<?> iface, Map<String, Map<String, Object>> properties) throws SecurityException {
// find class level bean reference
String defaultBean = null;
if (iface.isAnnotationPresent(DefaultBeanReference.class)) {
DefaultBeanReference beanRef = iface.getAnnotation(DefaultBeanReference.class);
defaultBean = beanRef.bean();
}
for (Method method : iface.getMethods()) {
String name = method.getName();
final boolean isGetter = name.startsWith("get");
if (isGetter || name.startsWith("set")) {
name = name.substring(3);
Map<String, Object> property = properties.get(name);
if (property == null) {
property = new HashMap<String, Object>();
properties.put(name, property);
}
String bean = null;
String attribute = null;
AttributeReference ar = method.getAnnotation(AttributeReference.class);
if (ar != null) {
bean = ar.bean();
attribute = ar.attribute();
}
if (!StringUtil.notEmpty(bean)) {
bean = defaultBean;
}
if (!StringUtil.notEmpty(attribute)) {
attribute = name;
}
if (StringUtil.notEmpty(bean) && StringUtil.notEmpty(attribute)) {
property.put("annotations", gatherReferencedAttributes(bean, attribute));
}
Attribute attr = method.getAnnotation(Attribute.class);
if (attr != null) {
property.put("defaultValue", attr.defaultValue());
}
Class<?> type = isGetter ? method.getReturnType() : method.getParameterTypes()[0];
property.put("type", type);
}
}
}
use of org.jvnet.hk2.config.Attribute in project Payara by payara.
the class ParamMetadata method getDefaultValue.
/**
* This method will process the annotations for a field to try to determine the default value, if one has been specified.
* @param annos
* @return
*/
private JsonValue getDefaultValue(Annotation[] annos) {
Object defval = null;
if (annos != null) {
for (Annotation annotation : annos) {
if (Default.class.isAssignableFrom(annotation.getClass())) {
try {
Default def = (Default) annotation;
Class clazz = def.generator();
if (def.useContext()) {
defval = ((DefaultsGenerator) context).getDefaultValue(name);
} else if (clazz != null && clazz != Void.class) {
if (DefaultsGenerator.class.isAssignableFrom(clazz)) {
defval = ((DefaultsGenerator) clazz.newInstance()).getDefaultValue(name);
} else {
RestLogging.restLogger.log(Level.SEVERE, RestLogging.DOESNT_IMPLEMENT_DEFAULTS_GENERATOR);
}
} else {
defval = parseValue(def.value());
}
break;
} catch (Exception ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
}
} else if (Attribute.class.isAssignableFrom(annotation.getClass())) {
Attribute attr = (Attribute) annotation;
defval = attr.defaultValue();
break;
}
}
}
try {
return JsonUtil.getJsonValue(defval);
} catch (JsonException e) {
return null;
}
}
use of org.jvnet.hk2.config.Attribute in project Payara by payara.
the class ClientGenerator method processAttributes.
protected void processAttributes(ClientClassWriter writer, ConfigModel model, Set<String> processed) {
Class clazz = model.getProxyType();
for (Method method : clazz.getMethods()) {
String methodName = method.getName();
Attribute a = method.getAnnotation(Attribute.class);
Param p = method.getAnnotation(Param.class);
if ((a != null) || (p != null)) {
String type = "String";
if (a != null) {
type = a.dataType().getName();
}
if (methodName.startsWith("get") || methodName.startsWith("set")) {
methodName = methodName.substring(3);
}
String fieldName = Util.lowerCaseFirstLetter(methodName);
if (processed.contains(fieldName)) {
continue;
}
processed.add(fieldName);
writer.generateGettersAndSetters(type, methodName, fieldName);
}
}
}
use of org.jvnet.hk2.config.Attribute in project Payara by payara.
the class DefaultValueTest method rawAttributeTest.
@Test
public void rawAttributeTest() throws NoSuchMethodException {
String address = listener.getAddress();
Dom raw = Dom.unwrap(listener);
Attribute attr = raw.getProxyType().getMethod("getAddress").getAnnotation(Attribute.class);
assertEquals(attr.defaultValue(), address);
assertEquals(raw.attribute("address"), address);
assertEquals(raw.rawAttribute("address"), address);
}
Aggregations