public void testServletAccess() throws Exception {
Runtime runtime = RuntimeLocator.getRequiredRuntime();
Module module = runtime.getModule(getClass().getClassLoader());
ModuleContext context = module.getModuleContext();
ServiceReference<HttpService> sref = context.getServiceReference(HttpService.class);
HttpService httpService = context.getService(sref);
String reqspec = "/service?test=param¶m=Kermit";
try {
Map<String, String> headers = Collections.singletonMap("Authorization", "Basic " + Base64Encoder.encode("graviaUser:graviaPass"));
// Verify that the alias is not yet available
assertNotAvailable(reqspec, headers);
HttpContext base = httpService.createDefaultHttpContext();
String realm = RuntimeType.getRuntimeType() == RuntimeType.KARAF ? "gravia" : "ApplicationRealm";
HttpContext secureContext = new SecureHttpContext(base, realm, "graviaRole");
// Register the test servlet and make a call
httpService.registerServlet("/service", new HttpServiceServlet(module), null, secureContext);
Assert.assertEquals("Hello: Kermit", performCall(reqspec, headers));
// Unregister the servlet alias
httpService.unregister("/service");
assertNotAvailable(reqspec, headers);
// Verify that the alias is not available any more
assertNotAvailable(reqspec, headers);
} finally {