Пример #1
0
 public static void main(String[] args) throws Exception {
   Component component = new Component();
   component.getServers().add(Protocol.HTTP, 8182);
   component.getDefaultHost().attach("/text", TextResource.class);
   component.getDefaultHost().attach("/json", JsonResource.class);
   component.start();
 }
Пример #2
0
  /**
   * @param args
   * @throws Exception Something bad happened.
   */
  public static void main(String[] args) throws Exception {

    Component component = new Component();
    component.getServers().add(Protocol.HTTP, 8182);
    //    component.getClients().add(Protocol.FILE);
    component.getClients().add(Protocol.CLAP);

    // Create an application
    Application application =
        new Application() {
          @Override
          public Restlet createInboundRoot() {
            Router router = new Router(getContext());
            // Directory directory = new Directory(getContext(), ROOT_URI);
            ////        String path = "file://" + System.getProperty("user.dir") +
            // "/src/main/resources/spa";
            ////        System.out.println("path: " + path);
            //        Directory directory = new Directory(getContext(), path);
            Directory directory =
                new Directory(
                    getContext(),
                    LocalReference.createClapReference(LocalReference.CLAP_CLASS, "/spa"));
            directory.setIndexName("index.html");
            //        directory.setDeeplyAccessible(true);
            router.attach("/spa/", directory);
            // Directory directory = new Directory(getContext(), "clap://application/spa/");

            return router;
          }
        };

    // Attach the application to the component and start it
    component.getDefaultHost().attach("/wattdepot", application);
    component.start();
  }
Пример #3
0
 @Test
 public void shouldInitializeTlbWithDefaultPortIfNotGiven() {
   Component component = initializer.init();
   ServerList servers = component.getServers();
   assertThat(servers.size(), is(1));
   assertThat(servers.get(0).getPort(), is(7019));
 }
 /**
  * Launches the application with an HTTP server.
  *
  * @param args The arguments.
  * @throws Exception
  */
 public static void main(String[] args) throws Exception {
   Component mailServer = new Component();
   mailServer.getClients().add(Protocol.CLAP);
   mailServer.getServers().add(Protocol.HTTP, 8111);
   mailServer.getDefaultHost().attach(new MailServerApplication());
   mailServer.start();
 }
Пример #5
0
  /**
   * A map of all values global to all running applications.
   *
   * <p>Note that this could be null if shared globals are not set up.
   *
   * @return The shared globals or null
   * @see #getComponent()
   */
  public ConcurrentMap<String, Object> getSharedGlobals() {
    if (sharedGlobals == null) {
      Component component = getComponent();
      if (component != null) sharedGlobals = component.getContext().getAttributes();
    }

    return sharedGlobals;
  }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   component = new Component();
   component.getServers().add(Protocol.HTTP, TEST_PORT);
   component.getDefaultHost().attach(new TestDigestApplication());
   component.start();
 }
Пример #7
0
 @Override
 public void startServer() throws Exception {
   component = new Component();
   component.getServers().add(Protocol.HTTP, 8182);
   RestApplication application = module.newObject(RestApplication.class, component.getContext());
   component.getDefaultHost().attach(application);
   component.start();
 }
Пример #8
0
  public static void main(String[] args) throws Exception {
    Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
    Engine.getInstance().getRegisteredConverters().add(new HtmlConverter());
    Component c = new Component();
    c.getServers().add(Protocol.HTTP, 9003);

    c.getDefaultHost().attach("/v1", new FormServerApplication());
    c.start();
  }
Пример #9
0
 public static void main(String[] args) throws Exception {
   Component component = new Component();
   Server server = new Server(Protocol.HTTP, 8312);
   component.getServers().add(server);
   server.getContext().getParameters().set("maxTotalConnections", Defaults.MAX_CONNECTIONS);
   server.getContext().getParameters().set("maxThreads", Defaults.MAX_THREADS);
   component.getDefaultHost().attach(new SubscriberTest());
   component.start();
 }
 private void initializeRestServer() throws Exception {
   log.info("*** initializeRestServer ***");
   component = new Component();
   // Add a new HTTP server listening on port 8182.
   component.getServers().add(Protocol.HTTP, REST_PORT);
   // component.getDefaultHost().attach(new
   // ActivitiRestServicesApplication());
   component.getDefaultHost().attach(new EsDmsActivitiRestServicesApplication());
   component.start();
 }
Пример #11
0
  public void start(BundleContext context) throws Exception {
    // Create a component
    component = new Component();
    component.getServers().add(Protocol.HTTP, 8088);

    // Create an application
    final Application application = new Test12();

    // Attach the application to the component and start it
    component.getDefaultHost().attachDefault(application);
    component.start();
  }
