use of org.jvnet.hk2.config.ConfigListener 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.ConfigListener in project Payara by payara.
the class GrizzlyService method postConstruct.
/**
* The component has been injected with any dependency and
* will be placed into commission by the subsystem.
*/
@Override
public void postConstruct() {
events.register(this);
final NetworkConfig networkConfig = config.getNetworkConfig();
configListener = new DynamicConfigListener(config, LOGGER);
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(networkConfig.getNetworkListeners());
bean.addListener(configListener);
bean = (ObservableBean) ConfigSupport.getImpl(config.getHttpService());
bean.addListener(configListener);
transactions.addListenerForType(SystemProperty.class, configListener);
configListener.setGrizzlyService(this);
try {
boolean isAtLeastOneProxyStarted = false;
futures = new ArrayList<Future<Result<Thread>>>();
// Record how long it took for the listeners to start up
final long startTime = System.currentTimeMillis();
// Keep a list of successfully started listeners
List<NetworkListener> startedListeners = new ArrayList<>();
for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
if (createNetworkProxy(listener) != null) {
isAtLeastOneProxyStarted = true;
startedListeners.add(listener);
}
}
if (isAtLeastOneProxyStarted) {
// Get the startup time
final long startupTime = System.currentTimeMillis() - startTime;
// Log the listeners which started.
String boundAddresses = Arrays.toString(startedListeners.stream().map(listener -> listener.getAddress() + ":" + listener.getPort()).collect(Collectors.toList()).toArray());
LOGGER.log(Level.INFO, KernelLoggerInfo.grizzlyStarted, new Object[] { Grizzly.getDotedVersion(), startupTime, boundAddresses });
registerContainerAdapters();
}
} catch (RuntimeException e) {
// So far postConstruct can not throw any other exception type
LOGGER.log(Level.SEVERE, KernelLoggerInfo.grizzlyCantStart, e);
for (NetworkProxy proxy : proxies) {
try {
proxy.stop();
} catch (Exception proxyStopException) {
LOGGER.log(Level.SEVERE, KernelLoggerInfo.grizzlyCloseException, new Object[] { proxy.getPort(), proxyStopException });
}
}
throw e;
}
registerMonitoringStatsProviders();
}
use of org.jvnet.hk2.config.ConfigListener in project Payara by payara.
the class WebContainer method createHttpListener.
protected WebConnector createHttpListener(NetworkListener listener, HttpService httpService, Mapper mapper) {
if (!Boolean.valueOf(listener.getEnabled())) {
return null;
}
int port = 8080;
WebConnector connector;
checkHostnameUniqueness(listener.getName(), httpService);
try {
port = Integer.parseInt(listener.getPort());
} catch (NumberFormatException nfe) {
String msg = rb.getString(LogFacade.HTTP_LISTENER_INVALID_PORT);
msg = MessageFormat.format(msg, listener.getPort(), listener.getName());
throw new IllegalArgumentException(msg);
}
if (mapper == null) {
for (Mapper m : habitat.<Mapper>getAllServices(Mapper.class)) {
if (m.getPort() == port && m instanceof ContextMapper) {
ContextMapper cm = (ContextMapper) m;
if (listener.getName().equals(cm.getId())) {
mapper = m;
break;
}
}
}
}
String defaultVS = listener.findHttpProtocol().getHttp().getDefaultVirtualServer();
if (!defaultVS.equals(org.glassfish.api.web.Constants.ADMIN_VS)) {
// Before we start a WebConnector, let's makes sure there is
// not another Container already listening on that port
DataChunk host = DataChunk.newInstance();
char[] c = defaultVS.toCharArray();
host.setChars(c, 0, c.length);
DataChunk mb = DataChunk.newInstance();
mb.setChars(new char[] { '/' }, 0, 1);
MappingData md = new MappingData();
try {
mapper.map(host, mb, md);
} catch (Exception e) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "", e);
}
}
if (md.context != null && md.context instanceof ContextRootInfo) {
ContextRootInfo r = (ContextRootInfo) md.context;
if (!(r.getHttpHandler() instanceof ContainerMapper)) {
new BindException("Port " + port + " is already used by Container: " + r.getHttpHandler() + " and will not get started.").printStackTrace();
return null;
}
}
}
/*
* Create Connector. Connector is SSL-enabled if
* 'security-enabled' attribute in <http-listener>
* element is set to TRUE.
*/
boolean isSecure = Boolean.valueOf(listener.findHttpProtocol().getSecurityEnabled());
if (isSecure && defaultRedirectPort == -1) {
defaultRedirectPort = port;
}
String address = listener.getAddress();
if ("any".equals(address) || "ANY".equals(address) || "INADDR_ANY".equals(address)) {
address = null;
/*
* Setting 'address' to NULL will cause Tomcat to pass a
* NULL InetAddress argument to the java.net.ServerSocket
* constructor, meaning that the server socket will accept
* connections on any/all local addresses.
*/
}
connector = (WebConnector) _embedded.createConnector(address, port, isSecure);
connector.setMapper(mapper);
connector.setJvmRoute(engine.getJvmRoute());
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, LogFacade.HTTP_LISTENER_CREATED, new Object[] { listener.getName(), listener.getAddress(), listener.getPort() });
}
connector.setDefaultHost(listener.findHttpProtocol().getHttp().getDefaultVirtualServer());
connector.setName(listener.getName());
connector.setInstanceName(instanceName);
connector.configure(listener, isSecure, httpService);
_embedded.addConnector(connector);
connectorMap.put(listener.getName(), connector);
// If we already know the redirect port, then set it now
// This situation will occurs when dynamic reconfiguration occurs
String redirectPort = listener.findHttpProtocol().getHttp().getRedirectPort();
if (redirectPort != null) {
connector.setRedirectPort(Integer.parseInt(redirectPort));
} else if (defaultRedirectPort != -1) {
connector.setRedirectPort(defaultRedirectPort);
}
ObservableBean httpListenerBean = (ObservableBean) ConfigSupport.getImpl(listener);
httpListenerBean.addListener(configListener);
return connector;
}
use of org.jvnet.hk2.config.ConfigListener in project Payara by payara.
the class WebContainer method postConstruct.
@Override
public void postConstruct() {
final ReentrantReadWriteLock mapperLock = grizzlyService.obtainMapperLock();
mapperLock.writeLock().lock();
try {
createProbeProviders();
injectionMgr = habitat.getService(InjectionManager.class);
invocationMgr = habitat.getService(InvocationManager.class);
tldProviders = habitat.getAllServices(TldProvider.class);
createStatsProviders();
setJspFactory();
_appsWorkRoot = instance.getApplicationCompileJspPath().getAbsolutePath();
_modulesRoot = instance.getApplicationRepositoryPath();
// START S1AS 6178005
appsStubRoot = instance.getApplicationStubPath().getAbsolutePath();
// END S1AS 6178005
// TODO: ParserUtils should become a @Service and it should initialize itself.
// TODO: there should be only one EntityResolver for both DigesterFactory
// and ParserUtils
File root = _serverContext.getInstallRoot();
File libRoot = new File(root, "lib");
File schemas = new File(libRoot, "schemas");
File dtds = new File(libRoot, "dtds");
try {
ParserUtils.setSchemaResourcePrefix(schemas.toURI().toURL().toString());
ParserUtils.setDtdResourcePrefix(dtds.toURI().toURL().toString());
ParserUtils.setEntityResolver(habitat.<EntityResolver>getService(EntityResolver.class, "web"));
} catch (MalformedURLException e) {
logger.log(Level.SEVERE, LogFacade.EXCEPTION_SET_SCHEMAS_DTDS_LOCATION, e);
}
instanceName = _serverContext.getInstanceName();
webContainerFeatureFactory = getWebContainerFeatureFactory();
configureDynamicReloadingSettings();
setDebugLevel();
String maxDepth = null;
org.glassfish.web.config.serverbeans.WebContainer configWC = serverConfig.getExtensionByType(org.glassfish.web.config.serverbeans.WebContainer.class);
if (configWC != null)
maxDepth = configWC.getPropertyValue(DISPATCHER_MAX_DEPTH);
if (maxDepth != null) {
int depth = -1;
try {
depth = Integer.parseInt(maxDepth);
} catch (NumberFormatException e) {
}
if (depth > 0) {
Request.setMaxDispatchDepth(depth);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogFacade.MAX_DISPATCH_DEPTH_SET, maxDepth);
}
}
}
File currentLogFile = loggingRuntime.getCurrentLogFile();
if (currentLogFile != null) {
logServiceFile = currentLogFile.getAbsolutePath();
}
Level level = Logger.getLogger("org.apache.catalina.level").getLevel();
if (level != null) {
logLevel = level.getName();
}
_embedded = habitat.getService(EmbeddedWebContainer.class);
_embedded.setWebContainer(this);
_embedded.setLogServiceFile(logServiceFile);
_embedded.setLogLevel(logLevel);
_embedded.setFileLoggerHandlerFactory(fileLoggerHandlerFactory);
_embedded.setWebContainerFeatureFactory(webContainerFeatureFactory);
_embedded.setCatalinaHome(instance.getDomainRoot().getAbsolutePath());
_embedded.setCatalinaBase(instance.getDomainRoot().getAbsolutePath());
_embedded.setUseNaming(false);
if (_debug > 1)
_embedded.setDebug(_debug);
_embedded.setLogger(new IASLogger(logger));
engine = _embedded.createEngine();
engine.setParentClassLoader(EmbeddedWebContainer.class.getClassLoader());
engine.setService(_embedded);
_embedded.addEngine(engine);
((StandardEngine) engine).setDomain(_serverContext.getDefaultDomainName());
engine.setName(_serverContext.getDefaultDomainName());
/*
* Set the server info.
* By default, the server info is taken from Version#getVersion.
* However, customers may override it via the product.name system
* property.
* Some customers prefer not to disclose the server info
* for security reasons, in which case they would set the value of the
* product.name system property to the empty string. In this case,
* the server name will not be publicly disclosed via the "Server"
* HTTP response header (which will be suppressed) or any container
* generated error pages. However, it will still appear in the
* server logs (see IT 6900).
*/
String serverInfo = System.getProperty("product.name");
if (serverInfo == null) {
ServerInfo.setServerInfo(Version.getVersion());
ServerInfo.setPublicServerInfo(Version.getVersion());
} else if (serverInfo.isEmpty()) {
ServerInfo.setServerInfo(Version.getVersion());
ServerInfo.setPublicServerInfo(serverInfo);
} else {
ServerInfo.setServerInfo(serverInfo);
ServerInfo.setPublicServerInfo(serverInfo);
}
initInstanceSessionProperties();
configListener = addAndGetWebConfigListener();
ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getHttpService());
bean.addListener(configListener);
bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getNetworkConfig().getNetworkListeners());
bean.addListener(configListener);
if (serverConfig.getAvailabilityService() != null) {
bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getAvailabilityService());
bean.addListener(configListener);
}
transactions.addListenerForType(SystemProperty.class, configListener);
configListener.setNetworkConfig(serverConfig.getNetworkConfig());
// embedded mode does not have manager-propertie in domain.xml
if (configListener.managerProperties != null) {
ObservableBean managerBean = (ObservableBean) ConfigSupport.getImpl(configListener.managerProperties);
managerBean.addListener(configListener);
}
if (serverConfig.getJavaConfig() != null) {
((ObservableBean) ConfigSupport.getImpl(serverConfig.getJavaConfig())).addListener(configListener);
}
configListener.setContainer(this);
configListener.setLogger(logger);
events.register(this);
grizzlyService.addMapperUpdateListener(configListener);
HttpService httpService = serverConfig.getHttpService();
NetworkConfig networkConfig = serverConfig.getNetworkConfig();
if (networkConfig != null) {
// continue;
securityService = serverConfig.getSecurityService();
// Configure HTTP listeners
NetworkListeners networkListeners = networkConfig.getNetworkListeners();
if (networkListeners != null) {
List<NetworkListener> listeners = networkListeners.getNetworkListener();
for (NetworkListener listener : listeners) {
createHttpListener(listener, httpService);
}
}
setDefaultRedirectPort(defaultRedirectPort);
// Configure virtual servers
createHosts(httpService, securityService);
}
loadSystemDefaultWebModules();
// _lifecycle.fireLifecycleEvent(START_EVENT, null);
_started = true;
/*
* Start the embedded container.
* Make sure to set the thread's context classloader to the
* classloader of this class (see IT 8866 for details)
*/
ClassLoader current = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
/*
* Trigger a call to sun.awt.AppContext.getAppContext().
* This will pin the classloader of this class in memory
* and fix a memory leak affecting instances of WebappClassLoader
* that was caused by a JRE implementation change in 1.6.0_15
* onwards. See IT 11110
*/
ImageIO.getCacheDirectory();
_embedded.start();
} catch (LifecycleException le) {
logger.log(Level.SEVERE, LogFacade.UNABLE_TO_START_WEB_CONTAINER, le);
return;
} finally {
// Restore original context classloader
Thread.currentThread().setContextClassLoader(current);
}
} finally {
mapperLock.writeLock().unlock();
}
}
use of org.jvnet.hk2.config.ConfigListener in project Payara by payara.
the class ConfigInstanceListener method lifecycleEvent.
/* (non-Javadoc)
* @see org.glassfish.hk2.api.InstanceLifecycleListener#lifecycleEvent(org.glassfish.hk2.api.InstanceLifecycleEvent)
*/
@Override
public void lifecycleEvent(InstanceLifecycleEvent lifecycleEvent) {
if (!lifecycleEvent.getEventType().equals(InstanceLifecycleEventType.POST_PRODUCTION)) {
return;
}
Map<Injectee, Object> injectees = lifecycleEvent.getKnownInjectees();
if (injectees == null)
return;
ConfigListener listener = (ConfigListener) lifecycleEvent.getLifecycleObject();
for (Object injectee : injectees.values()) {
if (!(injectee instanceof ConfigBeanProxy))
continue;
ConfigBeanProxy configBeanProxy = (ConfigBeanProxy) injectee;
Object impl = ConfigSupport.getImpl(configBeanProxy);
if (!(impl instanceof ObservableBean))
continue;
ObservableBean ob = (ObservableBean) impl;
ob.addListener(listener);
}
}
Aggregations