org.restlet.Server Java Examples

The following examples show how to use org.restlet.Server. 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: Main.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
public static void main( String[] args )
    throws Exception
{
    Energy4Java polygene = new Energy4Java(  );

    Server server = new Server( Protocol.HTTP, 8888 );

    Application app = polygene.newApplication( new ForumAssembler(), new MetadataService() );

    app.activate();

    ContextRestlet restlet = app.findModule( "REST", "Restlet" ).newObject( ContextRestlet.class, new org.restlet.Context() );

    ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm");
    MapVerifier mapVerifier = new MapVerifier();
    mapVerifier.getLocalSecrets().put("rickard", "secret".toCharArray());
    guard.setVerifier(mapVerifier);

    guard.setNext(restlet);

    server.setNext( restlet );
    server.start();
}
 
Example #5
Source File: RestComponent.java    From microservices-comparison with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #6
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);
			}  
		}
	}
}