Skip to content

Commit

Permalink
Refactor javalin logic according to version 5
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Jun 20, 2023
1 parent 9b28de5 commit 35bbfc2
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/main/java/io/github/bonigarcia/wdm/WdmServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static io.github.bonigarcia.wdm.WebDriverManager.firefoxdriver;
import static io.github.bonigarcia.wdm.WebDriverManager.iedriver;
import static io.github.bonigarcia.wdm.WebDriverManager.operadriver;
import static io.javalin.http.HandlerType.DELETE;
import static java.lang.invoke.MethodHandles.lookup;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.io.FileUtils.openInputStream;
Expand Down Expand Up @@ -60,6 +61,7 @@
import io.javalin.Javalin;
import io.javalin.http.Context;
import io.javalin.http.Handler;
import io.javalin.http.HandlerType;

/**
* WebDriverManager server.
Expand All @@ -70,9 +72,6 @@
public class WdmServer {

private static final String SESSION = "/session";
private static final String GET = "GET";
private static final String DELETE = "DELETE";
private static final String POST = "POST";
private static final String SESSIONID = "\"sessionId\":";

static final Logger log = getLogger(lookup().lookupClass());
Expand Down Expand Up @@ -125,7 +124,7 @@ private String getLocalHostAddress() {
}

private void handleRequest(Context ctx) throws IOException {
String requestMethod = ctx.method();
HandlerType requestMethod = ctx.method();
String requestPath = ctx.path();
log.info("Request: {} {}", requestMethod, requestPath);

Expand All @@ -141,7 +140,7 @@ private void handleRequest(Context ctx) throws IOException {
}

private void seleniumServer(Context ctx) throws IOException {
String requestMethod = ctx.method();
HandlerType requestMethod = ctx.method();
String requestPath = ctx.path().replace(path, "");
String requestBody = ctx.body();
log.debug("Body: {} ", requestBody);
Expand Down Expand Up @@ -185,8 +184,7 @@ private void seleniumServer(Context ctx) throws IOException {
}

// DELETE /session/sessionId
if (requestMethod.equalsIgnoreCase(DELETE)
&& requestPath.startsWith(SESSION + "/")) {
if (requestMethod == DELETE && requestPath.startsWith(SESSION + "/")) {
String sessionIdFromPath = getSessionIdFromPath(requestPath);
wdmMap.get(sessionIdFromPath).quit();
wdmMap.remove(sessionIdFromPath);
Expand Down Expand Up @@ -262,7 +260,7 @@ private synchronized void resolveDriver(Context ctx,
String driverLength = String.valueOf(driver.length());

// Response
ctx.res.setHeader("Content-Disposition",
ctx.res().setHeader("Content-Disposition",
"attachment; filename=\"" + driverName + "\"");
ctx.result(openInputStream(driver));
log.info("Server response: {} {} ({} bytes)", driverName, driverVersion,
Expand All @@ -274,7 +272,7 @@ private synchronized void resolveDriver(Context ctx,
}
}

public String exchange(String url, String method, String json,
public String exchange(String url, HandlerType method, String json,
int timeoutSec) throws IOException {
String responseContent = null;
BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
Expand Down

0 comments on commit 35bbfc2

Please sign in to comment.