org.restlet.Component Java Examples

The following examples show how to use org.restlet.Component. 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: Activator.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
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() +")");
  }
 
Example #2
Source File: ApiAnalysisTests.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@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();
	}
}
 
Example #3
Source File: ProjectAnalysisTests.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@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();
	}
}
 
Example #4
Source File: ControllerInstance.java    From uReplicator with Apache License 2.0 6 votes vote down vote up
public ControllerInstance(ManagerControllerHelix managerControllerHelix, ControllerConf conf) {
  LOGGER.info("Trying to init ControllerStarter with config: {}", conf);
  _managerControllerHelix = managerControllerHelix;
  _config = conf;
  initializeMetricsReporter(conf);
  _component = new Component();
  _controllerRestApp = new ControllerRestApplication(null);
  _helixMirrorMakerManager = new HelixMirrorMakerManager(_config);
  _validationManager = new ValidationManager(_helixMirrorMakerManager);
  _srcKafkaValidationManager = getSourceKafkaClusterValidationManager();
  _autoTopicWhitelistingManager = getAutoTopicWhitelistingManager();
  if (_config.getBackUpToGit()) {
    _clusterInfoBackupManager = new ClusterInfoBackupManager(_helixMirrorMakerManager,
        new GitBackUpHandler(conf.getRemoteBackupRepo(), conf.getLocalGitRepoPath()), _config);
  } else {
    _clusterInfoBackupManager = new ClusterInfoBackupManager(_helixMirrorMakerManager,
        new FileBackUpHandler(conf.getLocalBackupFilePath()), _config);
  }
}
 
Example #5
Source File: WorkerStarter.java    From uReplicator with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #6
Source File: OntopiaServlet.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@Override
protected Component createComponent() {
	Component component = super.createComponent();
	
	// a bit more configuration by initParams
	LogService log = component.getLogService();
	
	// allow access to the LogService in the application via the context
	component.getContext().getAttributes().put(LogService.class.getName(), log);
	
	// modify the logger name
	String loggerName = getInitParameter(LOGGER_NAME_ATTRIBUTE, LOGGER_NAME_ATTRIBUTE_DEFAULT_VALUE);
	log.setLoggerName(loggerName);
	
	// modify the logger pattern
	// note: overridden to be smaller than the restlet default value
	log.setResponseLogFormat(getInitParameter(LOGGER_FORMAT_ATTRIBUTE, LOGGER_FORMAT_ATTRIBUTE_DEFAULT_VALUE));
	
	return component;
}
 
Example #7
Source File: RunApp.java    From AGDISTIS with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
	try {
		// Create a new Component.
		Component component = new Component();

		// Add a new HTTP server listening on port 8082.
		component.getServers().add(Protocol.HTTP, 8080);

		// Attach the sample application.
		component.getDefaultHost().attach(new RestletApplication());

		// Start the component.
		component.start();
	} catch (Exception e) {
		// Something is wrong.
		e.printStackTrace();
	}
}
 
Example #8
Source File: ManagerStarter.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public ManagerStarter(ManagerConf conf) {
  LOGGER.info("Trying to init ManagerStarter with config: {}", conf);
  _config = conf;
  initializeMetricsReporter(conf);
  _component = new Component();
  _kafkaValidationManager = new KafkaClusterValidationManager(_config);
  _controllerHelixManager = new ControllerHelixManager(_kafkaValidationManager, _config);
}
 
Example #9
Source File: Activator.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
public void start(final BundleContext context) throws Exception {
	component = new Component();
	component.getServers().add(Protocol.HTTP, 8888);
	component.getClients().add(Protocol.CLAP);
	component.getDefaultHost().attach("", new RestService(context));
	component.start();
}
 
Example #10
Source File: RestApiServer.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
public void run(FloodlightModuleContext fmlContext, String restHost, int restPort) {
    setStatusService(new StatusService() {
        @Override
        public Representation getRepresentation(Status status,
                                                Request request,
                                                Response response) {
            return new JacksonRepresentation<Status>(status);
        }                
    });
    
    // Add everything in the module context to the rest
    for (Class<? extends IFloodlightService> s : fmlContext.getAllServices()) {
        if (logger.isTraceEnabled()) {
            logger.trace("Adding {} for service {} into context",
                         s.getCanonicalName(), fmlContext.getServiceImpl(s));
        }
        context.getAttributes().put(s.getCanonicalName(), 
                                    fmlContext.getServiceImpl(s));
    }
    
    // Start listening for REST requests
    try {
        final Component component = new Component();
        if (restHost == null) {
        	component.getServers().add(Protocol.HTTP, restPort);
        } else {
        	component.getServers().add(Protocol.HTTP, restHost, restPort);
        }
        component.getClients().add(Protocol.CLAP);
        component.getDefaultHost().attach(this);
        component.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #11
Source File: RestServerMixin.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@Override
public void startServer()
    throws Exception
{
    configuration.refresh();

    component = new Component();
    component.getServers().add( Protocol.HTTP, configuration.get().port().get() );
    RestApplication application = module.newObject( RestApplication.class, component.getContext() );
    component.getDefaultHost().attach( application );
    component.start();
}
 
Example #12
Source File: FoxbpmRestServer.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	
	 Component component = new Component();
	 component.getServers().add(Protocol.HTTP, 8082);
	 component.getDefaultHost().attach(new FoxbpmRestApplication());
	 component.start();     
	 System.out.println("The restlet server started ...");
}
 
Example #13
Source File: RestService.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
@Override
public void start() throws UnknownHostException {
	if (isEnabled) {
		final boolean isRunning = this.isRunning.getAndSet(true);
		if (!isRunning) {
			if (isEnabled && port <= 0) {
				this.isEnabled = false;
				TestServerConsole.log("Could not start RestService. Parameter missing: 'server.service.rest.port'", 1, TestServerServiceEnum.TEST_SERVER);
			}
			 
		    Component component = new Component();  

		    Server s = component.getServers().add(isSsl ? Protocol.HTTPS : Protocol.HTTP, InetAddress.getLocalHost().getHostAddress(), port);
		    
		    if (isSsl) {
			    Series<Parameter> parameters = s.getContext().getParameters();				    
			    parameters.add("keystorePath", QOS_KEY_FILE_ABSOLUTE);
			    parameters.add("keystorePassword", TestServer.QOS_KEY_PASSWORD);
			    parameters.add("keyPassword", TestServer.QOS_KEY_PASSWORD);
			    parameters.add("keystoreType", TestServer.QOS_KEY_TYPE);
		    }

		    component.getDefaultHost().attach("", new RestletApplication());
		    
		    try {
				component.start();
				TestServerConsole.log("[" + getName() + "] started: " + toString(), 1, TestServerServiceEnum.TEST_SERVER);
			} catch (Exception e) {
				TestServerConsole.error(getName(), e, 0, TestServerServiceEnum.TEST_SERVER);
			}  
		}
	}
}
 
Example #14
Source File: WorkspaceResourceServerManagerTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    workspaceResourceServerManager = WorkspaceResourceServerManager.getInstance();
    port = SocketUtil.findFreePort();
    workspaceResourceServerManager.start(port);

    final Component component = workspaceResourceServerManager.getComponent();
    assertThat(component).isNotNull();
    assertThat(component.isStarted()).isTrue();
    assertThat(component.getServers()).hasSize(1);
    server = component.getServers().get(0);

    defaultHost = component.getDefaultHost();
}
 
Example #15
Source File: Activator.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
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() +")");
}
 
Example #16
Source File: WorkspaceResourceServerManager.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected Component getComponent() {
    return component;
}