org.osgi.service.http.HttpService Java Examples

The following examples show how to use org.osgi.service.http.HttpService. 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: 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 #2
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 #3
Source File: OAuthUIServiceComponent.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void activate(ComponentContext context) {
    log.debug("Activating Identity OAuth UI bundle.");

    HttpService httpService = OAuthUIServiceComponentHolder.getInstance().getHttpService();

    try {

        // Register OAuth 1.a servlet
        Servlet oauth1aServlet = new ContextPathServletAdaptor(new OAuthServlet(), OAUTH_URL);
        httpService.registerServlet(OAUTH_URL, oauth1aServlet, null, null);
        log.debug("Successfully registered an instance of OAuthServlet");

    } catch (Exception e) {
        String errMsg = "Error when registering an OAuth endpoint via the HttpService.";
        log.error(errMsg, e);
        throw new RuntimeException(errMsg, e);
    }

    log.debug("Successfully activated Identity OAuth UI bundle.");

}
 
Example #4
Source File: Activator.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void serviceChange ( final ServiceReference<HttpService> reference, final HttpService service )
{
    if ( Activator.this.httpService != null )
    {
        Activator.this.httpService.unregister ( SERVLET_PATH );
        Activator.this.httpService.unregister ( "/media" );
        Activator.this.httpService = null;
    }
    Activator.this.httpService = service;
    try
    {
        Activator.this.httpService.registerServlet ( SERVLET_PATH, Activator.this.jsonServlet, null, null );
        Activator.this.httpService.registerResources ( SERVLET_PATH + "/ui", "/ui", null );
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to handle http service change", e );
    }
}
 
Example #5
Source File: Activator.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void start ( final BundleContext context ) throws Exception
{
    Activator.context = context;

    // start servlet
    this.httpServiceTracker = new SingleServiceTracker<HttpService> ( context, HttpService.class, this.httpServiceListener );
    this.httpServiceTracker.open ();

    this.exporterServiceTracker = new SingleServiceTracker<HttpExporter> ( context, HttpExporter.class, this.exporterServiceListener );
    this.exporterServiceTracker.open ();

    this.localHdServerServiceTracker = new SingleServiceTracker<Service> ( context, Service.class, this.localHdServerServiceListener );
    this.localHdServerServiceTracker.open ();

    // try to start local exporter
    registerRemoteExporter ( context );
}
 
Example #6
Source File: JaxRSServerContainer.java    From JaxRSProviders with Apache License 2.0 6 votes vote down vote up
protected void removeRegistration(RSARemoteServiceRegistration registration) {
	final HttpService httpService = getHttpService();
	if (httpService != null) {
		final String servletAlias = getServletAlias(registration);
		if (servletAlias != null) {
			synchronized (this.registrations) {
				this.registrations.remove(servletAlias);
				SafeRunner.run(new ISafeRunnable() {
					@Override
					public void run() throws Exception {
						httpService.unregister(servletAlias);
					}
				});
			}
		}
	}
}
 
Example #7
Source File: ServerTestsActivator.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public void start(BundleContext context) throws Exception {
	bundleContext = context;
	httpServiceTracker = new ServiceTracker<HttpService, HttpService>(context, HttpService.class, null);
	httpServiceTracker.open();

	packageAdminTracker = new ServiceTracker<PackageAdmin, PackageAdmin>(context, PackageAdmin.class.getName(), null);
	packageAdminTracker.open();
}
 
Example #8
Source File: Activator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void unregister(HttpService http) {
  log.info("Unregistering from removed HttpService");

  http.unregister(ALIAS_ROOT);
  http.unregister(ALIAS_SERVLET);
  http.unregister(ALIAS_DOCS);

  log.info("Unregistration done.");
}
 
Example #9
Source File: IconForwarder.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Reference
protected void setHttpService(HttpService httpService) {
    try {
        httpService.registerServlet(IMAGES_ALIAS, this, null, httpService.createDefaultHttpContext());
    } catch (Exception e) {
        logger.error("Could not register icon forwarder servlet: {}", e.getMessage());
    }
}
 
Example #10
Source File: Activator.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void start ( final BundleContext context ) throws Exception
{
    this.context = context;

    this.injector = new EventInjectorQueue ( context );

    this.httpServiceTracker = new ServiceTracker<HttpService, HttpService> ( context, HttpService.class, createHttpServiceTrackerCustomizer () );
    this.httpServiceTracker.open ();
}
 
Example #11
Source File: FrameworkServiceComponent.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
protected void unsetHttpService(HttpService httpService) {

        if (log.isDebugEnabled()) {
            log.debug("HTTP Service is unset in the Application Authentication Framework bundle");
        }

        this.httpService = null;
    }
 
