use of org.jvnet.hk2.config.Element in project Payara by payara.
the class ServerConfigLookup method getWebContainerAvailabilityPropertyString.
/**
* Get the String value of the property under web-container-availability
* element from domain.xml whose name matches propName
* return defaultValue if not found
* @param propName
*/
protected String getWebContainerAvailabilityPropertyString(String propName, String defaultValue) {
WebContainerAvailability wcAvailabilityBean = getWebContainerAvailability();
if (wcAvailabilityBean == null) {
return defaultValue;
}
List<Property> props = wcAvailabilityBean.getProperty();
if (props == null) {
return defaultValue;
}
for (Property prop : props) {
String name = prop.getName();
String value = prop.getValue();
if (name.equalsIgnoreCase(propName)) {
return value;
}
}
return defaultValue;
}
use of org.jvnet.hk2.config.Element in project Payara by payara.
the class VirtualServer method configureAuthRealm.
/**
* Configures this virtual server with its authentication realm.
*
* Checks if this virtual server specifies any authRealm property, and
* if so, ensures that its value identifies a valid realm.
*
* @param securityService The security-service element from domain.xml
*/
void configureAuthRealm(SecurityService securityService) {
List<Property> properties = vsBean.getProperty();
if (properties != null && properties.size() > 0) {
for (Property p : properties) {
if (p != null && "authRealm".equals(p.getName())) {
authRealmName = p.getValue();
if (authRealmName != null) {
AuthRealm realm = null;
List<AuthRealm> rs = securityService.getAuthRealm();
if (rs != null && rs.size() > 0) {
for (AuthRealm r : rs) {
if (r != null && r.getName().equals(authRealmName)) {
realm = r;
break;
}
}
}
if (realm == null) {
_logger.log(Level.SEVERE, LogFacade.INVALID_AUTH_REALM, new Object[] { getID(), authRealmName });
}
}
break;
}
}
}
}
use of org.jvnet.hk2.config.Element 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.Element in project Payara by payara.
the class WebContainer method createHost.
/**
* Creates a Host from a virtual-server config bean.
*
* @param vsBean The virtual-server configuration bean
* @param httpService The http-service element.
* @param securityService The security-service element
* @return
*/
public VirtualServer createHost(com.sun.enterprise.config.serverbeans.VirtualServer vsBean, HttpService httpService, SecurityService securityService) {
String vs_id = vsBean.getId();
String docroot = vsBean.getPropertyValue("docroot");
if (docroot == null) {
docroot = vsBean.getDocroot();
}
validateDocroot(docroot, vs_id, vsBean.getDefaultWebModule());
VirtualServer vs = createHost(vs_id, vsBean, docroot, null);
// cache control
Property cacheProp = vsBean.getProperty("setCacheControl");
if (cacheProp != null) {
vs.configureCacheControl(cacheProp.getValue());
}
PEAccessLogValve accessLogValve = vs.getAccessLogValve();
boolean startAccessLog = accessLogValve.configure(vs_id, vsBean, httpService, domain, habitat, webContainerFeatureFactory, globalAccessLogBufferSize, globalAccessLogWriteInterval);
if (startAccessLog && vs.isAccessLoggingEnabled(globalAccessLoggingEnabled)) {
vs.addValve((GlassFishValve) accessLogValve);
}
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, LogFacade.VIRTUAL_SERVER_CREATED, vs_id);
}
/*
* We must configure the Host with its associated port numbers and
* alias names before adding it as an engine child and thereby
* starting it, because a MapperListener, which is associated with
* an HTTP listener and receives notifications about Host
* registrations, relies on these Host properties in order to determine
* whether a new Host needs to be added to the HTTP listener's Mapper.
*/
configureHost(vs, securityService);
vs.setDomain(domain);
vs.setServices(habitat);
vs.setClassLoaderHierarchy(clh);
// Add Host to Engine
engine.addChild(vs);
ObservableBean virtualServerBean = (ObservableBean) ConfigSupport.getImpl(vsBean);
virtualServerBean.addListener(configListener);
return vs;
}
use of org.jvnet.hk2.config.Element in project Payara by payara.
the class JdbcConnectionPoolDeployer method getMCFConfigProperties.
/**
* Pull out the MCF configuration properties and return them as an array
* of ConnectorConfigProperty
*
* @param adminPool - The JdbcConnectionPool to pull out properties from
* @param conConnPool - ConnectorConnectionPool which will be used by Resource Pool
* @param connDesc - The ConnectorDescriptor for this JDBC RA
* @return ConnectorConfigProperty [] array of MCF Config properties specified
* in this JDBC RA
*/
private ConnectorConfigProperty[] getMCFConfigProperties(JdbcConnectionPool adminPool, ConnectorConnectionPool conConnPool, ConnectorDescriptor connDesc) {
ArrayList propList = new ArrayList();
if (adminPool.getResType() != null) {
if (ConnectorConstants.JAVA_SQL_DRIVER.equals(adminPool.getResType())) {
propList.add(new ConnectorConfigProperty("ClassName", adminPool.getDriverClassname() == null ? "" : adminPool.getDriverClassname(), "The driver class name", "java.lang.String"));
} else {
propList.add(new ConnectorConfigProperty("ClassName", adminPool.getDatasourceClassname() == null ? "" : adminPool.getDatasourceClassname(), "The datasource class name", "java.lang.String"));
}
} else {
// When resType is null, one of these classnames would be specified
if (adminPool.getDriverClassname() != null) {
propList.add(new ConnectorConfigProperty("ClassName", adminPool.getDriverClassname() == null ? "" : adminPool.getDriverClassname(), "The driver class name", "java.lang.String"));
} else if (adminPool.getDatasourceClassname() != null) {
propList.add(new ConnectorConfigProperty("ClassName", adminPool.getDatasourceClassname() == null ? "" : adminPool.getDatasourceClassname(), "The datasource class name", "java.lang.String"));
}
}
propList.add(new ConnectorConfigProperty("ConnectionValidationRequired", adminPool.getIsConnectionValidationRequired() + "", "Is connection validation required", "java.lang.String"));
propList.add(new ConnectorConfigProperty("ValidationMethod", adminPool.getConnectionValidationMethod() == null ? "" : adminPool.getConnectionValidationMethod(), "How the connection is validated", "java.lang.String"));
propList.add(new ConnectorConfigProperty("ValidationTableName", adminPool.getValidationTableName() == null ? "" : adminPool.getValidationTableName(), "Validation Table name", "java.lang.String"));
propList.add(new ConnectorConfigProperty("ValidationClassName", adminPool.getValidationClassname() == null ? "" : adminPool.getValidationClassname(), "Validation Class name", "java.lang.String"));
propList.add(new ConnectorConfigProperty("TransactionIsolation", adminPool.getTransactionIsolationLevel() == null ? "" : adminPool.getTransactionIsolationLevel(), "Transaction Isolatin Level", "java.lang.String"));
propList.add(new ConnectorConfigProperty("GuaranteeIsolationLevel", adminPool.getIsIsolationLevelGuaranteed() + "", "Transaction Isolation Guarantee", "java.lang.String"));
propList.add(new ConnectorConfigProperty("StatementWrapping", adminPool.getWrapJdbcObjects() + "", "Statement Wrapping", "java.lang.String"));
propList.add(new ConnectorConfigProperty("LogJdbcCalls", adminPool.getLogJdbcCalls() + "", "Log JDBC Calls", "java.lang.String"));
propList.add(new ConnectorConfigProperty("SlowQueryThresholdInSeconds", adminPool.getSlowQueryThresholdInSeconds() + "", "Slow Query Threshold In Seconds", "java.lang.String"));
propList.add(new ConnectorConfigProperty("StatementTimeout", adminPool.getStatementTimeoutInSeconds() + "", "Statement Timeout", "java.lang.String"));
PoolInfo poolInfo = conConnPool.getPoolInfo();
propList.add(new ConnectorConfigProperty("PoolMonitoringSubTreeRoot", ConnectorsUtil.getPoolMonitoringSubTreeRoot(poolInfo, true) + "", "Pool Monitoring Sub Tree Root", "java.lang.String"));
propList.add(new ConnectorConfigProperty("PoolName", poolInfo.getName() + "", "Pool Name", "java.lang.String"));
if (poolInfo.getApplicationName() != null) {
propList.add(new ConnectorConfigProperty("ApplicationName", poolInfo.getApplicationName() + "", "Application Name", "java.lang.String"));
}
if (poolInfo.getModuleName() != null) {
propList.add(new ConnectorConfigProperty("ModuleName", poolInfo.getModuleName() + "", "Module name", "java.lang.String"));
}
propList.add(new ConnectorConfigProperty("StatementCacheSize", adminPool.getStatementCacheSize() + "", "Statement Cache Size", "java.lang.String"));
propList.add(new ConnectorConfigProperty("StatementCacheType", adminPool.getStatementCacheType() + "", "Statement Cache Type", "java.lang.String"));
propList.add(new ConnectorConfigProperty("InitSql", adminPool.getInitSql() + "", "InitSql", "java.lang.String"));
propList.add(new ConnectorConfigProperty("SqlTraceListeners", adminPool.getSqlTraceListeners() + "", "Sql Trace Listeners", "java.lang.String"));
propList.add(new ConnectorConfigProperty("StatementLeakTimeoutInSeconds", adminPool.getStatementLeakTimeoutInSeconds() + "", "Statement Leak Timeout in seconds", "java.lang.String"));
propList.add(new ConnectorConfigProperty("StatementLeakReclaim", adminPool.getStatementLeakReclaim() + "", "Statement Leak Reclaim", "java.lang.String"));
// dump user defined poperties into the list
Set connDefDescSet = connDesc.getOutboundResourceAdapter().getConnectionDefs();
// since this a 1.0 RAR, we will have only 1 connDefDesc
if (connDefDescSet.size() != 1) {
throw new MissingResourceException("Only one connDefDesc present", null, null);
}
Iterator iter = connDefDescSet.iterator();
// Now get the set of MCF config properties associated with each
// connection-definition . Each element here is an EnviromnentProperty
Set mcfConfigProps = null;
while (iter.hasNext()) {
mcfConfigProps = ((ConnectionDefDescriptor) iter.next()).getConfigProperties();
}
if (mcfConfigProps != null) {
Map mcfConPropKeys = new HashMap();
Iterator mcfConfigPropsIter = mcfConfigProps.iterator();
while (mcfConfigPropsIter.hasNext()) {
String key = ((ConnectorConfigProperty) mcfConfigPropsIter.next()).getName();
mcfConPropKeys.put(key.toUpperCase(locale), key);
}
String driverProperties = "";
for (Property rp : adminPool.getProperty()) {
if (rp == null) {
continue;
}
String name = rp.getName();
// making it easy to compare in the event of a reconfig
if ("MATCHCONNECTIONS".equals(name.toUpperCase(locale))) {
// JDBC - matchConnections if not set is decided by the ConnectionManager
// so default is false
conConnPool.setMatchConnections(toBoolean(rp.getValue(), false));
logFine("MATCHCONNECTIONS");
} else if ("ASSOCIATEWITHTHREAD".equals(name.toUpperCase(locale))) {
conConnPool.setAssociateWithThread(toBoolean(rp.getValue(), false));
logFine("ASSOCIATEWITHTHREAD");
} else if ("LAZYCONNECTIONASSOCIATION".equals(name.toUpperCase(locale))) {
ConnectionPoolObjectsUtils.setLazyEnlistAndLazyAssocProperties(rp.getValue(), adminPool.getProperty(), conConnPool);
logFine("LAZYCONNECTIONASSOCIATION");
} else if ("LAZYCONNECTIONENLISTMENT".equals(name.toUpperCase(Locale.getDefault()))) {
conConnPool.setLazyConnectionEnlist(toBoolean(rp.getValue(), false));
logFine("LAZYCONNECTIONENLISTMENT");
} else if ("POOLDATASTRUCTURE".equals(name.toUpperCase(Locale.getDefault()))) {
conConnPool.setPoolDataStructureType(rp.getValue());
logFine("POOLDATASTRUCTURE");
} else if (ConnectorConstants.DYNAMIC_RECONFIGURATION_FLAG.equals(name.toLowerCase(locale))) {
String value = rp.getValue();
try {
conConnPool.setDynamicReconfigWaitTimeout(Long.parseLong(rp.getValue()) * 1000L);
logFine(ConnectorConstants.DYNAMIC_RECONFIGURATION_FLAG);
} catch (NumberFormatException nfe) {
_logger.log(Level.WARNING, "Invalid value for " + "'" + ConnectorConstants.DYNAMIC_RECONFIGURATION_FLAG + "' : " + value);
}
} else if ("POOLWAITQUEUE".equals(name.toUpperCase(locale))) {
conConnPool.setPoolWaitQueue(rp.getValue());
logFine("POOLWAITQUEUE");
} else if ("DATASTRUCTUREPARAMETERS".equals(name.toUpperCase(locale))) {
conConnPool.setDataStructureParameters(rp.getValue());
logFine("DATASTRUCTUREPARAMETERS");
} else if ("USERNAME".equals(name.toUpperCase(Locale.getDefault())) || "USER".equals(name.toUpperCase(locale))) {
propList.add(new ConnectorConfigProperty("User", (String) TranslatedConfigView.getTranslatedValue(rp.getValue()), "user name", "java.lang.String"));
} else if ("PASSWORD".equals(name.toUpperCase(locale))) {
propList.add(new ConnectorConfigProperty("Password", (String) TranslatedConfigView.getTranslatedValue(rp.getValue()), "Password", "java.lang.String"));
} else if ("JDBC30DATASOURCE".equals(name.toUpperCase(locale))) {
propList.add(new ConnectorConfigProperty("JDBC30DataSource", rp.getValue(), "JDBC30DataSource", "java.lang.String"));
} else if ("PREFER-VALIDATE-OVER-RECREATE".equals(name.toUpperCase(Locale.getDefault()))) {
String value = rp.getValue();
conConnPool.setPreferValidateOverRecreate(toBoolean(value, false));
logFine("PREFER-VALIDATE-OVER-RECREATE : " + value);
} else if ("STATEMENT-CACHE-TYPE".equals(name.toUpperCase(Locale.getDefault()))) {
if (adminPool.getStatementCacheType() != null) {
propList.add(new ConnectorConfigProperty("StatementCacheType", rp.getValue(), "StatementCacheType", "java.lang.String"));
}
} else if ("NUMBER-OF-TOP-QUERIES-TO-REPORT".equals(name.toUpperCase(Locale.getDefault()))) {
propList.add(new ConnectorConfigProperty("NumberOfTopQueriesToReport", rp.getValue(), "NumberOfTopQueriesToReport", "java.lang.String"));
} else if ("TIME-TO-KEEP-QUERIES-IN-MINUTES".equals(name.toUpperCase(Locale.getDefault()))) {
propList.add(new ConnectorConfigProperty("TimeToKeepQueriesInMinutes", rp.getValue(), "TimeToKeepQueriesInMinutes", "java.lang.String"));
} else if ("MAXCACHESIZE".equals(name.toUpperCase(Locale.getDefault())) || "MAX-CACHE-SIZE".equals(name.toUpperCase(Locale.getDefault()))) {
propList.add(new ConnectorConfigProperty("MaxCacheSize", rp.getValue(), "MaxCacheSize", "java.lang.String"));
} else if (mcfConPropKeys.containsKey(name.toUpperCase(Locale.getDefault()))) {
propList.add(new ConnectorConfigProperty((String) mcfConPropKeys.get(name.toUpperCase(Locale.getDefault())), rp.getValue() == null ? "" : (String) TranslatedConfigView.getTranslatedValue(rp.getValue()), "Some property", "java.lang.String"));
} else {
driverProperties = driverProperties + "set" + escape(name) + "#" + escape((String) TranslatedConfigView.getTranslatedValue(rp.getValue())) + "##";
}
}
if (!driverProperties.equals("")) {
propList.add(new ConnectorConfigProperty("DriverProperties", driverProperties, "some proprietarty properties", "java.lang.String"));
}
}
propList.add(new ConnectorConfigProperty("Delimiter", "#", "delim", "java.lang.String"));
propList.add(new ConnectorConfigProperty("EscapeCharacter", "\\", "escapeCharacter", "java.lang.String"));
// create an array of EnvironmentProperties from above list
ConnectorConfigProperty[] eProps = new ConnectorConfigProperty[propList.size()];
ListIterator propListIter = propList.listIterator();
for (int i = 0; propListIter.hasNext(); i++) {
eProps[i] = (ConnectorConfigProperty) propListIter.next();
}
return eProps;
}
Aggregations