use of org.glassfish.grizzly.config.dom.NetworkListener 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.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class WebContainer method configureHost.
/**
* Configures the given virtual server.
*
* @param vs The virtual server to be configured
* @param securityService The security-service element
*/
protected void configureHost(VirtualServer vs, SecurityService securityService) {
com.sun.enterprise.config.serverbeans.VirtualServer vsBean = vs.getBean();
vs.configureAliases();
// Set the ports with which this virtual server is associated
List<String> listeners = StringUtils.parseStringList(vsBean.getNetworkListeners(), ",");
if (listeners == null) {
return;
}
HashSet<NetworkListener> httpListeners = new HashSet<NetworkListener>();
for (String listener : listeners) {
boolean found = false;
for (NetworkListener httpListener : serverConfig.getNetworkConfig().getNetworkListeners().getNetworkListener()) {
if (httpListener.getName().equals(listener)) {
httpListeners.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);
}
}
configureHostPortNumbers(vs, httpListeners);
vs.configureCatalinaProperties();
vs.configureAuthRealm(securityService);
vs.addProbes(globalAccessLoggingEnabled);
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class WebConfigListener method changed.
/**
* Handles HttpService change events
* @param events the PropertyChangeEvent
*/
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
return ConfigSupport.sortAndDispatch(events, new Changed() {
@Override
public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogFacade.CHANGE_INVOKED, new Object[] { type, tClass, t });
}
try {
if (tClass == HttpService.class) {
container.updateHttpService((HttpService) t);
} else if (tClass == NetworkListener.class) {
if (type == TYPE.ADD) {
container.addConnector((NetworkListener) t, httpService, true);
} else if (type == TYPE.REMOVE) {
container.deleteConnector((NetworkListener) t);
} else if (type == TYPE.CHANGE) {
container.updateConnector((NetworkListener) t, httpService);
}
} else if (tClass == VirtualServer.class) {
if (type == TYPE.ADD) {
container.createHost((VirtualServer) t, httpService, null);
container.loadDefaultWebModule((VirtualServer) t);
} else if (type == TYPE.REMOVE) {
container.deleteHost(httpService);
} else if (type == TYPE.CHANGE) {
container.updateHost((VirtualServer) t);
}
} else if (tClass == AccessLog.class) {
container.updateAccessLog(httpService);
} else if (tClass == ManagerProperties.class) {
return new NotProcessed("ManagerProperties requires restart");
} else if (tClass == WebContainerAvailability.class || tClass == AvailabilityService.class) {
// container.updateHttpService handles SingleSignOn valve configuration
container.updateHttpService(httpService);
} else if (tClass == NetworkListeners.class) {
// skip updates
} else if (tClass == Property.class) {
ConfigBeanProxy config = ((Property) t).getParent();
if (config instanceof HttpService) {
container.updateHttpService((HttpService) config);
} else if (config instanceof VirtualServer) {
container.updateHost((VirtualServer) config);
} else if (config instanceof NetworkListener) {
container.updateConnector((NetworkListener) config, httpService);
} else {
container.updateHttpService(httpService);
}
} else if (tClass == SystemProperty.class) {
if (((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
if (listener.getPort().equals(((SystemProperty) t).getValue())) {
container.updateConnector(listener, httpService);
}
}
}
} else if (tClass == JavaConfig.class) {
JavaConfig jc = (JavaConfig) t;
final List<String> jvmOptions = new ArrayList<String>(jc.getJvmOptions());
for (String jvmOption : jvmOptions) {
if (jvmOption.startsWith("-DjvmRoute=")) {
container.updateJvmRoute(httpService, jvmOption);
}
}
} else {
// Ignore other unrelated events
}
} catch (LifecycleException le) {
logger.log(Level.SEVERE, LogFacade.EXCEPTION_WEB_CONFIG, le);
}
return null;
}
}, logger);
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class WebSslConfigHandler method delete.
@Override
public void delete(DeleteSsl command, ActionReport report) {
NetworkConfig netConfig = command.config.getNetworkConfig();
NetworkListener networkListener = netConfig.getNetworkListener(command.listenerId);
if (networkListener == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_SSL_HTTP_LISTENER_NOT_FOUND), command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Protocol protocol = networkListener.findHttpProtocol();
if (protocol.getSsl() == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_SSL_ELEMENT_DOES_NOT_EXIST), command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) {
param.setSsl(null);
return null;
}
}, networkListener.findHttpProtocol());
} catch (TransactionFailure e) {
command.reportError(report, e);
}
}
use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.
the class WebSslConfigHandler method create.
@Override
public void create(final CreateSsl command, ActionReport report) {
NetworkConfig netConfig = command.config.getNetworkConfig();
// ensure we have the specified listener
NetworkListener listener = netConfig.getNetworkListener(command.listenerId);
Protocol httpProtocol;
try {
if (listener == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_NOT_FOUND), command.listenerId));
httpProtocol = command.findOrCreateProtocol(command.listenerId);
} else {
httpProtocol = listener.findHttpProtocol();
Ssl ssl = httpProtocol.getSsl();
if (ssl != null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_SSL_HTTP_ALREADY_EXISTS), command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) throws TransactionFailure {
Ssl newSsl = param.createChild(Ssl.class);
command.populateSslElement(newSsl);
param.setSsl(newSsl);
return newSsl;
}
}, httpProtocol);
} catch (TransactionFailure e) {
command.reportError(report, e);
}
command.reportSuccess(report);
}
Aggregations