public void shutdown() throws Exception {
    if (started) {
      component.stop();

      started = false;
    }
  }
Esempio n. 2
0
 public void stop() {
   try {
     component.stop();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Esempio n. 3
0
 public void stopServer() {
   if (started) {
     try {
       server.stop();
       started = false;
     } catch (Exception e) {
       throw new RuntimeException("Could not stop server", e);
     }
   }
 }
Esempio n. 4
0
 @After
 public void tearDown() {
   try {
     factory.tearDown();
     component.stop();
   } catch (Exception e) {
     e.printStackTrace();
     Assert.fail();
   }
 }
 @Override
 protected void tearDown() throws Exception {
   component.stop();
   component = null;
   super.tearDown();
 }
Esempio n. 6
0
 public void stop(BundleContext context) throws Exception {
   component.stop();
 }
Esempio n. 7
0
 @Override
 public void stopServer() throws Exception {
   component.stop();
 }
 private void stopRestServer() throws Exception {
   log.info("*** stopRestServer ***");
   component.stop();
 }
  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();
    }
  }