Skip to content

Commit ea7cf41

Browse files
committed
Allow subclasses of HttpCommandExecutor to extend it at runtime.
This is useful for projects such as Selendroid, which currently have to jump through some ugly hoops in order to do this.
1 parent 0f36aa9 commit ea7cf41

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.openqa.selenium.remote.DriverCommand.NEW_SESSION;
2222
import static org.openqa.selenium.remote.DriverCommand.QUIT;
2323

24+
import com.google.common.base.Preconditions;
2425
import com.google.common.base.Throwables;
2526
import com.google.common.collect.ImmutableMap;
2627

@@ -116,11 +117,23 @@ public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addr
116117
host, remoteServer.getPort(), remoteServer.getProtocol());
117118

118119
for (Map.Entry<String, CommandInfo> entry : additionalCommands.entrySet()) {
119-
CommandInfo info = entry.getValue();
120-
commandCodec.defineCommand(entry.getKey(), info.getMethod(), info.getUrl());
120+
defineCommand(entry.getKey(), entry.getValue());
121121
}
122122
}
123123

124+
/**
125+
* It may be useful to extend the commands understood by this {@code HttpCommandExecutor} at run
126+
* time, and this can be achieved via this method. Note, this is protected, and expected usage is
127+
* for subclasses only to call this.
128+
*
129+
* @param commandName The name of the command to use.
130+
*/
131+
protected void defineCommand(String commandName, CommandInfo info) {
132+
Preconditions.checkNotNull(commandName);
133+
Preconditions.checkNotNull(info);
134+
commandCodec.defineCommand(commandName, info.getMethod(), info.getUrl());
135+
}
136+
124137
public void setLocalLogs(LocalLogs logs) {
125138
this.logs = logs;
126139
}

0 commit comments

Comments
 (0)