use of org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler in project felix by apache.
the class AbstractListenerManager method addingService.
@Override
public ServiceReference<EventListener> addingService(final ServiceReference<EventListener> reference) {
SystemLogger.warning("Deprecation warning: " + "Listener registered through Apache Felix whiteboard service: " + reference + ". Please change your code to the OSGi Http Whiteboard Service.", null);
final ListenerInfo info = new ListenerInfo(reference, true);
this.allInfos.put((Long) reference.getProperty(Constants.SERVICE_ID), info);
final ListenerHandler listenerHandler = new WhiteboardListenerHandler(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID, // context is only relevant for ServletContextListener which is not supported here
null, info, this.context);
synchronized (lock) {
registry.addListeners(listenerHandler);
}
return reference;
}
use of org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler in project felix by apache.
the class WhiteboardManager method registerWhiteboardService.
/**
* Register whiteboard service in the http service
* @param handler Context handler
* @param info Whiteboard service info
*/
private void registerWhiteboardService(final WhiteboardContextHandler handler, final WhiteboardServiceInfo<?> info) {
try {
int failureCode = -1;
if (info instanceof ServletInfo) {
final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
if (servletContext == null) {
failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
} else {
final ServletHandler servletHandler = new WhiteboardServletHandler(handler.getContextInfo().getServiceId(), servletContext, (ServletInfo) info, handler.getBundleContext(), info.getServiceReference().getBundle(), this.httpBundleContext.getBundle());
handler.getRegistry().registerServlet(servletHandler);
}
} else if (info instanceof FilterInfo) {
final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
if (servletContext == null) {
failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
} else {
final FilterHandler filterHandler = new WhiteboardFilterHandler(handler.getContextInfo().getServiceId(), servletContext, (FilterInfo) info, handler.getBundleContext());
handler.getRegistry().registerFilter(filterHandler);
}
} else if (info instanceof ResourceInfo) {
final ServletInfo servletInfo = ((ResourceInfo) info).getServletInfo();
final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
if (servletContext == null) {
failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
} else {
final ServletHandler servleHandler = new HttpServiceServletHandler(handler.getContextInfo().getServiceId(), servletContext, servletInfo, new ResourceServlet(servletInfo.getPrefix()));
handler.getRegistry().registerServlet(servleHandler);
}
} else if (info instanceof ListenerInfo) {
final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
if (servletContext == null) {
failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
} else {
final ListenerHandler listenerHandler = new WhiteboardListenerHandler(handler.getContextInfo().getServiceId(), servletContext, (ListenerInfo) info, handler.getBundleContext());
handler.getRegistry().registerListeners(listenerHandler);
}
} else {
// This should never happen, but we log anyway
SystemLogger.error("Unknown whiteboard service " + info.getServiceReference(), null);
}
if (failureCode != -1) {
this.failureStateHandler.addFailure(info, handler.getContextInfo().getServiceId(), failureCode);
}
} catch (final Exception e) {
this.failureStateHandler.addFailure(info, handler.getContextInfo().getServiceId(), FAILURE_REASON_UNKNOWN, e);
}
}
use of org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler in project felix by apache.
the class FilterRegistryTest method createListenerHandler.
private static ListenerHandler createListenerHandler(final long id, final int ranking, final Class<? extends EventListener> type) throws InvalidSyntaxException {
final ListenerInfo info = createListenerInfo(id, ranking, type);
final ExtServletContext ctx = mock(ExtServletContext.class);
return new WhiteboardListenerHandler(1L, ctx, info, info.getServiceReference().getBundle().getBundleContext());
}
Aggregations