當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpService類代碼示例

本文整理匯總了Java中org.osgi.service.http.HttpService的典型用法代碼示例。如果您正苦於以下問題:Java HttpService類的具體用法?Java HttpService怎麽用?Java HttpService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpService類屬於org.osgi.service.http包,在下文中一共展示了HttpService類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import org.osgi.service.http.HttpService; //導入依賴的package包/類
@Override
public void start(BundleContext context) throws Exception {
    log.info("######################################################");
    log.info("start");
    log.info("######################################################");

    Hashtable<String, String> props = new Hashtable<>();
    props.put("osgi.http.whiteboard.servlet.pattern", "/*");
    props.put("init.message", "Crazy filter!");
    props.put("service.ranking", "1");
    serviceRegistration = context.registerService(Filter.class.getName(), new CrazyFilter(), props);

    final ServiceReference<?> httpRef = context.getServiceReference("org.osgi.service.http.HttpService");
    httpService = (HttpService) context.getService(httpRef);

    httpService.registerServlet("/foo", new FooServlet(), new Hashtable(), httpService.createDefaultHttpContext());
}
 
開發者ID:L7R7,項目名稱:magic-bundle,代碼行數:18,代碼來源:Activator.java

示例2: serviceChange

import org.osgi.service.http.HttpService; //導入依賴的package包/類
@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 );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:21,代碼來源:Activator.java

示例3: start

import org.osgi.service.http.HttpService; //導入依賴的package包/類
@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 );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:19,代碼來源:Activator.java

示例4: activate

import org.osgi.service.http.HttpService; //導入依賴的package包/類
@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.");

}
 
開發者ID:wso2-attic,項目名稱:carbon-identity,代碼行數:23,代碼來源:OAuthUIServiceComponent.java

示例5: bindHttpService

import org.osgi.service.http.HttpService; //導入依賴的package包/類
/**
 * HTTP service ready
 * 
 * MOD_BD_20170724
 * 
 * @param aHttpService
 *            The bound service
 * @param aServiceProperties
 *            The HTTP service properties
 */
@Bind(id = IPOJO_ID_HTTP)
private void bindHttpService(final HttpService aHttpService,
        final Map<?, ?> aServiceProperties) {

    final Object rawPort = aServiceProperties.get(HTTP_SERVICE_PORT);

    if (rawPort instanceof Number) {
        // Get the integer
    	pHttpDefaultPort = ((Number) rawPort).intValue();

    } else if (rawPort instanceof CharSequence) {
        // Parse the string
    	pHttpDefaultPort = Integer.parseInt(rawPort.toString());

    } else {
        // Unknown port type
        pLogger.log(LogService.LOG_WARNING, "Couldn't read access port="
                + rawPort);
        pHttpDefaultPort = -1;
    }

    pLogger.log(LogService.LOG_INFO, String.format("Default Http port provided by Http Service [%s]",
    				pHttpDefaultPort));
    
}
 
開發者ID:cohorte,項目名稱:cohorte-herald,代碼行數:36,代碼來源:CHttpServiceAvailabilityChecker.java

示例6: testHttpServiceClassLoading

import org.osgi.service.http.HttpService; //導入依賴的package包/類
@Test
public void testHttpServiceClassLoading() throws Exception {

    Assume.assumeTrue(RuntimeType.getRuntimeType() == RuntimeType.WILDFLY);

    // Get the org.jboss.gravia class loader
    ClassLoader classLoader = RuntimeType.class.getClassLoader();
    Assert.assertTrue("Unexpected: " + classLoader, classLoader.toString().contains("org.jboss.gravia"));

    // Load the HttpService through module org.jboss.gravia
    Class<?> serviceClass = classLoader.loadClass(HttpService.class.getName());
    String loaderName = serviceClass.getClassLoader().toString();

    // Assert that the loaded class comes from org.osgi.enterprise
    Assert.assertTrue("Unexpected: " + loaderName, loaderName.contains("org.osgi.enterprise"));
}
 
開發者ID:tdiesler,項目名稱:fabric8poc,代碼行數:17,代碼來源:HttpServiceTestBase.java

示例7: testServletAccess