Example #12
Source File: ThriftAuthenticationServiceComponent.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Reference(
         name = "http.service", 
         service = org.osgi.service.http.HttpService.class, 
         cardinality = ReferenceCardinality.MANDATORY, 
         policy = ReferencePolicy.DYNAMIC, 
         unbind = "unsetHttpService")
protected void setHttpService(HttpService httpService) {
    setHttpServiceInstance(httpService);
}
 
Example #13
Source File: JspBundle.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public JspBundle ( final Bundle bundle, final HttpService service, final HttpContext context ) throws ServletException, NamespaceException
{
    this.service = service;

    this.alias = String.format ( "/bundle/%s/WEB-INF", bundle.getBundleId () );
    this.servlet = new JspServlet ( bundle, "/WEB-INF", this.alias );

    logger.info ( "Registering JSP servlet - resources: /WEB-INF, alias: {}, bundle: {}", this.alias, bundle.getSymbolicName () );

    final Dictionary<String, String> initparams = new Hashtable<> ( 2 );
    initparams.put ( "compilerSourceVM", "1.8" );
    initparams.put ( "compilerTargetVM", "1.8" );

    this.service.registerServlet ( this.alias, this.servlet, initparams, context );
}
 
Example #14
Source File: HTTPTransportActivator.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void start(final BundleContext context) throws Exception {

        ConfigAdminHttpConduitConfigurer conduitConfigurer = new ConfigAdminHttpConduitConfigurer();

        registerService(context, ManagedServiceFactory.class, conduitConfigurer,
                        ConfigAdminHttpConduitConfigurer.FACTORY_PID);
        registerService(context, HTTPConduitConfigurer.class, conduitConfigurer,
                        "org.apache.cxf.http.conduit-configurer");

        if (PropertyUtils.isTrue(context.getProperty(DISABLE_DEFAULT_HTTP_TRANSPORT))) {
            //TODO: Review if it also makes sense to support "http.transport.disable"
            //      directly in the CXF_CONFIG_SCOPE properties file
            return;
        }

        DestinationRegistry destinationRegistry = new DestinationRegistryImpl();
        HTTPTransportFactory transportFactory = new HTTPTransportFactory(destinationRegistry);

        HttpServiceTrackerCust customizer = new HttpServiceTrackerCust(destinationRegistry, context);
        httpServiceTracker = new ServiceTracker<>(context, HttpService.class, customizer);
        httpServiceTracker.open();

        context.registerService(DestinationRegistry.class.getName(), destinationRegistry, null);
        context.registerService(HTTPTransportFactory.class.getName(), transportFactory, null);

        BlueprintNameSpaceHandlerFactory factory = new BlueprintNameSpaceHandlerFactory() {

            @Override
            public Object createNamespaceHandler() {
                return new HttpBPHandler();
            }
        };
        NamespaceHandlerRegisterer.register(context, factory,
                                            "http://cxf.apache.org/transports/http/configuration");
    }
 
Example #15
Source File: CarbonUIServiceComponent.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public static HttpService getHttpService() {
    if (httpServiceInstance == null) {
        String msg = "Before activating Carbon UI bundle, an instance of "
                     + HttpService.class.getName() + " should be in existence";
        log.error(msg);
        throw new RuntimeException(msg);
    }
    return httpServiceInstance;
}
 
Example #16
Source File: FormAuthenticationService.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public void unsetHttpService(HttpService httpService) {
	if (httpService != null) {
		httpService.unregister("/mixlogin/manageoauth"); //$NON-NLS-1$
		httpService.unregister("/login"); //$NON-NLS-1$
		httpService.unregister("/logout"); //$NON-NLS-1$
		httpService = null;
	}
}
 
Example #17
Source File: Activator.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void addService ( final ServiceReference<?> serviceReference )
{
    if ( serviceReference == null )
    {
        return;
    }
    this.service = (HttpService)this.context.getService ( serviceReference );
    this.serviceReference = serviceReference;
    if ( this.service != null )
    {
        configureService ();
    }
}
 
Example #18
Source File: Activator.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void start ( final BundleContext context ) throws Exception
{
    this.context = context;
    addService ( context.getServiceReference ( HttpService.class ) );
    context.addServiceListener ( this, String.format ( "(%s=%s)", Constants.OBJECTCLASS, HttpService.class.getName () ) );
}
 
