Skip to content

Commit

Permalink
Remove gson reference from ExternalSessionKey
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Feb 20, 2018
1 parent 0213e01 commit bb77f73
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions java/server/src/org/openqa/grid/internal/ExternalSessionKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

package org.openqa.grid.internal;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import static org.openqa.selenium.json.Json.MAP_TYPE;

import org.openqa.grid.internal.exception.NewSessionException;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonException;

import java.util.Map;

public class ExternalSessionKey {

Expand Down Expand Up @@ -100,19 +102,19 @@ public static ExternalSessionKey fromWebDriverRequest(String path) {
*/
public static ExternalSessionKey fromJsonResponseBody(String responseBody) {
try {
JsonObject json = new JsonParser().parse(responseBody).getAsJsonObject();
if (json.has("sessionId") && !json.get("sessionId").isJsonNull()) {
return new ExternalSessionKey(json.get("sessionId").getAsString());
Map<String, Object> json = new Json().toType(responseBody, MAP_TYPE);
if (json.get("sessionId") instanceof String) {
return new ExternalSessionKey((String) json.get("sessionId"));
}

// W3C response
if (json.has("value") && json.get("value").isJsonObject()) {
JsonObject value = json.getAsJsonObject("value");
if (value.has("sessionId") && !value.get("sessionId").isJsonNull()) {
return new ExternalSessionKey(value.get("sessionId").getAsString());
if (json.get("value") instanceof Map) {
Map<?, ?> value = (Map<?, ?>) json.get("value");
if (value.get("sessionId") instanceof String) {
return new ExternalSessionKey((String) value.get("sessionId"));
}
}
} catch (JsonSyntaxException e) {
} catch (JsonException | ClassCastException e) {
return null;
}

Expand Down

0 comments on commit bb77f73

Please sign in to comment.