org.osgi.framework.ServiceListener#org.restlet.Application源码实例Demo

下面列出了org.osgi.framework.ServiceListener#org.restlet.Application 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: scava   文件: Activator.java
public void start(BundleContext context) throws Exception {
context.addServiceListener(new ServiceListener() {
			
	@Override
	public void serviceChanged(ServiceEvent event) {
		if (event.getType() == ServiceEvent.REGISTERED){
	    	component = new Component();
	    	
	    	Server server = new Server(Protocol.HTTP, 8182);
	    	component.getServers().add(server);
	    	component.setLogService(new LogService(false));
	    	
	    	final Application app = new ApiApplication();
	    	component.getDefaultHost().attachDefault(app);
	    	try {
	    		component.start();
	    	} catch (Exception e) {
	    		e.printStackTrace();
	    	}
		}
	}
}, "(objectclass=" + ApiStartServiceToken.class.getName() +")");
  }
 
源代码2 项目: scava   文件: ApiAnalysisTests.java
@Before
public void setUp() throws UnknownHostException {
	mongo = new Mongo();
	helper = new ApiHelper();
	PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor());
	platform = Platform.getInstance();
	platform.setMongo(mongo);
	platform.initialize();

	WORKER_ID = Configuration.getInstance().getSlaveIdentifier();
	// Register Worker
	platform.getAnalysisRepositoryManager().getWorkerService().registerWorker(WORKER_ID);

	Component component = new Component();

	Server server = new Server(Protocol.HTTP, 8182);
	component.getServers().add(server);

	final Application app = new ApiApplication();
	component.getDefaultHost().attachDefault(app);
	try {
		component.start();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
源代码3 项目: scava   文件: ProjectAnalysisTests.java
@Before
public void setUp() throws UnknownHostException {
	mongo = new Mongo();
	helper = new ApiHelper();
	PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor());
	platform = Platform.getInstance();
	platform.setMongo(mongo);
	platform.initialize();

	WORKER_ID = Configuration.getInstance().getSlaveIdentifier();
	// Register Worker
	platform.getAnalysisRepositoryManager().getWorkerService().registerWorker(WORKER_ID);

	Component component = new Component();

	Server server = new Server(Protocol.HTTP, 8182);
	component.getServers().add(server);

	final Application app = new ApiApplication();
	component.getDefaultHost().attachDefault(app);
	try {
		component.start();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
源代码4 项目: uReplicator   文件: WorkerStarter.java
public void runRestApplication() throws Exception {
  if (workerConf.getWorkerPort() == 0) {
    return;
  }
  Component _component = new Component();
  _component.getServers().add(Protocol.HTTP, workerConf.getWorkerPort());
  _component.getClients().add(Protocol.FILE);
  _component.getClients().add(Protocol.JAR);

  Context applicationContext = _component.getContext().createChildContext();
  LOGGER.info("Injecting workerInstance to the api context, port {}", workerConf.getWorkerPort());
  applicationContext.getAttributes().put(WorkerInstance.class.toString(), workerInstance);

  Application restletApplication = new RestletApplication(null);
  restletApplication.setContext(applicationContext);

  _component.getDefaultHost().attach(restletApplication);
  _component.start();
}
 
源代码5 项目: uReplicator   文件: ManagerStarter.java
public void start() throws Exception {
  _component.getServers().add(Protocol.HTTP, _config.getManagerPort());
  _component.getClients().add(Protocol.FILE);
  _component.getClients().add(Protocol.JAR);

  Context applicationContext = _component.getContext().createChildContext();
  LOGGER.info("Injecting conf and helix to the api context");
  applicationContext.getAttributes().put(ManagerConf.class.toString(), _config);
  applicationContext.getAttributes()
      .put(ControllerHelixManager.class.toString(), _controllerHelixManager);
  applicationContext.getAttributes()
      .put(KafkaClusterValidationManager.class.toString(), _kafkaValidationManager);
  Application managerRestApp = new ManagerRestApplication(null);
  managerRestApp.setContext(applicationContext);

  _component.getDefaultHost().attach(managerRestApp);

  try {
    LOGGER.info("Starting helix manager");
    _controllerHelixManager.start();
    LOGGER.info("Starting src and dst kafka cluster validation manager");
    _kafkaValidationManager.start();
    LOGGER.info("Starting API component");
    _component.start();
  } catch (final Exception e) {
    LOGGER.error("Caught exception while starting uReplicator-Manager", e);
    throw e;
  }
}
 
源代码6 项目: microservices-comparison   文件: RestComponent.java
@Inject
public RestComponent(@Hello Application helloApp, @Car Application carApp, Verifier authTokenVerifier) {
    getClients().add(Protocol.HTTPS);
    Server secureServer = getServers().add(Protocol.HTTPS, 8043);
    Series<Parameter> parameters = secureServer.getContext().getParameters();
    parameters.add("sslContextFactory", "org.restlet.engine.ssl.DefaultSslContextFactory");
    parameters.add("keyStorePath", System.getProperty("javax.net.ssl.keyStorePath"));
    getDefaultHost().attach("/api/hello", secure(helloApp, authTokenVerifier, "ame"));
    getDefaultHost().attach("/api/cars", secure(carApp, authTokenVerifier, "ame"));
    replaceConverter(JacksonConverter.class, new JacksonCustomConverter());
}
 
源代码7 项目: microservices-comparison   文件: RestComponent.java
private Restlet secure(Application app, Verifier verifier, String realm) {
    ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext().createChildContext(),
            ChallengeScheme.HTTP_OAUTH_BEARER, realm);
    guard.setVerifier(verifier);
    guard.setNext(app);
    return guard;
}
 
源代码8 项目: ontopia   文件: ContextUtils.java
public static Context getCurrentApplicationContext() {
	Application application = Application.getCurrent();
	if (application == null) {
		return null;
	}
	return application.getContext();
}
 
源代码9 项目: ontopia   文件: OntopiaServlet.java
@Override
protected Application createApplication(Context parentContext) {
	Application application = super.createApplication(parentContext);
	
	if (application == null) {
		application = new OntopiaRestApplication(parentContext.createChildContext());
	}
	
	return application;
}
 
源代码10 项目: scava   文件: Activator.java
public void start(BundleContext context) throws Exception {
	
	System.err.println("Starting Admin bundle");
	
	context.addServiceListener(new ServiceListener() {
		
		@Override
		public void serviceChanged(ServiceEvent event) {
			System.err.println(event);
			if (event.getType() == ServiceEvent.REGISTERED){
				Application application = new AdminApplication();

				component = new Component();
				component.getServers().add(Protocol.HTTP, 8183);
				component.getClients().add(Protocol.FILE);

				boolean useAuth = Boolean.valueOf(Configuration.getInstance().getProperty("adminapi.use_authentication", "false"));
				
				if (useAuth) {
					String username = Configuration.getInstance().getProperty("adminapi.username", null);
					String password = Configuration.getInstance().getProperty("adminapi.password", null);
					
					ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "myRealm");
					MapVerifier verifier = new MapVerifier();
					verifier.getLocalSecrets().put(username, password.toCharArray());
					guard.setVerifier(verifier);
					guard.setNext(application);
					
					component.getDefaultHost().attachDefault(guard);
				} else {
					component.getDefaultHost().attachDefault(application);
				}
				
				try {
					component.start();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}, "(objectclass=" + ApiStartServiceToken.class.getName() +")");
}
 
源代码11 项目: microservices-comparison   文件: CarModule.java
@Override
protected void configure() {
    bind(Application.class).annotatedWith(Car.class).to(CarApplication.class);
    bind(CarRepository.class).to(InMemoryCarRepository.class);
}
 
源代码12 项目: microservices-comparison   文件: HelloModule.java
@Override
protected void configure() {
    bind(Application.class).annotatedWith(Hello.class).to(HelloApplication.class);
    bind(CarService.class).to(RemoteCarService.class);
}
 
@Override
@SuppressWarnings( "unchecked" )
protected Application createApplication( Context context )
{
    return module.newObject( Application.class, context.createChildContext(), getServletConfig(), getServletContext() );
}