Commit c10ea081 authored by zeroleak's avatar zeroleak
Browse files

use Observable for HttpClient

parent e355b6d4
......@@ -6,6 +6,7 @@ import com.samourai.wallet.api.backend.beans.HttpException;
import com.samourai.whirlpool.cli.config.CliConfig;
import com.samourai.whirlpool.cli.services.CliTorClientService;
import com.samourai.whirlpool.cli.utils.CliUtils;
import io.reactivex.Observable;
import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.util.Map;
......@@ -62,7 +63,7 @@ public class JavaHttpClient implements IHttpClient {
}
@Override
public synchronized <T> T postJsonOverTor(
public synchronized <T> Observable<T> postJsonOverTor(
String urlStr, Class<T> responseType, Map<String, String> headers, Object bodyObj)
throws HttpException {
final boolean isRegOut = true;
......@@ -73,10 +74,12 @@ public class JavaHttpClient implements IHttpClient {
request.content(
new StringContentProvider(
MediaType.APPLICATION_JSON_VALUE, jsonBody, StandardCharsets.UTF_8));
ContentResponse response = request.send();
T result = parseResponse(response, responseType);
return result;
return Observable.fromCallable(
() -> {
ContentResponse response = request.send();
T result = parseResponse(response, responseType);
return result;
});
} catch (Exception e) {
clearHttpClient(isRegOut);
if (log.isDebugEnabled()) {
......
......@@ -172,7 +172,7 @@ public class CliConfigService {
}
// restart needed
this.setCliStatusNotReady("CLI restart required. Wallet initialization success.");
this.setCliStatusNotReady("Wallet initialization success. Restarting CLI...");
return apiKey;
}
......@@ -187,7 +187,7 @@ public class CliConfigService {
save(props);
// restart needed
this.setCliStatusNotReady("CLI restart required. Configuration updated.");
this.setCliStatusNotReady("Configuration updated. Restarting CLI...");
}
public synchronized void setApiConfig(ApiCliConfig apiCliConfig) throws Exception {
......@@ -225,7 +225,7 @@ public class CliConfigService {
}
// restart needed
this.setCliStatusNotReady("CLI restart required. Configuration reset.");
this.setCliStatusNotReady("Configuration reset. Restarting CLI...");
}
public void setCliStatusNotReady(String error) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment