Search in sources :

Example 6 with NamespaceException

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);
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) OSGiDispatcherServlet(org.motechproject.osgi.web.http.OSGiDispatcherServlet) OSGiDispatcherServlet(org.motechproject.osgi.web.http.OSGiDispatcherServlet) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) HttpContext(org.osgi.service.http.HttpContext) NamespaceException(org.osgi.service.http.NamespaceException)

Example 7 with NamespaceException

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) ServletRegistrationException(org.motechproject.osgi.web.exception.ServletRegistrationException) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) MotechDelegatingFilterProxy(org.motechproject.security.filter.MotechDelegatingFilterProxy) HttpContext(org.osgi.service.http.HttpContext) NamespaceException(org.osgi.service.http.NamespaceException) MotechProxyManager(org.motechproject.security.service.MotechProxyManager)

Example 8 with NamespaceException

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);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) NamespaceException(org.osgi.service.http.NamespaceException)

Aggregations

NamespaceException (org.osgi.service.http.NamespaceException)8 ServletException (javax.servlet.ServletException)4 HttpService (org.osgi.service.http.HttpService)3 BasicTestingServlet (org.apache.felix.httplite.osgi.test.BasicTestingServlet)2 HttpContext (org.osgi.service.http.HttpContext)2 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)2 Servlet (javax.servlet.Servlet)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServiceServletHandler (org.apache.felix.http.base.internal.handler.HttpServiceServletHandler)1 ServletHandler (org.apache.felix.http.base.internal.handler.ServletHandler)1 ServletRegistrationException (org.motechproject.osgi.web.exception.ServletRegistrationException)1 OSGiDispatcherServlet (org.motechproject.osgi.web.http.OSGiDispatcherServlet)1 MotechDelegatingFilterProxy (org.motechproject.security.filter.MotechDelegatingFilterProxy)1 MotechProxyManager (org.motechproject.security.service.MotechProxyManager)1 Bundle (org.osgi.framework.Bundle)1 Activate (org.osgi.service.component.annotations.Activate)1