Source:
public Result createSession(HttpClient client, Command command) throws IOException { Capabilities desired = (Capabilities) command.getParameters().get("desiredCapabilities"); desired = desired == null ? new DesiredCapabilities() : desired; Capabilities required = (Capabilities) command.getParameters().get("requiredCapabilities"); required = required == null ? new DesiredCapabilities() : required; String des = new BeanToJsonConverter().convert(desired); String req = new BeanToJsonConverter().convert(required); StringBuilder parameters = new StringBuilder("{"); amendW3CParameters(parameters, des, req); parameters.append(","); amendOssParamters(parameters, des, req); parameters.append("}"); LOG.fine("Attempting bi-dialect session, assuming Postel's Law holds true on the remote end"); Optional<Result> result = createSession(client, parameters); if (!result.isPresent()) { parameters = new StringBuilder("{"); amendOssParamters(parameters, des, req); parameters.append("}"); LOG.fine("Falling back to original OSS JSON Wire Protocol."); result = createSession(client, parameters); } if (!result.isPresent()) { parameters = new StringBuilder("{"); amendW3CParameters(parameters, des, req); parameters.append("}"); LOG.fine("Falling back to straight W3C remote end connection"); result = createSession(client, parameters); } if (result.isPresent()) { Result toReturn = result.get(); LOG.fine(String.format("Detected dialect: %s", toReturn.dialect)); return toReturn; } throw new SessionNotCreatedException( String.format( "Unable to create new remote session. " + "desired capabilities = %s, required capabilities = %s", desired, required)); }

Target:
public Result createSession(HttpClient client, Command command) throws IOException { Capabilities desired = (Capabilities) command.getParameters().get("desiredCapabilities"); desired = desired == null ? new DesiredCapabilities() : desired; Capabilities required = (Capabilities) command.getParameters().get("requiredCapabilities"); required = required == null ? new DesiredCapabilities() : required; String des = new BeanToJsonConverter().convert(desired); String req = new BeanToJsonConverter().convert(required); StringBuilder parameters = new StringBuilder("{"); amendW3CParameters(parameters, des, req); parameters.append(","); amendOssParamters(parameters, des, req); parameters.append("}"); LOG.fine("Attempting bi-dialect session, assuming Postel's Law holds true on the remote end"); Optional<Result> result = createSession(client, parameters); if (!result.isPresent()) { parameters = new StringBuilder("{"); amendOssParamters(parameters, des, req); parameters.append("}"); LOG.fine("Falling back to original OSS JSON Wire Protocol."); result = createSession(client, parameters); } if (!result.isPresent()) { parameters = new StringBuilder("{"); amendW3CParameters(parameters, des, req); parameters.append("}"); LOG.fine("Falling back to straight W3C remote end connection"); result = createSession(client, parameters); } if (result.isPresent()) { Result toReturn = result.get(); LOG.info(String.format("Detected dialect: %s", toReturn.dialect)); return toReturn; } throw new SessionNotCreatedException( String.format( "Unable to create new remote session. " + "desired capabilities = %s, required capabilities = %s", desired, required)); }