Uh oh!
There was an error while loading. Please reload this page.
A proposed fix for issue 276 (https://github.com/appium/java-client/i… - #278
Conversation
baechul
commented
Dec 1, 2015
And here is the usage example: publicclassHeaderInjectableHttpClientimplementsHttpClient {
privatefinalHttpClientactualClient;
privatefinalMap<String,String> extraHeaders;
publicHeaderInjectableHttpClient(HttpClientactualClient) {
this.actualClient = actualClient;
extraHeaders = newHashMap<>();
}
publicvoidaddHeader(Stringheader, Stringvalue) {
if(header != null) extraHeaders.put(header, value);
}
publicvoidaddHeaders(Map<String,String> headers) {
if(headers != null) extraHeaders.putAll(headers);
}
@OverridepublicHttpResponseexecute(HttpRequestrequest, booleanfollowRedirects) throwsIOException { // intercept and add the given extra headers.for(Stringheader : extraHeaders.keySet()) {
Stringvalue = extraHeaders.get(header);
if(value != null) {
request.addHeader(header, value);
}
}
returnactualClient.execute(request, followRedirects);
}
}
HttpClient.FactoryhttpClientFactory = newApacheHttpClient.Factory() {
@OverridepublicHttpClientcreateClient(URLurl) {
HeaderInjectableHttpClientclient = newHeaderInjectableHttpClient(super.createClient(url));
client.addHeader("name", "value");
}
};
AndroidDriverdriver = newAndroidDriver(url, httpClientFactory, desiredCapabilities); |
TikhomirovSergey
commented
Dec 2, 2015
@baechul But I have some remarks. My opinion is that proposed changes look bit incomplete. It would be better if you redesigned AppiumCommandExecutor and AppiumDriver the way below : ...
importorg.openqa.selenium.remote.internal.ApacheHttpClient;
...
publicclassAppiumCommandExecutorextendsHttpCommandExecutor{
privatefinalDriverServiceservice;
publicAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, URLaddressOfRemoteServer,
HttpClient.FactoryhttpClientFactory) {
super(additionalCommands, addressOfRemoteServer, httpClientFactory);
service = null;
}
publicAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverServiceservice,
HttpClient.FactoryhttpClientFactory) {
super(additionalCommands, service.getUrl(), httpClientFactory);
this.service = service;
}
publicAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, URLaddressOfRemoteServer) {
this(additionalCommands, addressOfRemoteServer, newApacheHttpClient.Factory());
}
publicAppiumCommandExecutor(Map<String, CommandInfo> additionalCommands, DriverServiceservice) {
this(additionalCommands, service, newApacheHttpClient.Factory());
}
...and ...
i@SuppressWarnings("unchecked")
publicabstractclassAppiumDriver<RequiredElementTypeextendsWebElement> extendsDefaultGenericMobileDriver<RequiredElementType> {
...
privateAppiumDriver(HttpCommandExecutorexecutor, Capabilitiescapabilities){
super(executor, capabilities);
this.executeMethod = newAppiumExecutionMethod(this);
locationContext = newRemoteLocationContext(executeMethod);
super.setErrorHandler(errorHandler);
this.remoteAddress = executor.getAddressOfRemoteServer();
}
publicAppiumDriver(URLremoteAddress, CapabilitiesdesiredCapabilities) {
this(newAppiumCommandExecutor(
getMobileCommands(), remoteAddress), desiredCapabilities);
}
publicAppiumDriver(URLremoteAddress, HttpClient.FactoryhttpClientFactory, CapabilitiesdesiredCapabilities) {
this(newAppiumCommandExecutor(
getMobileCommands(), remoteAddress, httpClientFactory), desiredCapabilities);
}
publicAppiumDriver(AppiumDriverLocalServiceservice, CapabilitiesdesiredCapabilities) {
this(newAppiumCommandExecutor(
getMobileCommands(), service), desiredCapabilities);
}
publicAppiumDriver(AppiumDriverLocalServiceservice, HttpClient.FactoryhttpClientFactory, CapabilitiesdesiredCapabilities) {
this(newAppiumCommandExecutor(
getMobileCommands(), service, httpClientFactory), desiredCapabilities);
}
publicAppiumDriver(AppiumServiceBuilderbuilder, CapabilitiesdesiredCapabilities) {
this(builder.build(), desiredCapabilities);
}
publicAppiumDriver(AppiumServiceBuilderbuilder, HttpClient.FactoryhttpClientFactory, CapabilitiesdesiredCapabilities) {
this(builder.build(), httpClientFactory, desiredCapabilities);
}
publicAppiumDriver(CapabilitiesdesiredCapabilities) {
this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities);
}
publicAppiumDriver(HttpClient.FactoryhttpClientFactory, CapabilitiesdesiredCapabilities) {
this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory, desiredCapabilities);
}
...and add new public constructors to AndroidDriver/IOSDriver. I just think that other users would like to use the new capability (you probably too) combined with the AppiumDriverLocalService. I was managed to make this improvement locally. It works! If you improve your PR the way above then there won't be necessity to cover the new capability with tests and the only way to shoot user's leg will be the implementation of a bad httpClientFactory (and only a user will be responsible) :) @Jonahss@bootstraponline |
TikhomirovSergey
commented
Dec 2, 2015
…builder parameters as suggested by Tikhomirov Sergey
baechul
commented
Dec 2, 2015
Makes sense. Added the same capability for the constructors with localservice and builder parameters as suggested. BTW when is the next release? Can this be merged for the next release? |
TikhomirovSergey
commented
Dec 3, 2015
I think this feature will be included to the new build. Let's wait for some time. |
A proposed fix for issue 276 (https://github.com/appium/java-client/i…
Jonahss
commented
Dec 4, 2015
merged. Ok, let's see where we are on a release. I think there's some outstanding pull requests, and then we should publish. |
baechul
commented
Dec 8, 2015
Great. Thanks. |
…ssues/276)