@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) { } }
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")); }
@Before public void init() throws InterruptedException { counter = 0; random = new Random(DateTime.now().getMillis()); gson = new Gson(); httpServer = new HttpServer(); httpServer.start(); }
public static void main(String args[]) { try { HttpServer server = new HttpServer(7896); server.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
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(); }
public void startHttpServer(HttpServer httpServer) throws Exception { httpServer.start(); SysLog.logInfo("http server was started"); }