import org.osgi.service.http.HttpService; //導入依賴的package包/類
@Test
public void testServletAccess() throws Exception {

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module module = runtime.getModule(getClass().getClassLoader());
    HttpService httpService = ServiceLocator.getRequiredService(HttpService.class);

    // Verify that the alias is not yet available
    String reqspec = "/fabric8/service?test=param&param=Kermit";
    assertNotAvailable(reqspec);

    // Register the test servlet and make a call
    httpService.registerServlet("/service", new HttpServiceServlet(module), null, null);
    Assert.assertEquals("Hello: Kermit", performCall(reqspec));

    // Unregister the servlet alias
    httpService.unregister("/service");
    assertNotAvailable(reqspec);

    // Verify that the alias is not available any more
    assertNotAvailable(reqspec);
}
 
開發者ID:tdiesler,項目名稱:fabric8poc,代碼行數:23,代碼來源:HttpServiceTestBase.java

示例8: start

import org.osgi.service.http.HttpService; //導入依賴的package包/類
@Override
public void start(final ModuleContext context) throws Exception {

    camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").transform(body().prepend("Hello "));
        }
    });
    camelctx.start();

    // [FELIX-4415] Cannot associate HttpService instance with ServletContext
    tracker = new ServiceTracker<HttpService, HttpService>(context, HttpService.class, null) {
        @Override
        public HttpService addingService(ServiceReference<HttpService> sref) {
            if (httpService == null) {
                httpService = super.addingService(sref);
                registerHttpServiceServlet(httpService);
            }
            return httpService;
        }
    };
    tracker.open();
}
 
開發者ID:tdiesler,項目名稱:fabric8poc,代碼行數:26,代碼來源:CamelTransformHttpActivator.java

示例9: activateInternal

import org.osgi.service.http.HttpService; //導入依賴的package包/類
private void activateInternal() {
    ModuleContext syscontext = RuntimeLocator.getRequiredRuntime().getModuleContext();
    httpTracker = new ServiceTracker<HttpService, HttpService>(syscontext, HttpService.class.getName(), null) {

        public HttpService addingService(ServiceReference<HttpService> sref) {
            HttpService service = super.addingService(sref);
            try {
                service.registerServlet("/agent", new AgentServlet(agent.get()), null, null);
                // [TODO] #37 Compute actual endpoint url for HttpEndpointService
                LOGGER.info("Agent HttpEndpoint registered: http://localhost:8080/agent");
            } catch (Exception ex) {
                LOGGER.error("Cannot register agent servlet", ex);
            }
            return service;
        }

        public void removedService(ServiceReference<HttpService> sref, HttpService service) {
            service.unregister("/agent");
            LOGGER.info("Agent HttpEndpoint unregistered");
        }
    };
    httpTracker.open();
}
 
開發者ID:tdiesler,項目名稱:fabric8poc,代碼行數:24,代碼來源:HttpEndpointService.java

示例10: testStart_dmFound

import org.osgi.service.http.HttpService; //導入依賴的package包/類
@Test
public void testStart_dmFound() throws Exception {

	// Mock
	Bundle b = Mockito.mock( Bundle.class );
	Mockito.when( b.getSymbolicName()).thenReturn( "net.roboconf.dm" );

	this.factory.httpService = Mockito.mock( HttpService.class );
	this.factory.bundleContext = Mockito.mock( BundleContext.class );
	Mockito.when( this.factory.bundleContext.getBundles()).thenReturn( new Bundle[] { b });

	// Start
	this.factory.start();

	// Check
	Mockito.verify( this.factory.httpService, Mockito.times( 1 )).registerServlet(
			Mockito.eq( HttpConstants.DM_SOCKET_PATH ),
			Mockito.any( Servlet.class ),
			Mockito.any( Dictionary.class ),
			Mockito.isNull( HttpContext.class ));
}
 
開發者ID:roboconf,項目名稱:roboconf-platform,代碼行數:22,代碼來源:HttpClientFactoryTest.java

示例11: testStart_dmNotFound

import org.osgi.service.http.HttpService; //導入依賴的package包/類
@Test
public void testStart_dmNotFound() throws Exception {

	// Mock
	Bundle b = Mockito.mock( Bundle.class );
	Mockito.when( b.getSymbolicName()).thenReturn( "net.roboconf.NOT.dm" );

	this.factory.httpService = Mockito.mock( HttpService.class );
	this.factory.bundleContext = Mockito.mock( BundleContext.class );
	Mockito.when( this.factory.bundleContext.getBundles()).thenReturn( new Bundle[] { b });

	// Start
	this.factory.start();

	// Check
	Mockito.verifyZeroInteractions( this.factory.httpService );
}
 
