_component.getClients().add(Protocol.WAR); final Context applicationContext = _component.getContext().createChildContext();
/** * Constructor. * * @param component * The parent component. */ public SpringHost(Component component) { super(component.getContext()); }
public class CustomRedirector extends Redirector { public CustomRedirector(Component component, String targetPattern, int mode) { super(component.getContext(), targetPattern, mode); } }
/** * Constructor. * * @param component * The parent component. */ public ClientRouter(Component component) { super((component == null) ? null : component.getContext() .createChildContext()); this.component = component; }
/** * Constructor. * * @param component * The parent component. */ public ServerRouter(Component component) { super((component == null) ? null : component.getContext() .createChildContext()); this.component = component; setRoutingMode(MODE_FIRST_MATCH); }
Component component = (...) // HTTPS VirtualHost hostHttps = new VirtualHost(component.getContext()); component.getHosts().add(hostHttps); hostHttps.setHostScheme("https"); Restlet restletSecure = (...) hostHttps.attachDefault(restletSecure); // HTTP VirtualHost hostHttp = new VirtualHost(component.getContext()); component.getHosts().add(hostHttp); hostHttp.setHostScheme("http"); Restlet restletUnsecure = (...) hostHttp.attachDefault(restletUnsecure);
final Component component = new Component(); component.getClients().add(Protocol.CLAP); final Directory dir = new Directory(component.getContext(), "clap://class/META-INF/resources/webjars"); dir.setDeeplyAccessible(true); this.attach("/webjars", dir); //access via http://example.com/webjars/jquery/1.9.0/jquery.min.js
@Override public Context createChildContext() { return new ChildContext(getComponentHelper().getHelped().getContext()); }
Component serverComponent = new Component(); serverComponent.getServers().add(Protocol.HTTP, 8080); final Router router = new Router(serverComponent.getContext().createChildContext()); router.attach("/myrestendpoint", MyServerResource.class); serverComponent.getDefaultHost().attach(router); serverComponent.start();
Component component = new Component(); component.getServers().add(Protocol.HTTP, 8182); // JAXRS application JaxRsApplication application = new JaxRsApplication(component.getContext()); application.add(new MyApplication()); // Attachment component.getDefaultHost().attachDefault(application); // Start component.start();
@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; } }
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(SourceKafkaClusterValidationManager.class.toString(), _srcKafkaValidationManager); Application managerRestApp = new ManagerRestApplication(null); managerRestApp.setContext(applicationContext); _component.getDefaultHost().attach(managerRestApp); try { LOGGER.info("Starting helix manager"); _controllerHelixManager.start(); LOGGER.info("Starting source kafka cluster validation manager"); _srcKafkaValidationManager.start(); LOGGER.info("Starting API component"); _component.start(); } catch (final Exception e) { LOGGER.error("Caught exception while starting uReplicator-Manager", e); throw e; } }
public static void main(String[] args) throws Exception { // create Component (as ever for Restlet) final Component comp = new Component(); final Server server = comp.getServers().add(Protocol.HTTP, 80); // create JAX-RS runtime environment final JaxRsApplication application = new JaxRsApplication(comp .getContext().createChildContext()); // attach ApplicationConfig application.add(new ExampleApplication()); // Attach the application to the component and start it comp.getDefaultHost().attach(application); comp.start(); System.out.println("Server started on port " + server.getPort()); System.out.println("Press key to stop server"); System.in.read(); System.out.println("Stopping server"); comp.stop(); System.out.println("Server stopped"); } }
.getContext()); getServletContext().setAttribute( applicationAttributeName, result);
.getContext()); getServletContext().setAttribute( applicationAttributeName, result);
host = new VirtualHost(component.getContext().createChildContext()); host.setHostDomain(hostDomain); host.setHostPort(hostPort);
public synchronized void start() throws Exception { LOG.info("helixAdminWebApp starting"); if (_component == null) { _zkClient = new ZkClient(_zkServerAddress, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer()); _rawZkClient = new ZkClient(_zkServerAddress, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer()); _component = new Component(); _component.getServers().add(Protocol.HTTP, _helixAdminPort); Context applicationContext = _component.getContext().createChildContext(); applicationContext.getAttributes() .put(RestAdminApplication.ZKSERVERADDRESS, _zkServerAddress); applicationContext.getAttributes().put(RestAdminApplication.PORT, "" + _helixAdminPort); applicationContext.getAttributes().put(RestAdminApplication.ZKCLIENT, _zkClient); applicationContext.getAttributes().put(ResourceUtil.ContextKey.RAW_ZKCLIENT.toString(), _rawZkClient); _adminApp = new RestAdminApplication(applicationContext); // Attach the application to the component and start it _component.getDefaultHost().attach(_adminApp); _component.start(); } LOG.info("helixAdminWebApp started on port: " + _helixAdminPort); }
/** * Constructor. */ public Component() { super(); this.hosts = new CopyOnWriteArrayList<VirtualHost>(); this.clients = new ClientList(null); this.servers = new ServerList(null, this); this.realms = new CopyOnWriteArrayList<Realm>(); this.services = new ServiceList(getContext()); if (Engine.getInstance() != null) { // To be done before setting the helper... this.services.add(new org.restlet.service.TaskService()); this.helper = new ComponentHelper(this); Context childContext = getContext().createChildContext(); this.defaultHost = new VirtualHost(childContext); this.internalRouter = new InternalRouter(childContext); this.services.add(new LogService()); getLogService().setContext(childContext); this.services.add(new StatusService()); getStatusService().setContext(childContext); this.clients.setContext(childContext); this.servers.setContext(childContext); } }
@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(); }
/** Starts the Restlet. */ @Override public synchronized void start() throws Exception { // Attach all virtual hosts for (VirtualHost host : getComponent().getHosts()) { getRoutes().add(new HostRoute(this, host)); } // Also attach the default host if it exists if (getComponent().getDefaultHost() != null) { getRoutes().add( new HostRoute(this, getComponent().getDefaultHost())); } // If no host matches, display and error page with a precise message final Restlet noHostMatched = new Restlet(getComponent().getContext() .createChildContext()) { @Override public void handle(Request request, Response response) { response.setStatus(Status.CLIENT_ERROR_NOT_FOUND, "No virtual host could handle the request"); } }; setDefaultRoute(new org.restlet.routing.TemplateRoute(this, "", noHostMatched)); // Start the router super.start(); }