use of org.osgi.service.http.NamespaceException 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);
}
}
}
use of org.osgi.service.http.NamespaceException in project motech by motech.
the class Activator method serviceAdded.
/**
* Initializes the security chain by fetching the proxy manager,
* registers the security filter and spring dispatcher servlet.
*/
private void serviceAdded(ExtHttpService service) {
DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setContextConfigLocation(CONTEXT_CONFIG_LOCATION);
dispatcherServlet.setContextClass(WebSecurityApplicationContext.class);
ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
HttpContext httpContext = HttpContextFactory.getHttpContext(service.createDefaultHttpContext(), bundleContext.getBundle());
service.registerServlet(SERVLET_URL_MAPPING, dispatcherServlet, null, null);
service.registerResources(RESOURCE_URL_MAPPING, "/webapp", httpContext);
LOGGER.debug("Servlet registered");
filter = new MotechDelegatingFilterProxy("springSecurityFilterChain", dispatcherServlet.getWebApplicationContext());
MotechProxyManager proxyManager = dispatcherServlet.getWebApplicationContext().getBean(MotechProxyManager.class);
LOGGER.debug("Creating initial proxy chain");
proxyManager.initializeProxyChain();
service.registerFilter(filter, "/.*", null, 0, httpContext);
LOGGER.debug("Filter registered");
} catch (NamespaceException e) {
throw new ServletRegistrationException("Web-security servlet already registered", e);
} catch (ServletException e) {
throw new ServletRegistrationException("Unable to register servlet for web-security", e);
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
use of org.osgi.service.http.NamespaceException in project smarthome by eclipse.
the class PaperUIApp method activate.
protected void activate(BundleContext bundleContext) {
try {
Bundle paperuiBundle = bundleContext.getBundle();
httpService.registerResources(WEBAPP_ALIAS, "web", httpContextFactoryService.createDefaultHttpContext(paperuiBundle));
logger.info("Started Paper UI at " + WEBAPP_ALIAS);
} catch (NamespaceException e) {
logger.error("Error during servlet startup", e);
}
}
Aggregations