Search in sources :

Example 1 with NamespaceException

use of org.osgi.service.http.NamespaceException in project felix by apache.

the class TestOSGiService method testCannotRegisterInvalidAlias.

/**
 * Test invalid aliases throw NamespaceException.
 *
 * @throws ServletException
 * @throws NamespaceException
 */
public void testCannotRegisterInvalidAlias() throws ServletException, NamespaceException {
    HttpService httpService = getHTTPService(registry.getBundleContext());
    String[] badAliases = { "noslash" };
    for (int i = 0; i < badAliases.length; ++i) {
        boolean namespaceExceptionThrown = false;
        try {
            httpService.registerServlet(badAliases[i], new BasicTestingServlet(), null, null);
        } catch (NamespaceException e) {
            namespaceExceptionThrown = true;
        }
    }
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpService(org.osgi.service.http.HttpService) NamespaceException(org.osgi.service.http.NamespaceException)

Example 2 with NamespaceException

use of org.osgi.service.http.NamespaceException in project felix by apache.

the class TestOSGiService method testCannotRegisterSameAliasTwice.

/**
 * Test that HTTP Service does not allow same alias to be registered twice.
 *
 * @throws ServletException
 * @throws NamespaceException
 */
public void testCannotRegisterSameAliasTwice() throws ServletException, NamespaceException {
    HttpService httpService = getHTTPService(registry.getBundleContext());
    boolean namespaceExceptionThrown = false;
    httpService.registerServlet("/alias", new BasicTestingServlet(), null, null);
    try {
        httpService.registerServlet("/alias", new BasicTestingServlet(), null, null);
    } catch (NamespaceException e) {
        namespaceExceptionThrown = true;
    }
    assertTrue(namespaceExceptionThrown);
}
Also used : BasicTestingServlet(org.apache.felix.httplite.osgi.test.BasicTestingServlet) HttpService(org.osgi.service.http.HttpService) NamespaceException(org.osgi.service.http.NamespaceException)

Example 3 with NamespaceException

use of org.osgi.service.http.NamespaceException in project felix by apache.

the class SharedHttpServiceImpl method registerServlet.

/**
 * Register a servlet
 */
public void registerServlet(@Nonnull final String alias, @Nonnull final ExtServletContext httpContext, @Nonnull final Servlet servlet, @Nonnull final ServletInfo servletInfo) throws ServletException, NamespaceException {
    final ServletHandler handler = new HttpServiceServletHandler(httpContext, servletInfo, servlet);
    synchronized (this.aliasMap) {
        if (this.aliasMap.containsKey(alias)) {
            throw new NamespaceException("Alias " + alias + " is already in use.");
        }
        this.handlerRegistry.getRegistry(handler.getContextServiceId()).registerServlet(handler);
        this.aliasMap.put(alias, handler);
    }
}
Also used : ServletHandler(org.apache.felix.http.base.internal.handler.ServletHandler) HttpServiceServletHandler(org.apache.felix.http.base.internal.handler.HttpServiceServletHandler) HttpServiceServletHandler(org.apache.felix.http.base.internal.handler.HttpServiceServletHandler) NamespaceException(org.osgi.service.http.NamespaceException)

Example 4 with NamespaceException

use of org.osgi.service.http.NamespaceException in project smarthome by eclipse.

the class ProxyServletService method activate.

@Activate
protected void activate(Map<String, Object> config) {
    try {
        Servlet servlet = getImpl();
        logger.debug("Starting up '{}' servlet  at /{}", servlet.getServletInfo(), PROXY_ALIAS);
        Hashtable<String, String> props = propsFromConfig(config);
        httpService.registerServlet("/" + PROXY_ALIAS, servlet, props, createHttpContext());
    } catch (NamespaceException | ServletException e) {
        logger.error("Error during servlet startup: {}", e.getMessage());
    }
}
Also used : ServletException(javax.servlet.ServletException) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) NamespaceException(org.osgi.service.http.NamespaceException) Activate(org.osgi.service.component.annotations.Activate)

Example 5 with NamespaceException

use of org.osgi.service.http.NamespaceException in project spring-roo by spring-projects.

the class HttpTracker method addingService.

@Override
public HttpService addingService(ServiceReference<HttpService> ref) {
    try {
        HttpService service = super.addingService(ref);
        HttpService active = application.addHttpService(service);
        // It that case we don't need to track the last HttpService
        if (service != active) {
            bundleContext.ungetService(ref);
        }
        return service;
    } catch (ServletException ex) {
        throw new RuntimeException(ex);
    } catch (NamespaceException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ServletException(javax.servlet.ServletException) HttpService(org.osgi.service.http.HttpService) 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