Java Code Examples for org.restlet.Component#start()

The following examples show how to use org.restlet.Component#start() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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);
			}  
		}
	}
}