Java Code Examples for org.osgi.service.http.HttpService#registerResources()

The following examples show how to use org.osgi.service.http.HttpService#registerResources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Activator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private HttpService register(final ServiceReference sr)
{
  log.info("Registering with added HttpService");

  final HttpService http = (HttpService) bc.getService(sr);

  try {
    http.registerResources(ALIAS_ROOT, RES_ROOT, new CompletingHttpContext());
    http.registerServlet(ALIAS_SERVLET, new InfoServlet(sr),
                         new Hashtable(), null);
    http.registerResources(ALIAS_DOCS, "", new DirectoryHttpContext());
  } catch (Exception e) {
    log.error("Failed to register in HttpService: " +e.getMessage(), e);
  }

  log.info("Registration done.");
  return http;
}
 
Example 2
Source File: RMICodeBaseService.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Creates a new RMICodeBaseService object.
 *
 * @param mountpoint DOCUMENT ME!
 *
 * @throws Exception DOCUMENT ME!
 */
private RMICodeBaseService(String mountpoint) throws Exception {
    this.mountpoint = mountpoint;

    ServiceReference ref = Activator.bc.getServiceReference(
            "org.osgi.service.http.HttpService");
    httpService = (HttpService) Activator.bc.getService(ref);

    if (setCodeBase(prepareCodeBase(ref, httpService, mountpoint))) {
        bundleHttpContext = new BundleHttpContext();

        try {
            httpService.registerResources(mountpoint, "", bundleHttpContext);
        } catch (Exception ex) {
            Debug.printDebugInfo(10,
                "Could not register mointpount " + mountpoint);
            throw new Exception("Mountpoint already in use");
        }
    } else {
        Debug.printDebugInfo(10,
            "Could not set " + RMI_SERVER_CODEBASE + " property");
        throw new Exception("Unable to set " + RMI_SERVER_CODEBASE +
            " property");
    }
}
 
Example 3
Source File: HttpWrapper.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void register(ServiceReference sr) {
  HttpService http = (HttpService) bc.getService(sr);
  if (http == null) {
    Activator.log.warn("http resource is null");
    return;
  }
  
  try {
    Hashtable props = new Hashtable();
    http.registerServlet(Activator.SERVLET_ALIAS, servlet, props, null);
    http.registerResources(Activator.RES_ALIAS, Activator.RES_DIR, context);
  } catch (Exception e) {
    Activator.log.error("Failed to register resource", e);
  }
}
 
Example 4
Source File: PictureResources.java    From osgi.iot.contest.sdk with Apache License 2.0 5 votes vote down vote up
@Reference
void setHttpService(HttpService http){
	try {
		http.registerResources("/osgi.enroute.trains/pictures", "pictures", null);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 5
Source File: Activator.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object addingService(ServiceReference reference) {
    @SuppressWarnings("unchecked")
    HttpService httpService = (HttpService) context.getService(reference);
    if (httpService != null) {
        try {
            httpService.registerResources(ALIAS, "/res", this);
        } catch (NamespaceException e) {
            logger.warn("Failed registering resource {}", ALIAS, e);
        }
    }
    return httpService;
}