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;
}
}
}
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);
}
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);
}
}
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());
}
}
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);
}
}
Aggregations