Skip to content

Commit f28f1df

Browse files
shs96cdiemol
andauthored
[java] Remove Json Wire Protocol support (#11823)
* [java] Remove support for the original Json Wire Protocol * cp: remote jwp from new session new session payload * cp: make the driver command encode capabilities as a set in all cases * cp: remove `desiredCapabilities` from encoded new session command * cp: continuing to remove desired capabilities * cp: start removing usages of `Dialect.OSS` * cp: making w3c the default protocol * cp: start ripping out protocol conversion * cp: removing protocol conversion * cp: finish removing `Dialect.OSS` from the tree * [java] Refining proxyType to fix browser tests * [java] Fixing proxy tests * [grid] Removing platform before sending payload to driver --------- Co-authored-by: Diego Molina <[email protected]> Co-authored-by: Diego Molina <[email protected]>
1 parent ca50360 commit f28f1df

40 files changed

+150
-2240
lines changed

java/src/org/openqa/selenium/Proxy.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,27 @@ public enum ProxyType {
3939
// Keep these in sync with the Firefox preferences numbers:
4040
// http://kb.mozillazine.org/Network.proxy.type
4141

42-
DIRECT, // Direct connection, no proxy (default on Windows)
43-
MANUAL, // Manual proxy settings (e.g. for httpProxy)
44-
PAC, // Proxy auto-configuration from URL
42+
DIRECT("direct"), // Direct connection, no proxy (default on Windows)
43+
MANUAL("manual"), // Manual proxy settings (e.g. for httpProxy)
44+
PAC("pac"), // Proxy auto-configuration from URL
4545

46-
RESERVED_1, // Never used (but reserved in Firefox)
46+
RESERVED_1("reserved_1"), // Never used (but reserved in Firefox)
4747

48-
AUTODETECT, // Proxy auto-detection (presumably with WPAD)
49-
SYSTEM, // Use system settings (default on Linux)
48+
AUTODETECT("autodetect"), // Proxy auto-detection (presumably with WPAD)
49+
SYSTEM("system"), // Use system settings (default on Linux)
5050

51-
UNSPECIFIED
51+
UNSPECIFIED("unspecified");
52+
53+
private final String type;
54+
55+
ProxyType(String type) {
56+
this.type = type;
57+
}
58+
59+
@Override
60+
public String toString() {
61+
return String.valueOf(type);
62+
}
5263
}
5364

5465
private static final String PROXY_TYPE = "proxyType";

java/src/org/openqa/selenium/grid/node/CapabilityResponseEncoder.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.openqa.selenium.internal.Require;
2727
import org.openqa.selenium.json.Json;
2828
import org.openqa.selenium.remote.Dialect;
29-
import org.openqa.selenium.remote.ErrorCodes;
3029
import org.openqa.selenium.remote.SessionId;
3130

3231
import java.util.Map;
@@ -36,8 +35,6 @@
3635
public class CapabilityResponseEncoder {
3736

3837
private static final Json JSON = new Json();
39-
private static final ResponseEncoder<Session, Map<String, Object>, byte[]> JWP_ENCODER =
40-
new Encoder(Dialect.OSS);
4138
private static final ResponseEncoder<Session, Map<String, Object>, byte[]> W3C_ENCODER =
4239
new Encoder(Dialect.W3C);
4340

@@ -47,9 +44,6 @@ private CapabilityResponseEncoder() {
4744

4845
public static ResponseEncoder<Session, Map<String, Object>, byte[]> getEncoder(Dialect dialect) {
4946
switch (dialect) {
50-
case OSS:
51-
return JWP_ENCODER;
52-
5347
case W3C:
5448
return W3C_ENCODER;
5549

@@ -108,10 +102,6 @@ private static byte[] encodeAsResponse(
108102
Map<String, Object> toEncode;
109103

110104
switch (dialect) {
111-
case OSS:
112-
toEncode = encodeJsonWireProtocol(id, capabilities, metadata);
113-
break;
114-
115105
case W3C:
116106
toEncode = encodeW3C(id, capabilities, metadata);
117107
break;
@@ -134,19 +124,5 @@ private static Map<String, Object> encodeW3C(
134124
"capabilities", capabilities))
135125
.build();
136126
}
137-
138-
private static Map<String, Object> encodeJsonWireProtocol(
139-
SessionId id,
140-
Capabilities capabilities,
141-
Map<String, Object> metadata) {
142-
return ImmutableMap.<String, Object>builder()
143-
.putAll(metadata)
144-
.put("status", ErrorCodes.SUCCESS)
145-
.put("sessionId", id)
146-
.put("value", capabilities)
147-
.build();
148-
149-
}
150-
151127
}
152128
}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
// Licensed to the Software Freedom Conservancy (SFC) under one
2-
// or more contributor license agreements. See the NOTICE file
3-
// distributed with this work for additional information
4-
// regarding copyright ownership. The SFC licenses this file
5-
// to you under the Apache License, Version 2.0 (the
6-
// "License"); you may not use this file except in compliance
7-
// with the License. You may obtain a copy of the License at
8-
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
10-
//
11-
// Unless required by applicable law or agreed to in writing,
12-
// software distributed under the License is distributed on an
13-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-
// KIND, either express or implied. See the License for the
15-
// specific language governing permissions and limitations
16-
// under the License.
17-
181
package org.openqa.selenium.grid.node;
192

203
import org.openqa.selenium.Capabilities;
21-
import org.openqa.selenium.grid.web.ProtocolConverter;
224
import org.openqa.selenium.grid.web.ReverseProxyHandler;
235
import org.openqa.selenium.internal.Require;
246
import org.openqa.selenium.remote.Dialect;
@@ -29,19 +11,20 @@
2911
import org.openqa.selenium.remote.http.HttpResponse;
3012
import org.openqa.selenium.remote.tracing.Tracer;
3113

14+
import java.io.UncheckedIOException;
3215
import java.net.URL;
3316
import java.time.Instant;
3417
import java.util.stream.Collectors;
3518
import java.util.stream.StreamSupport;
3619

3720
import static org.openqa.selenium.remote.http.HttpMethod.DELETE;
3821

39-
public abstract class ProtocolConvertingSession extends BaseActiveSession {
22+
public class DefaultActiveSession extends BaseActiveSession {
4023

4124
private final HttpHandler handler;
4225
private final String killUrl;
4326

44-
protected ProtocolConvertingSession(
27+
protected DefaultActiveSession(
4528
Tracer tracer,
4629
HttpClient client,
4730
SessionId id,
@@ -55,17 +38,12 @@ protected ProtocolConvertingSession(
5538

5639
Require.nonNull("HTTP client", client);
5740

58-
if (downstream.equals(upstream)) {
59-
this.handler = new ReverseProxyHandler(tracer, client);
60-
} else {
61-
this.handler = new ProtocolConverter(tracer, client, downstream, upstream);
62-
}
63-
41+
this.handler = new ReverseProxyHandler(tracer, client);
6442
this.killUrl = "/session/" + id;
6543
}
6644

6745
@Override
68-
public HttpResponse execute(HttpRequest req) {
46+
public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
6947
String host = "host";
7048
StreamSupport.stream(req.getHeaderNames().spliterator(), true)
7149
.filter(host::equalsIgnoreCase)
@@ -78,4 +56,9 @@ public HttpResponse execute(HttpRequest req) {
7856
}
7957
return res;
8058
}
59+
60+
@Override
61+
public void stop() {
62+
// no-op
63+
}
8164
}

java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020
import org.openqa.selenium.Capabilities;
2121
import org.openqa.selenium.ImmutableCapabilities;
22+
import org.openqa.selenium.MutableCapabilities;
2223
import org.openqa.selenium.PersistentCapabilities;
2324
import org.openqa.selenium.Platform;
2425
import org.openqa.selenium.SessionNotCreatedException;
2526
import org.openqa.selenium.WebDriverException;
2627
import org.openqa.selenium.devtools.CdpEndpointFinder;
2728
import org.openqa.selenium.grid.data.CreateSessionRequest;
2829
import org.openqa.selenium.grid.node.ActiveSession;
29-
import org.openqa.selenium.grid.node.ProtocolConvertingSession;
30+
import org.openqa.selenium.grid.node.DefaultActiveSession;
3031
import org.openqa.selenium.grid.node.SessionFactory;
3132
import org.openqa.selenium.internal.Either;
3233
import org.openqa.selenium.internal.Require;
@@ -119,7 +120,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
119120

120121
Optional<Platform> platformName = Optional.ofNullable(capabilities.getPlatformName());
121122
if (platformName.isPresent()) {
122-
capabilities = generalizePlatform(capabilities);
123+
capabilities = removePlatform(capabilities);
123124
}
124125

125126
CAPABILITIES.accept(span, capabilities);
@@ -171,7 +172,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
171172

172173
span.addEvent("Driver service created session", attributeMap);
173174
return Either.right(
174-
new ProtocolConvertingSession(
175+
new DefaultActiveSession(
175176
tracer,
176177
client,
177178
new SessionId(response.getSessionId()),
@@ -293,10 +294,12 @@ private Capabilities readVncEndpoint(Capabilities requestedCaps, Capabilities re
293294
return returnedCaps;
294295
}
295296

296-
// We set the platform to ANY before sending the caps to the driver because some drivers will
297+
// We remove the platform before sending the caps to the driver because some drivers will
297298
// reject session requests when they cannot parse the platform.
298-
private Capabilities generalizePlatform(Capabilities caps) {
299-
return new PersistentCapabilities(caps).setCapability("platformName", Platform.ANY);
299+
private Capabilities removePlatform(Capabilities caps) {
300+
MutableCapabilities noPlatformName = new MutableCapabilities(new HashMap<>(caps.asMap()));
301+
noPlatformName.setCapability("platformName", (String) null);
302+
return new PersistentCapabilities(noPlatformName);
300303
}
301304

302305
private Capabilities setInitialPlatform(Capabilities caps, Platform platform) {

java/src/org/openqa/selenium/grid/node/docker/DockerSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import org.openqa.selenium.Capabilities;
2121
import org.openqa.selenium.docker.Container;
22-
import org.openqa.selenium.grid.node.ProtocolConvertingSession;
22+
import org.openqa.selenium.grid.node.DefaultActiveSession;
2323
import org.openqa.selenium.internal.Require;
2424
import org.openqa.selenium.remote.Dialect;
2525
import org.openqa.selenium.remote.SessionId;
@@ -35,7 +35,7 @@
3535
import java.util.logging.Level;
3636
import java.util.logging.Logger;
3737

38-
public class DockerSession extends ProtocolConvertingSession {
38+
public class DockerSession extends DefaultActiveSession {
3939

4040
private static final Logger LOG = Logger.getLogger(DockerSession.class.getName());
4141
private final Container container;

java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.openqa.selenium.WebDriverException;
2424
import org.openqa.selenium.grid.data.CreateSessionRequest;
2525
import org.openqa.selenium.grid.node.ActiveSession;
26-
import org.openqa.selenium.grid.node.ProtocolConvertingSession;
26+
import org.openqa.selenium.grid.node.DefaultActiveSession;
2727
import org.openqa.selenium.grid.node.SessionFactory;
2828
import org.openqa.selenium.internal.Debug;
2929
import org.openqa.selenium.internal.Either;
@@ -172,7 +172,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
172172

173173
span.addEvent("Relay service created session", attributeMap);
174174
LOG.fine(String.format("Created session: %s - %s", response.getSessionId(), capabilities));
175-
return Either.right(new ProtocolConvertingSession(
175+
return Either.right(new DefaultActiveSession(
176176
tracer,
177177
client,
178178
new SessionId(response.getSessionId()),

java/src/org/openqa/selenium/grid/session/remote/RemoteSession.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.openqa.selenium.WebDriver;
2424
import org.openqa.selenium.grid.session.ActiveSession;
2525
import org.openqa.selenium.grid.session.SessionFactory;
26-
import org.openqa.selenium.grid.web.ProtocolConverter;
2726
import org.openqa.selenium.grid.web.ReverseProxyHandler;
2827
import org.openqa.selenium.internal.Require;
2928
import org.openqa.selenium.io.TemporaryFilesystem;
@@ -52,8 +51,6 @@
5251
import java.util.logging.Level;
5352
import java.util.logging.Logger;
5453

55-
import static org.openqa.selenium.remote.Dialect.OSS;
56-
5754
/**
5855
* Abstract class designed to do things like protocol conversion.
5956
*/
@@ -150,8 +147,11 @@ protected Optional<ActiveSession> performHandshake(
150147
codec = new ReverseProxyHandler(tracer, client);
151148
downstream = upstream;
152149
} else {
153-
downstream = downstreamDialects.isEmpty() ? OSS : downstreamDialects.iterator().next();
154-
codec = new ProtocolConverter(tracer, client, downstream, upstream);
150+
LOG.warning(String.format(
151+
"Unable to match protocol versions. Found %s upstream but can handle %s",
152+
upstream,
153+
downstreamDialects));
154+
return Optional.empty();
155155
}
156156

157157
Response response = result.createResponse();

0 commit comments

Comments
 (0)