use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class MessageSecurityConfigEventListenerImpl method handleDelete.
/**
* @param event Event to be processed.
* @throws AdminEventListenerException when the listener is unable to process the event.
*/
public <T extends ConfigBeanProxy> NotProcessed handleDelete(T instance) {
NotProcessed notProcessed = null;
logger.fine("MessageSecurityConfigEventListenerImpl - handleDelete called");
if (instance instanceof MessageSecurityConfig) {
GFServerConfigProvider.loadConfigContext(service);
} else {
notProcessed = new NotProcessed("unimplemented: unknown instance: " + instance.getClass().getName());
}
return notProcessed;
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class SetMonitoringConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
Config config = targetUtil.getConfig(target);
final MonitoringService service = serviceLocator.getService(MonitoringService.class);
if (service == null) {
actionReport.appendMessage("Could not find a monitoring service.");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
try {
ConfigSupport.apply(new SingleConfigCode<MonitoringServiceConfiguration>() {
@Override
public Object run(final MonitoringServiceConfiguration monitoringConfigProxy) throws PropertyVetoException, TransactionFailure {
updateConfiguration(monitoringConfigProxy);
updateAttributes(monitoringConfigProxy, actionReport);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return monitoringConfigProxy;
}
}, monitoringConfig);
if (dynamic) {
enableOnTarget(actionReport, context, enabled);
}
} catch (TransactionFailure ex) {
Logger.getLogger(SetMonitoringConfiguration.class.getName()).log(Level.WARNING, "Exception during command " + "set-monitoring-configuration: " + ex.getCause().getMessage());
actionReport.setMessage(ex.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
use of org.jvnet.hk2.annotations.Service in project mycore by MyCoRe-Org.
the class MCRJerseyDefaultConfiguration method setupGuiceBridge.
/**
* Adds the binding between guice and hk2. This binding is one directional.
* You can add guice services into hk2 (jersey) resources. You cannot add
* a hk2 service into guice.
* <p>
* <a href="https://hk2.java.net/guice-bridge/">about the bridge</a>
* </p>
*
* @param resourceConfig the jersey resource configuration
*/
protected void setupGuiceBridge(ResourceConfig resourceConfig) {
LogManager.getLogger().info("Initialize hk2 - guice bridge...");
resourceConfig.register(new AbstractContainerLifecycleListener() {
@Override
public void onStartup(Container container) {
ServiceLocator serviceLocator = container.getApplicationHandler().getServiceLocator();
Injector injector = MCRInjectorConfig.injector();
GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
guiceBridge.bridgeGuiceInjector(injector);
}
});
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class IiopServiceSslConfigHandler method create.
@Override
public void create(final CreateSsl command, ActionReport report) {
IiopService iiopSvc = command.config.getExtensionByType(IiopService.class);
if (iiopSvc.getSslClientConfig() != null) {
report.setMessage(localStrings.getLocalString("create.ssl.iiopsvc.alreadyExists", "IIOP Service " + "already has been configured with SSL configuration."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<IiopService>() {
public Object run(IiopService param) throws PropertyVetoException, TransactionFailure {
SslClientConfig newSslClientCfg = param.createChild(SslClientConfig.class);
Ssl newSsl = newSslClientCfg.createChild(Ssl.class);
command.populateSslElement(newSsl);
newSslClientCfg.setSsl(newSsl);
param.setSslClientConfig(newSslClientCfg);
return newSsl;
}
}, iiopSvc);
} catch (TransactionFailure e) {
command.reportError(report, e);
}
command.reportSuccess(report);
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class WebContainer method postConstruct.
@Override
public void postConstruct() {
ReentrantReadWriteLock mapperLock = grizzlyService.obtainMapperLock();
mapperLock.writeLock().lock();
try {
createProbeProviders();
injectionMgr = serviceLocator.getService(InjectionManager.class);
invocationMgr = serviceLocator.getService(InvocationManager.class);
tldProviders = serviceLocator.getAllServices(TldProvider.class);
createStatsProviders();
setJspFactory();
_appsWorkRoot = instance.getApplicationCompileJspPath().getAbsolutePath();
_modulesRoot = instance.getApplicationRepositoryPath();
appsStubRoot = instance.getApplicationStubPath().getAbsolutePath();
// 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(serviceLocator.<EntityResolver>getService(EntityResolver.class, "web"));
} catch (MalformedURLException e) {
logger.log(SEVERE, 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);
logger.log(FINE, 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 = serviceLocator.getService(EmbeddedWebContainer.class);
_embedded.setWebContainer(this);
_embedded.setLogServiceFile(logServiceFile);
_embedded.setLogLevel(logLevel);
_embedded.setFileLoggerHandlerFactory(fileLoggerHandlerFactory);
_embedded.setWebContainerFeatureFactory(webContainerFeatureFactory);
_embedded.setCatalinaHome(instance.getInstanceRoot().getAbsolutePath());
_embedded.setCatalinaBase(instance.getInstanceRoot().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(SEVERE, UNABLE_TO_START_WEB_CONTAINER, le);
} finally {
// Restore original context classloader
Thread.currentThread().setContextClassLoader(current);
}
} finally {
mapperLock.writeLock().unlock();
}
}
Aggregations