コード例 #1
0
 @Test
 public void testMultipleStartAndStop() throws IOException, InterruptedException {
   final HttpServer server1 = new HttpServer().port(8086);
   server1.start();
   assertEquals(404, client().newCall(request(8086).build()).execute().code());
   final HttpServer server2 = new HttpServer().port(8087);
   server2.start();
   assertEquals(404, client().newCall(request(8087).build()).execute().code());
   server1.shutdown();
   Thread.sleep(5000L);
   try {
     assertEquals(404, client().newCall(request(8086).build()).execute().code());
     fail("Server should have stopped");
   } catch (final ConnectException ignore) {
   } catch (final InterruptedIOException ignored) {
   }
   assertEquals(404, client().newCall(request(8087).build()).execute().code());
   server2.shutdown();
   Thread.sleep(5000L);
   try {
     assertEquals(404, client().newCall(request(8087).build()).execute().code());
     fail("Server should have stopped");
   } catch (final ConnectException ignore) {
   } catch (final InterruptedIOException ignored) {
   }
 }
コード例 #2
0
  public HttpServerExample(QWidget parent) {
    server = new HttpServer(this);
    if (!server.start()) {
      QMessageBox.critical(
          this, tr("HTTP Server"), tr("Unable to start the server: ") + server.errorString());
      close();
    }

    QPushButton publishButton = new QPushButton(this);
    publishButton.setText("Publish");
    editor = new QTextEdit(this);

    editor.setPlainText(
        "<h1>Server is up and running!</h1>"
            + "You should be able to view it in a normal web browser."
            + " Try this address: http://localhost:"
            + server.serverPort());

    QGridLayout layout = new QGridLayout(this);
    setLayout(layout);
    layout.addWidget(publishButton);
    layout.addWidget(editor);

    publishButton.clicked.connect(this, "publish()");

    setWindowTitle(tr("Simple HTTP Server"));
    setWindowIcon(new QIcon("classpath:com/trolltech/images/qt-logo.png"));
  }
コード例 #3
0
 @Before
 public void init() throws InterruptedException {
   counter = 0;
   random = new Random(DateTime.now().getMillis());
   gson = new Gson();
   httpServer = new HttpServer();
   httpServer.start();
 }
コード例 #4
0
 public static void main(String args[]) {
   try {
     HttpServer server = new HttpServer(7896);
     server.start();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
コード例 #5
0
 protected void setUp() throws Exception {
   super.setUp();
   HttpServerConfiguration config = new HttpServerConfiguration();
   config.setWebappsDir(null);
   config.setServerLogPath("build/test-server.log");
   config.setAccessLogPath("build/test-access.log");
   config.setPort(9000);
   HttpServerFactory factory = HttpServerFactory.getInstance();
   this.server = factory.create(config);
   ApplicationManager manager = server.getApplicationManager();
   Application application = manager.createApplication("test");
   application.addController(new TestAsyncController());
   manager.publish(application);
   server.start();
 }
コード例 #6
0
ファイル: ServerMain.java プロジェクト: snpamueh/wahlzeit
 public void startHttpServer(HttpServer httpServer) throws Exception {
   httpServer.start();
   SysLog.logInfo("http server was started");
 }