use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class SlingServletResolver method activate.
// ---------- SCR Integration ----------------------------------------------
/**
* Activate this component.
*/
@Activate
protected void activate(final BundleContext context, final Config config) throws LoginException {
final Collection<PendingServlet> refs;
synchronized (this.pendingServlets) {
refs = new ArrayList<>(pendingServlets);
pendingServlets.clear();
this.sharedScriptResolver = resourceResolverFactory.getServiceResourceResolver(Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) "scripts"));
this.searchPaths = this.sharedScriptResolver.getSearchPath();
servletResourceProviderFactory = new ServletResourceProviderFactory(config.servletresolver_servletRoot(), this.searchPaths);
// register servlets immediately from now on
this.context = context;
}
createAllServlets(refs);
// execution paths
this.executionPaths = config.servletresolver_paths();
if (this.executionPaths != null) {
// we simply set the array to null
if (this.executionPaths.length == 0) {
this.executionPaths = null;
} else {
boolean hasRoot = false;
for (int i = 0; i < this.executionPaths.length; i++) {
final String path = this.executionPaths[i];
if (path == null || path.length() == 0 || path.equals("/")) {
hasRoot = true;
break;
}
}
if (hasRoot) {
this.executionPaths = null;
}
}
}
this.defaultExtensions = config.servletresolver_defaultExtensions();
// create cache - if a cache size is configured
this.cacheSize = config.servletresolver_cacheSize();
if (this.cacheSize > 5) {
this.cache = new ConcurrentHashMap<>(cacheSize);
this.logCacheSizeWarning = true;
} else {
this.cacheSize = 0;
}
// setup default servlet
this.getDefaultServlet();
// and finally register as event listener if we need to flush the cache
if (this.cache != null) {
final Dictionary<String, Object> props = new Hashtable<>();
props.put("event.topics", new String[] { "javax/script/ScriptEngineFactory/*", "org/apache/sling/api/adapter/AdapterFactory/*", "org/apache/sling/scripting/core/BindingsValuesProvider/*" });
props.put(ResourceChangeListener.PATHS, "/");
props.put("service.description", "Apache Sling Servlet Resolver and Error Handler");
props.put("service.vendor", "The Apache Software Foundation");
this.eventHandlerReg = context.registerService(new String[] { ResourceChangeListener.class.getName(), EventHandler.class.getName() }, this, props);
}
this.plugin = new ServletResolverWebConsolePlugin(context);
if (this.cacheSize > 0) {
try {
Dictionary<String, String> mbeanProps = new Hashtable<>();
mbeanProps.put("jmx.objectname", "org.apache.sling:type=servletResolver,service=SlingServletResolverCache");
ServletResolverCacheMBeanImpl mbean = new ServletResolverCacheMBeanImpl();
mbeanRegistration = context.registerService(SlingServletResolverCacheMBean.class, mbean, mbeanProps);
} catch (Throwable t) {
LOGGER.debug("Unable to register mbean");
}
}
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class ResourcePresenter method activate.
@Activate
public void activate(final ResourcePresenterConfiguration configuration, final BundleContext bundleContext) {
logger.info("activating resource presenter for {}", configuration.path());
path = configuration.path();
this.bundleContext = bundleContext;
try (final ResourceResolver resourceResolver = getServiceResourceResolver()) {
final Resource resource = resourceResolver.getResource(path);
if (resource != null) {
registerResourcePresence();
}
registerResourceChangeListener();
} catch (LoginException e) {
logger.error(e.getMessage(), e);
}
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class MimeTypeServiceImpl method activate.
// ---------- SCR implementation -------------------------------------------
@Activate
protected void activate(final BundleContext context, final Config config) {
context.addBundleListener(this);
// register core and default sling mime types
Bundle bundle = context.getBundle();
registerMimeType(bundle.getEntry(CORE_MIME_TYPES));
registerMimeType(bundle.getEntry(MIME_TYPES));
// register maps of existing bundles
Bundle[] bundles = context.getBundles();
for (int i = 0; i < bundles.length; i++) {
if ((bundles[i].getState() & (Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING)) != 0 && bundles[i].getBundleId() != bundle.getBundleId()) {
this.registerMimeType(bundles[i].getEntry(MIME_TYPES));
}
}
// register configuration properties
if (config.mime_types() != null) {
for (final String configType : config.mime_types()) {
registerMimeType(configType);
}
}
try {
MimeTypeWebConsolePlugin plugin = new MimeTypeWebConsolePlugin(this);
Dictionary<String, String> props = new Hashtable<>();
props.put("felix.webconsole.label", MimeTypeWebConsolePlugin.LABEL);
props.put("felix.webconsole.title", MimeTypeWebConsolePlugin.TITLE);
props.put("felix.webconsole.category", "Sling");
props.put("felix.webconsole.css", MimeTypeWebConsolePlugin.CSS_REFS);
webConsolePluginService = context.registerService("javax.servlet.Servlet", plugin, props);
} catch (Throwable t) {
// don't care, we thus don't have the console plugin
}
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class ResourceValidationModelProviderImpl method activate.
@Activate
protected void activate(ComponentContext componentContext) throws LoginException {
ResourceResolver rr = null;
try {
rr = rrf.getServiceResourceResolver(null);
StringBuilder sb = new StringBuilder("(");
String[] searchPaths = rr.getSearchPath();
if (searchPaths.length > 1) {
sb.append("|");
}
for (String searchPath : searchPaths) {
sb.append("(path=").append(searchPath + "*").append(")");
}
sb.append(")");
Dictionary<String, Object> eventHandlerProperties = new Hashtable<String, Object>();
eventHandlerProperties.put(EventConstants.EVENT_TOPIC, TOPICS);
eventHandlerProperties.put(EventConstants.EVENT_FILTER, sb.toString());
eventHandlerRegistration = componentContext.getBundleContext().registerService(EventHandler.class, this, eventHandlerProperties);
LOG.debug("Registered event handler for validation models in {}", sb.toString());
} finally {
if (rr != null) {
rr.close();
}
}
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class ValidationServiceImpl method activate.
@Activate
protected void activate(ValidationServiceConfiguration configuration) {
this.configuration = configuration;
ResourceResolver rr = null;
try {
rr = rrf.getServiceResourceResolver(null);
searchPaths = Arrays.asList(rr.getSearchPath());
} catch (LoginException e) {
throw new IllegalStateException("Could not get service resource resolver to figure out search paths", e);
} finally {
if (rr != null) {
rr.close();
}
}
}
Aggregations