_context,
HttpService.class.getName(),
new ServiceTrackerCustomizer() {
public Object addingService(ServiceReference serviceReference) {
try {
HttpService service = (HttpService)_context.getService(serviceReference);
Dictionary<String, String> initParams = new Hashtable<String, String>();
initParams.put("javax.ws.rs.Application", SampleApplication.class.getName());
service.registerServlet(_path, new SampleServlet(), initParams, null);
return service;
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
public void modifiedService(ServiceReference serviceReference, Object o) {
// do nothing
}
public void removedService(ServiceReference serviceReference, Object o) {
HttpService service = (HttpService)_context.getService(serviceReference);
if (service != null) {
service.unregister(_path);
}
}
}
);
_tracker.open();