開發者ID:roboconf,項目名稱:roboconf-platform,代碼行數:18,代碼來源:HttpClientFactoryTest.java

示例12: serviceChanged

import org.osgi.service.http.HttpService; //導入依賴的package包/類
public void serviceChanged(ServiceEvent event) {
	ServiceReference sr = event.getServiceReference();
	switch (event.getType()) {
	case ServiceEvent.REGISTERED: {
		httpHandler.setHttpService((HttpService) Activator.bc.getService(sr));
		Activator.log(LogService.LOG_INFO,
				"Getting instance of service: "
						+ HttpService.class.getName() + "," + Constants.SERVICE_PID + "=" + (String) sr.getProperty(Constants.SERVICE_PID)
						+ " from " + sr.getBundle().getSymbolicName());
	}
		break;
	case ServiceEvent.UNREGISTERING: {
		Activator.log(LogService.LOG_INFO, "Releasing service: "
				+ HttpService.class.getName() + ","
				+ Constants.SERVICE_PID + "="
				+ (String) sr.getProperty(Constants.SERVICE_PID));

		// httpService.unregister(obixServletPath);
		httpHandler.setHttpService(null);
	}
		break;
	}
}
 
開發者ID:lathil,項目名稱:Ptoceti,代碼行數:24,代碼來源:Activator.java

示例13: bindHttpService

import org.osgi.service.http.HttpService; //導入依賴的package包/類
/**
 * HTTP service ready
 * 
 * @param aHttpService
 *            The bound service
 * @param aServiceProperties
 *            The HTTP service properties
 */
@Bind(id = IPOJO_ID_HTTP)
private void bindHttpService(final HttpService aHttpService,
        final Map<?, ?> aServiceProperties) {

    final Object rawPort = aServiceProperties.get(HTTP_SERVICE_PORT);

    if (rawPort instanceof Number) {
        // Get the integer
        pHttpPort = ((Number) rawPort).intValue();

    } else if (rawPort instanceof CharSequence) {
        // Parse the string
        pHttpPort = Integer.parseInt(rawPort.toString());

    } else {
        // Unknown port type
        pLogger.log(LogService.LOG_WARNING, "Couldn't read access port "
                + rawPort);
        pHttpPort = -1;
    }
}
 
開發者ID:cohorte,項目名稱:cohorte-remote-services,代碼行數:30,代碼來源:ServletWrapper.java

示例14: bindHttpService

import org.osgi.service.http.HttpService; //導入依賴的package包/類
/**
 * HTTP service ready: store its listening port
 *
 * @param aHttpService
 *            The bound service
 * @param aServiceProperties
 *            The HTTP service properties
 */
@Bind(id = IPOJO_ID_HTTP)
private void bindHttpService(final HttpService aHttpService,
        final Map<?, ?> aServiceProperties) {

    final Object rawPort = aServiceProperties.get(HTTP_SERVICE_PORT);

    if (rawPort instanceof Number) {
        // Get the integer
        pHttpPort = ((Number) rawPort).intValue();

    } else if (rawPort instanceof CharSequence) {
        // Parse the string
        pHttpPort = Integer.parseInt(rawPort.toString());

    } else {
        // Unknown port type
        pLogger.log(LogService.LOG_WARNING, "Couldn't read access port="
                + rawPort);
        pHttpPort = -1;
    }

    pLogger.log(LogService.LOG_INFO, "JABSORB-RPC endpoint bound to port="
            + pHttpPort);
}
 
開發者ID:cohorte,項目名稱:cohorte-remote-services,代碼行數:33,代碼來源:JabsorbRpcExporter.java

示例15: start

import org.osgi.service.http.HttpService; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
public void start(BundleContext context) throws Exception {
    // XXX service already registered at this point?
    ServiceReference reference = context.getServiceReference(HttpService.class.getName());
    if (reference == null) {
        throw new Exception("No service reference found for HttpService. Unable to register ContextServlet.");
    }
    HttpService service = (HttpService) context.getService(reference);
    if (service == null) {
        throw new Exception("No HttpService found. Unable to register ContextServlet.");
    }

    service.registerServlet(SERVLET_ALIAS, new ContextServlet(), null, null);
    LOG.info(getClass().getName() + "::Start");
}
 
開發者ID:hnunner,項目名稱:osgi-servlet,代碼行數:17,代碼來源:Activator.java


注:本文中的org.osgi.service.http.HttpService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。