本文整理汇总了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");
}