Example #19
Source File: HttpTestSuite.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void runTest() throws Throwable {
  out.println("HttpTestSuite:SETUP starting");
  httpSR = bc.getServiceReference(HttpServiceClass);
  assertNotNull("Setup: no http service ref available", httpSR);
  httpService = (HttpService) bc.getService(httpSR);
  assertNotNull("Setup: no http service object available", httpService);

  Object hostObj = httpSR.getProperty("host");
  if(hostObj != null) {
    String s = hostObj.toString();
    if(s.length() > 0) {
      hostname = s;
    }
  }

  // Now let's get on with the port...
  obj = httpSR.getProperty("port.http");
  if(obj == null) {
    obj = httpSR.getProperty("openPort");
  }
  if (obj != null) {
    port = obj.toString();
  } else {
    out.println("Ooops - failed to find the port property!!!");

    // Dump the properties as known by the http service
    String[] keys = httpSR.getPropertyKeys();
    System.out.println("--- Propetry keys ---");
    for (int i=0; i<keys.length; i++) {
      out.println(i +": " +keys[i] +" --> " +httpSR.getProperty(keys[i]));
    }
  }
  out.println("HttpTestSuite:SETUP using service with URL=" +getUrl("/"));
}
 
Example #20
Source File: CarbonCoreDataHolder.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public  HttpService getHttpService() throws Exception {
    if (httpService == null) {
        String msg = "Before activating Carbon Core bundle, an instance of "
                + HttpService.class.getName() + " should be in existance";
        log.error(msg);
        throw new Exception(msg);
    }
    return httpService;
}
 
Example #21
Source File: HttpTrigger.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public HttpTrigger ( final SitePrefixService prefixService, final HttpService httpService, final HttpTriggerConfiguration configuration, final ChannelService channelService )
{
    this.prefixService = prefixService;
    this.httpService = httpService;
    this.configuration = configuration;
    this.channelService = channelService;
}
 
Example #22
Source File: HttpServiceTrackerCust.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public HttpService addingService(ServiceReference<HttpService> reference) {
    HttpService httpService = context.getService(reference);
    Servlet servlet = new CXFNonSpringServlet(destinationRegistry, false);
    servletExporter = new ServletExporter(servlet, httpService);
    servletPublisherReg = context.registerService(ManagedService.class,
                                                  servletExporter,
                                                  CollectionUtils.singletonDictionary(Constants.SERVICE_PID,
                                                                                      CXF_CONFIG_PID));
    return httpService;
}
 
Example #23
Source File: JaxRSServerContainer.java    From JaxRSProviders with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<String, Object> exportRemoteService(RSARemoteServiceRegistration reg) {
	// Create Servlet
	Servlet servlet = createServlet(reg);
	if (servlet == null)
		throw new NullPointerException(
				"Servlet is null.  It cannot be null to export Jax RS servlet.   See subclass implementation of JaxRSServerContainer.createServlet()");
	// Create servletProps
	@SuppressWarnings("rawtypes")
	Dictionary servletProperties = createServletProperties(reg);
	// Create HttpContext
	HttpContext servletContext = createServletContext(reg);
	// Get servlet alias
	String servletAlias = getServletAlias(reg);
	// Get HttpService instance
	HttpService httpService = getHttpService();
	if (httpService == null)
		throw new NullPointerException("HttpService cannot cannot be null");
	synchronized (this.registrations) {
		try {
			httpService.registerServlet(servletAlias, servlet, servletProperties, servletContext);
		} catch (ServletException | NamespaceException e) {
			throw new RuntimeException("Cannot register servlet with alias=" + servletAlias, e);
		}
		this.registrations.put(servletAlias, reg);
	}
	return createExtraExportProperties(servletAlias, reg);
}
 
Example #24
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 #25
Source File: FrameworkServiceComponent.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
protected void setHttpService(HttpService httpService) {
    if (log.isDebugEnabled()) {
        log.debug("HTTP Service is set in the Application Authentication Framework bundle");
    }

    this.httpService = httpService;
}
 
Example #26
Source File: FrameworkServiceComponent.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
protected void unsetHttpService(HttpService httpService) {
    if (log.isDebugEnabled()) {
        log.debug("HTTP Service is unset in the Application Authentication Framework bundle");
    }

    this.httpService = null;
}
 
Example #27
Source File: HttpServiceTrackerCust.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void removedService(ServiceReference<HttpService> reference, HttpService service) {
    servletPublisherReg.unregister();
    try {
        servletExporter.updated(null);
    } catch (ConfigurationException e) {
        // Ignore
    }
}
 
Example #28
Source File: Activator.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void start(BundleContext context) throws Exception {
    this.context = context;
    httpTracker = new ServiceTracker(context, HttpService.class.getName(), this);
    httpTracker.open();
}
 
Example #29
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;
}
 
Example #30
Source File: JAXWSExporterWithHttpServiceTest.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
@Override
protected void prepareMockInterceptors() {
    super.prepareMockInterceptors();

    //Add httpservice mock
    field("http").ofType(HttpService.class).in(exporter).set(httpServiceMock);
}