示例#1
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();
  }
 /**
  * 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();
 }
  /**
   * 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();
  }
  @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();
  }
  @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();
  }
示例#6
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();
    }
  }
示例#7
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();
  }
  public void testTemplateFilter() {
    try {
      // Create a temporary directory for the tests
      this.testDir = new File(System.getProperty("java.io.tmpdir"), "TemplateFilterTestCase");
      deleteDir(this.testDir);
      this.testDir.mkdir();

      // Create temporary template files
      // Will be templated
      final File testFileFm1 = new File(this.testDir, "testFm1.txt.fmt");
      FileWriter fw = new FileWriter(testFileFm1);
      fw.write("Method=${m}/Authority=${ra}");
      fw.close();

      // Will not be templated
      final File testFileFm2 = new File(this.testDir, "testFm2.txt");
      fw = new FileWriter(testFileFm2);
      fw.write("Method=${m}/Authority=${ra}");
      fw.close();

      // Will be templated
      final File testFileVl1 = new File(this.testDir, "testVl1.txt.vm");
      fw = new FileWriter(testFileVl1);
      fw.write("Method=${m}/Path=${rp}");
      fw.close();

      // Will not be templated
      final File testFileVl2 = new File(this.testDir, "testVl2.txt");
      fw = new FileWriter(testFileVl2);
      fw.write("Method=${m}/Path=${rp}");
      fw.close();

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

      // Create an application filtered with Freemarker
      final MyFreemakerApplication freemarkerApplication = new MyFreemakerApplication(this.testDir);
      // Create an application filtered with Velocity
      final MyVelocityApplication velocityApplication = new MyVelocityApplication(this.testDir);

      // Attach the applications to the component and start it
      component.getDefaultHost().attach("/freemarker", freemarkerApplication);
      component.getDefaultHost().attach("/velocity", velocityApplication);

      // Now, let's start the component!
      component.start();

      // Allow extensions tunneling
      freemarkerApplication.getTunnelService().setExtensionsTunnel(true);
      velocityApplication.getTunnelService().setExtensionsTunnel(true);
      final Client client = new Client(Protocol.HTTP);
      Response response = client.get("http://localhost:8182/freemarker/" + testFileFm1.getName());
      if (response.isEntityAvailable()) {
        assertEquals(response.getEntity().getText(), "Method=GET/Authority=localhost:8182");
      }
      response = client.get("http://localhost:8182/freemarker/" + testFileFm2.getName());
      assertTrue(response.getStatus().isSuccess());
      if (response.isEntityAvailable()) {
        assertEquals(response.getEntity().getText(), "Method=${m}/Authority=${ra}");
      }

      response = client.get("http://localhost:8182/velocity/" + testFileVl1.getName());
      if (response.isEntityAvailable()) {
        assertEquals(response.getEntity().getText(), "Method=GET/Path=/velocity/testVl1");
      }
      response = client.get("http://localhost:8182/velocity/" + testFileVl2.getName());
      assertTrue(response.getStatus().isSuccess());
      if (response.isEntityAvailable()) {
        assertEquals(response.getEntity().getText(), "Method=${m}/Path=${rp}");
      }
      // Now, let's stop the component!
      component.stop();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }