bundleContext.registerService(HttpService.class.getName(), httpService, null);
try
{
ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
HttpService service = (HttpService) bundleContext.getService(sr);
service.registerResources("/a/b", ".", new HttpContext()
{
public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
{
return true;
}
public URL getResource(String name)
{
name = name.replaceAll("^\\./", "");
name = name.replaceAll("/\\./", "/");
return HttpServiceImplTest.class.getResource(name);
}
public String getMimeType(String name)
{
return null;
}
});
URL url = new URL("http://localhost:8080/a/b/HttpServiceImplTest.class");
DataInputStream reader = new DataInputStream(url.openStream());
assertEquals((byte) 0xca, reader.readByte());
assertEquals((byte) 0xfe, reader.readByte());
assertEquals((byte) 0xba, reader.readByte());
assertEquals((byte) 0xbe, reader.readByte());
service.unregister("/a/b");
}
finally
{
httpService.stop();
server.stop();