@@ -151,6 +151,7 @@ public abstract class AbstractHttpCommandCodec implements CommandCodec<HttpReque
151
151
private static final String SESSION_ID_PARAM = "sessionId" ;
152
152
153
153
private final BiMap <String , CommandSpec > nameToSpec = HashBiMap .create ();
154
+ private final Map <String , String > aliases = new HashMap <>();
154
155
private final BeanToJsonConverter beanToJsonConverter = new BeanToJsonConverter ();
155
156
private final JsonToBeanConverter jsonToBeanConverter = new JsonToBeanConverter ();
156
157
@@ -277,12 +278,13 @@ public AbstractHttpCommandCodec() {
277
278
278
279
@ Override
279
280
public HttpRequest encode (Command command ) {
280
- CommandSpec spec = nameToSpec .get (command .getName ());
281
+ String name = aliases .getOrDefault (command .getName (), command .getName ());
282
+ CommandSpec spec = nameToSpec .get (name );
281
283
if (spec == null ) {
282
284
throw new UnsupportedCommandException (command .getName ());
283
285
}
284
286
Map <String , ?> parameters = amendParameters (command .getName (), command .getParameters ());
285
- String uri = buildUri (command . getName () , command .getSessionId (), parameters , spec );
287
+ String uri = buildUri (name , command .getSessionId (), parameters , spec );
286
288
287
289
HttpRequest request = new HttpRequest (spec .method , uri );
288
290
@@ -357,6 +359,11 @@ public void defineCommand(String name, HttpMethod method, String pathPattern) {
357
359
defineCommand (name , new CommandSpec (method , pathPattern ));
358
360
}
359
361
362
+ @ Override
363
+ public void alias (String commandName , String isAnAliasFor ) {
364
+ aliases .put (commandName , isAnAliasFor );
365
+ }
366
+
360
367
protected void defineCommand (String name , CommandSpec spec ) {
361
368
checkNotNull (name , "null name" );
362
369
nameToSpec .put (name , spec );
0 commit comments