Skip to content

Commit

Permalink
More migration to our own JSON serialisers
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Aug 21, 2017
1 parent d4eb9a2 commit 6574275
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.net.HttpHeaders;
import com.google.common.net.MediaType;
import com.google.gson.Gson;

import org.openqa.selenium.Platform;
import org.openqa.selenium.logging.LoggingHandler;
import org.openqa.selenium.remote.BeanToJsonConverter;
import org.openqa.selenium.remote.ErrorCodes;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.remote.server.log.LoggingManager;
Expand Down Expand Up @@ -302,7 +302,7 @@ private void writeThrowable(HttpServletResponse resp, Throwable e) {
"lineNumber", element.getLineNumber()))
.collect(ImmutableList.toImmutableList())));

byte[] bytes = new Gson().toJson(value).getBytes(UTF_8);
byte[] bytes = new BeanToJsonConverter().convert(value).getBytes(UTF_8);

try {
resp.setStatus(HTTP_INTERNAL_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import com.google.common.base.StandardSystemProperty;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.google.common.io.CharStreams;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.HasCapabilities;
Expand All @@ -35,6 +33,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.io.TemporaryFilesystem;
import org.openqa.selenium.remote.Dialect;
import org.openqa.selenium.remote.JsonToBeanConverter;
import org.openqa.selenium.remote.SessionId;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
Expand Down Expand Up @@ -129,13 +128,11 @@ public void stop() {

public static class Factory implements SessionFactory {

private static final Type MAP_TYPE = new TypeToken<Map<String, Object>>(){}.getType();
private final Gson gson;
private final JsonToBeanConverter toBean = new JsonToBeanConverter();
private final DriverProvider provider;

public Factory(DriverProvider provider) {
this.provider = provider;
gson = new GsonBuilder().setLenient().create();
}

@Override
Expand All @@ -145,7 +142,7 @@ public ActiveSession apply(NewSessionPayload payload) {
InputStream is = payload.getPayload().get();
Reader ir = new InputStreamReader(is, UTF_8);
Reader reader = new BufferedReader(ir)) {
Map<String, Object> raw = gson.fromJson(reader, MAP_TYPE);
Map<?, ?> raw = toBean.convert(Map.class, CharStreams.toString(reader));
Object desired = raw.get("desiredCapabilities");

if (!(desired instanceof Map)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public void execute(HttpRequest req, HttpResponse resp) throws IOException {
BuildInfo buildInfo = new BuildInfo();
value.put("build", ImmutableMap.of(
// We need to fix the BuildInfo to properly fill out these values.
// "revision", buildInfo.getBuildRevision(),
// "time", buildInfo.getBuildTime(),
"revision", buildInfo.getBuildRevision(),
"time", buildInfo.getBuildTime(),
"version", buildInfo.getReleaseLabel()));

value.put("os", ImmutableMap.of(
Expand Down

0 comments on commit 6574275

Please sign in to comment.