31
31
import org .openqa .selenium .remote .http .HttpClient ;
32
32
import org .openqa .selenium .remote .http .HttpRequest ;
33
33
import org .openqa .selenium .remote .http .HttpResponse ;
34
- import org .openqa .selenium .remote .tracing .Span ;
35
- import org .openqa .selenium .remote .tracing .TracedHttpClient ;
36
- import org .openqa .selenium .remote .tracing .Tracer ;
37
- import org .openqa .selenium .remote .tracing .opentelemetry .OpenTelemetryTracer ;
38
34
39
35
import java .io .IOException ;
40
36
import java .net .MalformedURLException ;
@@ -57,7 +53,6 @@ public class HttpCommandExecutor implements CommandExecutor, NeedsLocalLogs {
57
53
private final HttpClient client ;
58
54
private final HttpClient .Factory httpClientFactory ;
59
55
private final Map <String , CommandInfo > additionalCommands ;
60
- private final Tracer tracer ;
61
56
private CommandCodec <HttpRequest > commandCodec ;
62
57
private ResponseCodec <HttpResponse > responseCodec ;
63
58
@@ -115,8 +110,7 @@ public HttpCommandExecutor(
115
110
}
116
111
remoteServer = config .baseUrl ();
117
112
this .additionalCommands = additionalCommands ;
118
- tracer = OpenTelemetryTracer .getInstance ();
119
- this .httpClientFactory = new TracedHttpClient .Factory (tracer , httpClientFactory );
113
+ this .httpClientFactory = httpClientFactory ;
120
114
this .client = this .httpClientFactory .createClient (config );
121
115
}
122
116
@@ -149,75 +143,72 @@ public URL getAddressOfRemoteServer() {
149
143
150
144
@ Override
151
145
public Response execute (Command command ) throws IOException {
152
- try (Span commandSpan = tracer .getCurrentContext ().createSpan ("command" )) {
153
- commandSpan .setAttribute ("command" , command .toString ());
154
- if (command .getSessionId () == null ) {
155
- if (QUIT .equals (command .getName ())) {
156
- return new Response ();
157
- }
158
- if (!GET_ALL_SESSIONS .equals (command .getName ())
159
- && !NEW_SESSION .equals (command .getName ())) {
160
- throw new NoSuchSessionException (
161
- "Session ID is null. Using WebDriver after calling quit()?" );
162
- }
146
+ if (command .getSessionId () == null ) {
147
+ if (QUIT .equals (command .getName ())) {
148
+ return new Response ();
163
149
}
164
-
165
- if (NEW_SESSION .equals (command .getName ())) {
166
- if (commandCodec != null ) {
167
- throw new SessionNotCreatedException ("Session already exists" );
168
- }
169
- ProtocolHandshake handshake = new ProtocolHandshake ();
170
- log (LogType .PROFILER , new HttpProfilerLogEntry (command .getName (), true ));
171
- ProtocolHandshake .Result result = handshake .createSession (client , command );
172
- Dialect dialect = result .getDialect ();
173
- commandCodec = dialect .getCommandCodec ();
174
- for (Map .Entry <String , CommandInfo > entry : additionalCommands .entrySet ()) {
175
- defineCommand (entry .getKey (), entry .getValue ());
176
- }
177
- responseCodec = dialect .getResponseCodec ();
178
- log (LogType .PROFILER , new HttpProfilerLogEntry (command .getName (), false ));
179
- return result .createResponse ();
150
+ if (!GET_ALL_SESSIONS .equals (command .getName ())
151
+ && !NEW_SESSION .equals (command .getName ())) {
152
+ throw new NoSuchSessionException (
153
+ "Session ID is null. Using WebDriver after calling quit()?" );
180
154
}
155
+ }
181
156
182
- if (commandCodec == null || responseCodec == null ) {
183
- throw new WebDriverException (
184
- "No command or response codec has been defined. Unable to proceed" );
157
+ if (NEW_SESSION .equals (command .getName ())) {
158
+ if (commandCodec != null ) {
159
+ throw new SessionNotCreatedException ("Session already exists" );
160
+ }
161
+ ProtocolHandshake handshake = new ProtocolHandshake ();
162
+ log (LogType .PROFILER , new HttpProfilerLogEntry (command .getName (), true ));
163
+ ProtocolHandshake .Result result = handshake .createSession (client , command );
164
+ Dialect dialect = result .getDialect ();
165
+ commandCodec = dialect .getCommandCodec ();
166
+ for (Map .Entry <String , CommandInfo > entry : additionalCommands .entrySet ()) {
167
+ defineCommand (entry .getKey (), entry .getValue ());
185
168
}
169
+ responseCodec = dialect .getResponseCodec ();
170
+ log (LogType .PROFILER , new HttpProfilerLogEntry (command .getName (), false ));
171
+ return result .createResponse ();
172
+ }
186
173
187
- HttpRequest httpRequest = commandCodec .encode (command );
174
+ if (commandCodec == null || responseCodec == null ) {
175
+ throw new WebDriverException (
176
+ "No command or response codec has been defined. Unable to proceed" );
177
+ }
188
178
189
- // Ensure that we set the required headers
190
- if (httpRequest .getHeader ("Content-Type" ) == null ) {
191
- httpRequest .addHeader ("Content-Type" , JSON_UTF_8 );
192
- }
179
+ HttpRequest httpRequest = commandCodec .encode (command );
193
180
194
- try {
195
- log (LogType .PROFILER , new HttpProfilerLogEntry (command .getName (), true ));
196
- HttpResponse httpResponse = client .execute (httpRequest );
197
- log (LogType .PROFILER , new HttpProfilerLogEntry (command .getName (), false ));
198
-
199
- Response response = responseCodec .decode (httpResponse );
200
- if (response .getSessionId () == null ) {
201
- if (httpResponse .getTargetHost () != null ) {
202
- response .setSessionId (getSessionId (httpResponse .getTargetHost ()).orElse (null ));
203
- } else {
204
- // Spam in the session id from the request
205
- response .setSessionId (command .getSessionId ().toString ());
206
- }
207
- }
208
- if (QUIT .equals (command .getName ())) {
209
- client .close ();
210
- httpClientFactory .cleanupIdleClients ();
211
- }
212
- return response ;
213
- } catch (UnsupportedCommandException e ) {
214
- if (e .getMessage () == null || "" .equals (e .getMessage ())) {
215
- throw new UnsupportedOperationException (
216
- "No information from server. Command name was: " + command .getName (),
217
- e .getCause ());
181
+ // Ensure that we set the required headers
182
+ if (httpRequest .getHeader ("Content-Type" ) == null ) {
183
+ httpRequest .addHeader ("Content-Type" , JSON_UTF_8 );
184
+ }
185
+
186
+ try {
187
+ log (LogType .PROFILER , new HttpProfilerLogEntry (command .getName (), true ));
188
+ HttpResponse httpResponse = client .execute (httpRequest );
189
+ log (LogType .PROFILER , new HttpProfilerLogEntry (command .getName (), false ));
190
+
191
+ Response response = responseCodec .decode (httpResponse );
192
+ if (response .getSessionId () == null ) {
193
+ if (httpResponse .getTargetHost () != null ) {
194
+ response .setSessionId (getSessionId (httpResponse .getTargetHost ()).orElse (null ));
195
+ } else {
196
+ // Spam in the session id from the request
197
+ response .setSessionId (command .getSessionId ().toString ());
218
198
}
219
- throw e ;
220
199
}
200
+ if (QUIT .equals (command .getName ())) {
201
+ client .close ();
202
+ httpClientFactory .cleanupIdleClients ();
203
+ }
204
+ return response ;
205
+ } catch (UnsupportedCommandException e ) {
206
+ if (e .getMessage () == null || "" .equals (e .getMessage ())) {
207
+ throw new UnsupportedOperationException (
208
+ "No information from server. Command name was: " + command .getName (),
209
+ e .getCause ());
210
+ }
211
+ throw e ;
221
212
}
222
213
}
223
214
}
0 commit comments