Skip to content

Commit

Permalink
Revert "Refactor javalin logic according to version 5"
Browse files Browse the repository at this point in the history
This reverts commit 35bbfc2.
  • Loading branch information
bonigarcia committed Aug 22, 2023
1 parent 8e8d191 commit 09046a6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/main/java/io/github/bonigarcia/wdm/WdmServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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 @@ -61,7 +60,6 @@
import io.javalin.Javalin;
import io.javalin.http.Context;
import io.javalin.http.Handler;
import io.javalin.http.HandlerType;

/**
* WebDriverManager server.
Expand All @@ -72,6 +70,9 @@
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 @@ -124,7 +125,7 @@ private String getLocalHostAddress() {
}

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

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

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

// DELETE /session/sessionId
if (requestMethod == DELETE && requestPath.startsWith(SESSION + "/")) {
if (requestMethod.equalsIgnoreCase(DELETE)
&& requestPath.startsWith(SESSION + "/")) {
String sessionIdFromPath = getSessionIdFromPath(requestPath);
wdmMap.get(sessionIdFromPath).quit();
wdmMap.remove(sessionIdFromPath);
Expand Down Expand Up @@ -260,7 +262,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 @@ -272,7 +274,7 @@ private synchronized void resolveDriver(Context ctx,
}
}

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

0 comments on commit 09046a6

Please sign in to comment.