Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This code is placed in the public domain by its author, Tim Peierls.
- */
- package com.example.server;
- import com.google.inject.Stage;
- import javax.inject.Inject;
- import javax.inject.Named;
- import javax.inject.Singleton;
- import org.restlet.Component;
- import org.restlet.data.Protocol;
- //import org.restlet.ext.guice.FinderFactory;
- import org.restlet.routing.VirtualHost;
- import org.restlet.util.ClientList;
- /**
- * The main Restlet component
- */
- @Singleton
- public class MainComponent extends Component {
- /**
- * For binding a port number in standalone mode (e.g., {@code @Named(HTTP_PORT) int port}).
- */
- public static final String HTTP_PORT = "main.httpPort";
- /**
- * Component that contains Restlet applications, deployable in either
- * standalone or servlet mode.
- */
- @Inject MainComponent() {
- setName("Main component");
- setDescription("The main component");
- setOwner("My Organization");
- setAuthor("Me");
- }
- /**
- * Configure connectors and wire application(s) to host(s).
- */
- @Inject void initialize(
- // Not used in this example, but can be injected to provide
- // behavior that depends on the Guice stage.
- Stage stage,
- // Used here to decide whether to set up an HTTP server connector.
- DeploymentMode deploymentMode,
- // Not used in this example, but can be injected in applications for
- // creating Finder instances that will inject resources, e.g.:
- // router.attach("/path/to/my/resource", ff.finder(MyServerResource.class));
- // Needs the Restlet-Guice extension; see the {@link Main} class, where the
- // injector is created with Guice.createInjector, but could use instead
- // RestletGuice.createInjector.
- //FinderFactory ff,
- // Other dependencies go here, e.g., applications and other restlets.
- //
- // MyApplication app1,
- // MyOtherApplication app2,
- @Named(HTTP_PORT) int httpPort
- ) {
- getLogger().info(String.format(
- "Component running in %s mode in %s stage.",
- deploymentMode, stage));
- switch (deploymentMode) {
- case SERVLET:
- // In servlet mode the HTTP listener is set up automatically.
- // No need to add to the server list.
- break;
- case STANDALONE:
- default:
- // In standalone mode we have set to it up explictly.
- getServers().add(Protocol.HTTP, httpPort);
- break;
- }
- ClientList clients = getClients();
- clients.add(Protocol.RIAP);
- clients.add(Protocol.CLAP);
- clients.add(Protocol.HTTP);
- //clients.add(Protocol.HTTPS);
- VirtualHost host = getDefaultHost();
- //host.attach("/path/to/app1", app1);
- //host.attach("/path/to/app2", app2);
- // Only accessible from within this component.
- //getInternalRouter().attach("/internal/path", internalApp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement