Skip to content

Commit 0319122

Browse files
committed
Move method to the one class where it is used
1 parent abffd85 commit 0319122

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

java/server/src/org/openqa/selenium/grid/sessionqueue/NewSessionQueuer.java

-47
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,26 @@
1717

1818
package org.openqa.selenium.grid.sessionqueue;
1919

20-
import org.openqa.selenium.Capabilities;
21-
import org.openqa.selenium.SessionNotCreatedException;
2220
import org.openqa.selenium.grid.data.RequestId;
2321
import org.openqa.selenium.grid.security.RequiresSecretFilter;
2422
import org.openqa.selenium.grid.security.Secret;
2523
import org.openqa.selenium.internal.Require;
26-
import org.openqa.selenium.remote.NewSessionPayload;
2724
import org.openqa.selenium.remote.http.HttpRequest;
2825
import org.openqa.selenium.remote.http.HttpResponse;
2926
import org.openqa.selenium.remote.http.Routable;
3027
import org.openqa.selenium.remote.http.Route;
31-
import org.openqa.selenium.remote.tracing.AttributeKey;
32-
import org.openqa.selenium.remote.tracing.EventAttribute;
33-
import org.openqa.selenium.remote.tracing.EventAttributeValue;
34-
import org.openqa.selenium.remote.tracing.Span;
3528
import org.openqa.selenium.remote.tracing.Tracer;
3629
import org.openqa.selenium.status.HasReadyState;
3730

38-
import java.io.IOException;
39-
import java.io.Reader;
40-
import java.util.HashMap;
41-
import java.util.Iterator;
4231
import java.util.List;
4332
import java.util.Map;
44-
import java.util.Objects;
4533
import java.util.Optional;
4634
import java.util.UUID;
4735

48-
import static org.openqa.selenium.remote.http.Contents.reader;
4936
import static org.openqa.selenium.remote.http.Route.combine;
5037
import static org.openqa.selenium.remote.http.Route.delete;
5138
import static org.openqa.selenium.remote.http.Route.get;
5239
import static org.openqa.selenium.remote.http.Route.post;
53-
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;
5440

