本文整理匯總了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());
}
示例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 );
}
}
示例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 );
}
示例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.");
}
示例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));
}
示例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"));
}
示例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¶m=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);
}
示例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();
}
示例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();
}
示例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 ));
}
示例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 );
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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");
}