Пример #12
0
  public void start() {
    KillBugApp app = new KillBugApp();

    component.getServers().add(Protocol.HTTP, port);

    component.getDefaultHost().attach(app);
    try {
      component.start();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    component.getServers().add(Protocol.HTTP, 8111);
    component.getClients().add(Protocol.CLAP);
    component
        .getDefaultHost()
        .attach("/CoopOData.svc", new org.restlet.test.ext.odata.deepexpand.feed.CoOpApplication());
    component.start();

    service = new ContainerService();
  }
  /**
   * Run the example as a standalone component.
   *
   * @param args The optional arguments.
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    // Create a component
    Component component = new Component();
    component.getServers().add(Protocol.HTTP, 8111);
    component.getClients().add(Protocol.FILE);

    // Create an application
    Application application = new Part09a_GuardAccess();

    // Attach the application to the component and start it
    component.getDefaultHost().attachDefault(application);
    component.start();
  }
Пример #15
0
 public void startServer() {
   if (!started) {
     server = new Component();
     server.getServers().add(Protocol.HTTP, getConfig().getPort());
     server.getDefaultHost().attach(this);
     try {
       server.start();
       started = true;
     } catch (Exception e) {
       stopServer();
       throw new RuntimeException("Exception while starting server", e);
     }
   }
 }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    component = new Component();
    component.getServers().add(Protocol.HTTP, TEST_PORT);
    component.getClients().add(Protocol.FILE);
    component.getDefaultHost().attach(new TestRangeApplication());
    component.start();

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 1000; i++) {
      sb.append("1");
    }
    str1000 = sb.toString();
  }
  public void shutdown() throws Exception {
    if (started) {
      component.stop();

      started = false;
    }
  }
Пример #18
0
 public void start() {
   try {
     _component.start();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Пример #19
0
 public void stop() {
   try {
     component.stop();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Пример #20
0
  @Before
  public void setUp() {
    testContext = new Context();

    component = new Component();
    component.getServers().add(Protocol.HTTP, PORT);
    component.getClients().add(Protocol.CLAP);
    component.getClients().add(Protocol.FILE);
    component.getDefaultHost().attach(testApp);

    try {
      component.start();
      factory.setUp();
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail();
    }
  }
  public void start(Properties configuration) throws Exception {
    if (!started) {
      component = new Component();
      component
          .getServers()
          .add(
              Protocol.HTTP,
              Integer.valueOf(configuration.getProperty(MediaServerConfiguration.HTTP_PORT)));

      Context context = component.getContext().createChildContext();
      component.getDefaultHost().attach(new MediaServerApplication(context));

      component.start();

      LOGGER.debug("Started test HTTP server");

      started = true;
    }
  }
Пример #22
0
 public void stopServer() {
   if (started) {
     try {
       server.stop();
       started = false;
     } catch (Exception e) {
       throw new RuntimeException("Could not stop server", e);
     }
   }
 }
Пример #23
0
  public static void main(String[] args) throws Exception {
    // Create a component
    Component component = new Component();
    component.getServers().add(Protocol.HTTP, 8182);
    component.getClients().add(Protocol.FILE);

    // Create an application
    Application application =
        new Application() {
          @Override
          public Restlet createInboundRoot() {
            return new Directory(getContext(), ROOT_URI);
          }
        };

    // Attach the application to the component and start it
    component.getDefaultHost().attach(application);
    component.start();
  }
Пример #24
0
 @After
 public void tearDown() {
   try {
     factory.tearDown();
     component.stop();
   } catch (Exception e) {
     e.printStackTrace();
     Assert.fail();
   }
 }
Пример #25
0
  public static void main(String[] args) {
    System.out.println("Starting server");

    try {
      // Create a new Component.
      Component component = new Component();

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

      // Attach the sample application.
      component.getDefaultHost().attach("/main", new QServerApplication());

      // Start the component.
      component.start();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Пример #26
0
  public void activate() throws RESTException {
    /*
     * server opstarten
     */
    servicesByID = new HashMap<String, Object>();
    methodsByString = new HashMap<String, Method>();
    clientsByString = new HashMap<String, ClientResource>();

    component = new Component();
    Server server = component.getServers().add(Protocol.HTTP, 8080);
    try {
      server.start();
    } catch (Exception e1) {
      throw new RESTException("Error starting the server", e1);
    }

    /*
     * ServiceListener that automatically exports services with exported interfaces
     * as defined by the Remote Services specification
     */
    try {
      ServiceTracker serviceTracker =
          new ServiceTracker(
              context,
              context.createFilter("(service.exported.interfaces=*)"),
              new ServiceTrackerCustomizer() {

                @Override
                public Object addingService(ServiceReference ref) {
                  Collection<ExportRegistration> regs = exportService(ref, null);
                  return regs;
                }

                @Override
                public void modifiedService(ServiceReference ref, Object regs) {}

                @Override
                public void removedService(ServiceReference ref, Object regs) {
                  for (ExportRegistration r : (Collection<ExportRegistration>) regs) {
                    r.close();
                  }
                }
              });
      serviceTracker.open();
    } catch (InvalidSyntaxException e) {
    }
  }
Пример #27
0
  @Override
  public Collection<ExportRegistration> exportService(
      ServiceReference reference, Map<String, ?> properties) {
    // Kortom:
    // - we hebben een implementatie (in reference) van een service
    // - de interface moeten we wel aangeraken (kan in properties)
    // - die moeten we toevoegen aan de Restlet server...
    Object serviceObject = context.getService(reference);
    Method[] methods = serviceObject.getClass().getMethods();

    String id = "" + reference.getProperty("service.id");
    servicesByID.put(id, serviceObject);

    for (int i = 0; i < methods.length; i++) {
      String URI = "/" + id + "/" + RESTImportProxyHandler.methodToID(methods[i]);
      methodsByString.put(URI, methods[i]);

      component.getDefaultHost().attach(URI, RemoteMethod.class);
    }

    return null; // Sorry, not supported -Jeroen
  }
Пример #28
0
 /**
  * Constructor.
  *
  * @param component The parent component.
  */
 public ServerRouter(Component component) {
   super((component == null) ? null : component.getContext().createChildContext());
   this.component = component;
   setRoutingMode(MODE_FIRST_MATCH);
 }
 @Override
 protected void tearDown() throws Exception {
   component.stop();
   component = null;
   super.tearDown();
 }
Пример #30
0
 public static void main(String[] args) throws Exception {
   Component component = new DemoComponent();
   component.start();
 }