Skip to content

Commit c4837a0

Browse files
committed
expose getter getAdditionalCommands
1 parent 77384fb commit c4837a0

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

java/src/org/openqa/selenium/remote/HttpCommandExecutor.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import java.io.IOException;
2727
import java.net.URL;
28+
import java.util.Collections;
29+
import java.util.HashMap;
2830
import java.util.Map;
2931
import org.openqa.selenium.NoSuchSessionException;
3032
import org.openqa.selenium.SessionNotCreatedException;
@@ -46,7 +48,7 @@ public class HttpCommandExecutor implements CommandExecutor, NeedsLocalLogs {
4648
private final URL remoteServer;
4749
public final HttpClient client;
4850
private final HttpClient.Factory httpClientFactory;
49-
protected final Map<String, CommandInfo> additionalCommands;
51+
private final Map<String, CommandInfo> additionalCommands;
5052
protected CommandCodec<HttpRequest> commandCodec;
5153
protected ResponseCodec<HttpResponse> responseCodec;
5254

@@ -109,11 +111,34 @@ public HttpCommandExecutor(
109111
ClientConfig config,
110112
HttpClient.Factory httpClientFactory) {
111113
remoteServer = Require.nonNull("HTTP client configuration", config).baseUrl();
112-
this.additionalCommands = Require.nonNull("Additional commands", additionalCommands);
114+
this.additionalCommands =
115+
new HashMap<>(Require.nonNull("Additional commands", additionalCommands));
113116
this.httpClientFactory = Require.nonNull("HTTP client factory", httpClientFactory);
114117
this.client = this.httpClientFactory.createClient(config);
115118
}
116119

120+
/**
121+
* Returns an immutable view of the additional commands.
122+
*
123+
* @return an unmodifiable map of additional commands.
124+
*/
125+
public Map<String, CommandInfo> getAdditionalCommands() {
126+
return Collections.unmodifiableMap(additionalCommands);
127+
}
128+
129+
/**
130+
* Adds or updates additional commands. This method is protected to allow subclasses to define
131+
* their commands.
132+
*
133+
* @param commandName the name of the command to add or update.
134+
* @param info the CommandInfo for the command.
135+
*/
136+
protected void addAdditionalCommand(String commandName, CommandInfo info) {
137+
Require.nonNull("Command name", commandName);
138+
Require.nonNull("Command info", info);
139+
this.additionalCommands.put(commandName, info);
140+
}
141+
117142
/**
118143
* It may be useful to extend the commands understood by this {@code HttpCommandExecutor} at run
119144
* time, and this can be achieved via this method. Note, this is protected, and expected usage is

0 commit comments

Comments
 (0)