5541
public abstract class NewSessionQueuer implements HasReadyState, Routable {
5642

@@ -64,7 +50,6 @@ protected NewSessionQueuer(Tracer tracer, Secret registrationSecret) {
6450
RequiresSecretFilter requiresSecret = new RequiresSecretFilter(registrationSecret);
6551

6652
routes = combine(
67-
6853
post("/session")
6954
.to(() -> this::addToQueue),
7055
post("/se/grid/newsessionqueuer/session")
@@ -86,38 +71,6 @@ private RequestId requestIdFrom(Map<String, String> params) {
8671
return new RequestId(UUID.fromString(params.get("requestId")));
8772
}
8873

89-
public void validateSessionRequest(HttpRequest request) {
90-
try (Span span = tracer.getCurrentContext().createSpan("newsession_queuer.validate")) {
91-
Map<String, EventAttributeValue> attributeMap = new HashMap<>();
92-
try (
93-
Reader reader = reader(request);
94-
NewSessionPayload payload = NewSessionPayload.create(reader)) {
95-
Objects.requireNonNull(payload, "Requests to process must be set.");
96-
attributeMap.put("request.payload", EventAttribute.setValue(payload.toString()));
97-
98-
Iterator<Capabilities> iterator = payload.stream().iterator();
99-
if (!iterator.hasNext()) {
100-
SessionNotCreatedException exception =
101-
new SessionNotCreatedException("No capabilities found");
102-
EXCEPTION.accept(attributeMap, exception);
103-
attributeMap.put(
104-
AttributeKey.EXCEPTION_MESSAGE.getKey(), EventAttribute.setValue(exception.getMessage()));
105-
span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);
106-
throw exception;
107-
}
108-
} catch (IOException e) {
109-
SessionNotCreatedException exception = new SessionNotCreatedException(e.getMessage(), e);
110-
EXCEPTION.accept(attributeMap, exception);
111-
String errorMessage = "IOException while reading the request payload. " +
112-
exception.getMessage();
113-
attributeMap.put(
114-
AttributeKey.EXCEPTION_MESSAGE.getKey(), EventAttribute.setValue(errorMessage));
115-
span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);
116-
throw exception;
117-
}
118-
}
119-
}
120-
12174
public abstract HttpResponse addToQueue(HttpRequest request);
12275

12376
public abstract boolean retryAddToQueue(HttpRequest request, RequestId reqId);

java/server/src/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueuer.java

+47
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.openqa.selenium.grid.sessionqueue.local;
1919

20+
import org.openqa.selenium.Capabilities;
21+
import org.openqa.selenium.SessionNotCreatedException;
2022
import org.openqa.selenium.events.EventBus;
2123
import org.openqa.selenium.grid.config.Config;
2224
import org.openqa.selenium.grid.data.RequestId;
@@ -29,14 +31,28 @@
2931
import org.openqa.selenium.grid.sessionqueue.NewSessionQueuer;
3032
import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;
3133
import org.openqa.selenium.internal.Require;
34+
import org.openqa.selenium.remote.NewSessionPayload;
3235
import org.openqa.selenium.remote.http.HttpRequest;
3336
import org.openqa.selenium.remote.http.HttpResponse;
37+
import org.openqa.selenium.remote.tracing.AttributeKey;
38+
import org.openqa.selenium.remote.tracing.EventAttribute;
39+
import org.openqa.selenium.remote.tracing.EventAttributeValue;
40+
import org.openqa.selenium.remote.tracing.Span;
3441
import org.openqa.selenium.remote.tracing.Tracer;
3542

43+
import java.io.IOException;
44+
import java.io.Reader;
3645
import java.time.Duration;
46+
import java.util.HashMap;
47+
import java.util.Iterator;
3748
import java.util.List;
49+
import java.util.Map;
50+
import java.util.Objects;
3851
import java.util.Optional;
3952

53+
import static org.openqa.selenium.remote.http.Contents.reader;
54+
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;
55+
4056
public class LocalNewSessionQueuer extends NewSessionQueuer {
4157

4258
public final NewSessionQueue sessionRequests;
@@ -103,5 +119,36 @@ public boolean isReady() {
103119
return bus.isReady();
104120
}
105121

122+
private void validateSessionRequest(HttpRequest request) {
123+
try (Span span = tracer.getCurrentContext().createSpan("newsession_queuer.validate")) {
124+
Map<String, EventAttributeValue> attributeMap = new HashMap<>();
125+
try (
126+
Reader reader = reader(request);
127+
NewSessionPayload payload = NewSessionPayload.create(reader)) {
128+
Objects.requireNonNull(payload, "Requests to process must be set.");
129+
attributeMap.put("request.payload", EventAttribute.setValue(payload.toString()));
130+
131+
Iterator<Capabilities> iterator = payload.stream().iterator();
132+
if (!iterator.hasNext()) {
133+
SessionNotCreatedException exception =
134+
new SessionNotCreatedException("No capabilities found");
135+
EXCEPTION.accept(attributeMap, exception);
136+
attributeMap.put(
137+
AttributeKey.EXCEPTION_MESSAGE.getKey(), EventAttribute.setValue(exception.getMessage()));
138+
span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);
139+
throw exception;
140+
}
141+
} catch (IOException e) {
142+
SessionNotCreatedException exception = new SessionNotCreatedException(e.getMessage(), e);
143+
EXCEPTION.accept(attributeMap, exception);
144+
String errorMessage = "IOException while reading the request payload. " +
145+
exception.getMessage();
146+
attributeMap.put(
147+
AttributeKey.EXCEPTION_MESSAGE.getKey(), EventAttribute.setValue(errorMessage));
148+
span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);
149+
throw exception;
150+
}
151+
}
152+
}
106153
}
107154

0 commit comments

Comments
 (0)