use of cloud.piranha.http.api.HttpServer in project piranha by piranhacloud.
the class HttpServerTest method testProcessing.
/**
* Test processing.
*
* @throws Exception when an error occurs.
*/
@Test
void testProcessing() throws Exception {
int port = findPort();
HttpServer server = createServer(port);
server.start();
try {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(HTTP_LOCALHOST_PREFIX + port)).build();
HttpResponse<Void> response = client.send(request, HttpResponse.BodyHandlers.discarding());
assertEquals(200, response.statusCode());
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} finally {
server.stop();
}
}
use of cloud.piranha.http.api.HttpServer in project piranha by piranhacloud.
the class HttpServerTest method testProcessing2.
/**
* Test processing.
*
* @throws Exception when an error occurs.
*/
@Test
void testProcessing2() throws Exception {
int port = findPort();
HttpServer server = createServer(port);
server.start();
try {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(HTTP_LOCALHOST_PREFIX + port)).build();
HttpResponse<Void> response = client.send(request, HttpResponse.BodyHandlers.discarding());
assertEquals(200, response.statusCode());
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} finally {
server.stop();
}
}
use of cloud.piranha.http.api.HttpServer in project piranha by piranhacloud.
the class HttpWebApplicationServerTest method testProcess.
/**
* Test process method.
*
* @throws Exception when a serious error occurs.
*/
@Test
void testProcess() throws Exception {
HttpWebApplicationServer server = new HttpWebApplicationServer();
HttpServer httpServer = new DefaultHttpServer(8180, server, false);
DefaultWebApplication application = new DefaultWebApplication();
application.setContextPath("/context");
application.addServlet("snoop", new TestSnoopServlet());
application.addServletMapping("snoop", "/snoop/*");
server.addWebApplication(application);
server.initialize();
server.start();
httpServer.start();
try {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(new URI("http://localhost:8180/context/snoop/index.html")).build();
HttpResponse<Void> response = client.send(request, HttpResponse.BodyHandlers.discarding());
assertEquals(200, response.statusCode());
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
httpServer.stop();
server.stop();
}
use of cloud.piranha.http.api.HttpServer in project piranha by piranhacloud.
the class HttpWebApplicationServerTest method testSessionUrlRewriting2.
@Test
void testSessionUrlRewriting2() throws Exception {
HttpWebApplicationServer server = new HttpWebApplicationServer();
HttpServer httpServer = new DefaultHttpServer(8182, server, false);
DefaultWebApplication application = new DefaultWebApplication();
application.setContextPath("/context");
application.addServlet("snoop", new TestSnoopServlet());
application.addServletMapping("snoop", "/snoop/*");
server.addWebApplication(application);
server.initialize();
server.start();
httpServer.start();
try {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(new URI("http://localhost:8182/context/snoop/index.html;jsessionid=sessionIdURL")).headers("Cookie", "JSESSIONID=sessionIdCookie").build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertEquals(200, response.statusCode());
assertTrue(response.body().contains("sessionIdCookie"));
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
httpServer.stop();
server.stop();
}
use of cloud.piranha.http.api.HttpServer in project piranha by piranhacloud.
the class IsolatedServerPiranha method run.
/**
* Start method.
*/
@Override
public void run() {
long startTime = System.currentTimeMillis();
LOGGER.log(INFO, () -> "Starting Piranha");
webApplicationServer = new HttpWebApplicationServer();
HttpServer httpServer = ServiceLoader.load(HttpServer.class).findFirst().orElseThrow();
httpServer.setServerPort(8080);
httpServer.setHttpServerProcessor(webApplicationServer);
httpServer.setSSL(ssl);
httpServer.start();
webApplicationServer.start();
File[] webapps = new File("webapps").listFiles();
if (webapps != null) {
if (webapps.length != 0) {
// Limit threads used by Weld, since default is Runtime.getRuntime().availableProcessors(), which is per deployment.
int threadsPerApp = Math.max(2, Runtime.getRuntime().availableProcessors() / webapps.length);
System.setProperty("org.jboss.weld.executor.threadPoolSize", threadsPerApp + "");
}
File deployingFile = createDeployingFile();
Arrays.stream(webapps).parallel().filter(warFile -> warFile.getName().toLowerCase().endsWith(".war")).forEach(warFile -> deploy(warFile, webApplicationServer));
try {
Files.delete(deployingFile.toPath());
} catch (IOException ioe) {
LOGGER.log(WARNING, "Unable to delete deploying file", ioe);
}
}
long finishTime = System.currentTimeMillis();
LOGGER.log(INFO, "Started Piranha");
LOGGER.log(INFO, "It took {0} milliseconds", finishTime - startTime);
File startedFile = createStartedFile();
File pidFile = new File("tmp/piranha.pid");
while (httpServer.isRunning()) {
try {
Thread.sleep(2000);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
if (!pidFile.exists()) {
webApplicationServer.stop();
httpServer.stop();
try {
Files.delete(startedFile.toPath());
} catch (IOException ioe) {
LOGGER.log(WARNING, "Unable to delete PID file", ioe);
}
System.exit(0);
}
}
finishTime = System.currentTimeMillis();
LOGGER.log(INFO, "Stopped Piranha");
LOGGER.log(INFO, "We ran for {0} milliseconds", finishTime - startTime);
}
Aggregations