use of org.motechproject.osgi.web.http.OSGiDispatcherServlet in project motech by motech.
the class HttpServiceTracker method register.
private void register(HttpService httpService) {
if (contextPath == null && httpService != null) {
DispatcherServlet dispatcherServlet = new OSGiDispatcherServlet(context, (ConfigurableWebApplicationContext) bundleContextWrapper.getBundleApplicationContext());
contextPath = WebBundleUtil.getContextPath(context.getBundle());
dispatcherServlet.setContextClass(MotechOSGiWebApplicationContext.class);
dispatcherServlet.setContextConfigLocation(WebBundleUtil.getContextLocation(context.getBundle()));
ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
HttpContext httpContext = HttpContextFactory.getHttpContext(httpService.createDefaultHttpContext(), context.getBundle());
httpService.unregister(contextPath);
httpService.registerServlet(contextPath, dispatcherServlet, null, httpContext);
if (resourceMapping != null) {
for (String key : resourceMapping.keySet()) {
LOGGER.debug(String.format("Registering %s = %s for bundle %s ", key, resourceMapping.keySet(), bundleContextWrapper.getCurrentBundleSymbolicName()));
httpService.registerResources(key, resourceMapping.get(key), httpContext);
}
}
LOGGER.info(String.format("servlet registered with context path %s for bundle %s", contextPath, OsgiStringUtils.nullSafeSymbolicName(context.getBundle())));
} catch (ServletException e) {
LOGGER.error("Unable to register dispatcher servlet for {}", bundleContextWrapper.getCurrentBundleSymbolicName(), e);
} catch (NamespaceException e) {
LOGGER.error("Unable to register dispatcher servlet for {}, namespace already taken", bundleContextWrapper.getCurrentBundleSymbolicName(), e);
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
}
Aggregations