-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathChromeRequest.java
More file actions
67 lines (55 loc) · 1.71 KB
/
ChromeRequest.java
File metadata and controls
67 lines (55 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.hubspot.chrome.devtools.base;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
public class ChromeRequest {
// It's *much* easier to implement this as a POJO instead of an immutable for two reasons:
//
// 1. Immutable::putParams does not allow setting null values (even with
// @AllowNulls and @Nullable annotations).
//
// 2. Using a Map<String, Optional<Object>> for params gets around the
// above, but then tries to serialize the optionals as nulls, even with
//
// objectMapper.registerModule(new Jdk8Module());
// objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
// objectMapper.setSerializationInclusion(Include.NON_NULL);
//
private static AtomicInteger requestNumber = new AtomicInteger();
private final Integer id;
private String method;
private Map<String, Object> params;
private String sessionId;
public ChromeRequest(String method) {
this.id = requestNumber.getAndIncrement();
this.method = method;
this.params = new HashMap<>();
}
public Integer getId() {
return id;
}
public String getSessionId() {
return sessionId;
}
public String getMethod() {
return method;
}
@JsonProperty
public Map<String, Object> getParams() {
return params;
}
public ChromeRequest setMethod(String methodName) {
this.method = methodName;
return this;
}
public ChromeRequest putParams(String key, Object value) {
if (value != null) {
this.params.put(key, value);
}
return this;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
}