本文整理了Java中com.github.robozonky.integrations.zonkoid.ZonkoidConfirmationProvider
类的一些代码示例,展示了ZonkoidConfirmationProvider
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonkoidConfirmationProvider
类的具体详情如下:
包路径:com.github.robozonky.integrations.zonkoid.ZonkoidConfirmationProvider
类名称:ZonkoidConfirmationProvider
[英]If delegated, this provider will allow investors to fill out CAPTCHA.
[中]如果授权,该提供商将允许投资者填写验证码。
代码示例来源:origin: com.github.robozonky/robozonky-integration-zonkoid
@Override
public Optional<ConfirmationProvider> find(final String providerId) {
if ("zonkoid".equals(providerId) || "zonkios".equals(providerId)) {
return Optional.of(new ZonkoidConfirmationProvider());
} else {
return Optional.empty();
}
}
}
代码示例来源:origin: com.github.robozonky/robozonky-integration-zonkoid
static HttpPost getRequest(final RequestId requestId, final int loanId, final int amount, final String protocol,
final String rootUrl) throws UnsupportedEncodingException {
final String auth = getAuthenticationString(requestId, loanId);
final HttpPost httpPost = new HttpPost(protocol + "://" + rootUrl + PATH);
httpPost.addHeader("Accept", "text/plain");
httpPost.addHeader("Authorization", auth);
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.addHeader("User-Agent", Defaults.ROBOZONKY_USER_AGENT);
httpPost.setEntity(getFormData(requestId, loanId, amount));
return httpPost;
}
代码示例来源:origin: RoboZonky/robozonky
static String getAuthenticationString(final RequestId requestId, final int loanId) {
final String auth = new StringJoiner("|")
.add(String.valueOf(requestId.getPassword()))
.add(CLIENT_APP)
.add(requestId.getUserId())
.add(String.valueOf(loanId))
.toString();
try {
return md5(auth);
} catch (final NoSuchAlgorithmException ex) {
throw new IllegalStateException("Your Java Runtime Environment does not support MD5!", ex);
}
}
代码示例来源:origin: com.github.robozonky/robozonky-integration-zonkoid
private static boolean requestConfirmation(final RequestId requestId, final int loanId, final int amount,
final String rootUrl, final String protocol) {
return Try.withResources(HttpClients::createDefault)
.of(httpClient -> {
LOGGER.debug("Requesting notification of {} CZK for loan #{}.", amount, loanId);
final HttpPost post = getRequest(requestId, loanId, amount, protocol, rootUrl);
return httpClient.execute(post, ZonkoidConfirmationProvider::respond);
})
.getOrElseGet(t -> handleError(requestId, loanId, amount, rootUrl, protocol, t));
}
代码示例来源:origin: RoboZonky/robozonky
private boolean execute(final int code) {
this.mockServerResponse(code);
final RequestId id = new RequestId("user@somewhere.cz", "apitest".toCharArray());
final ZonkoidConfirmationProvider zcp = new ZonkoidConfirmationProvider(serverUrl);
final boolean result = zcp.requestConfirmation(id , 1, 200);
this.verifyClientRequest();
return result;
}
代码示例来源:origin: RoboZonky/robozonky
@Test
void properHttpPost() throws UnsupportedEncodingException {
final int loanId = 1;
final RequestId r = new RequestId("user@somewhere.cz", "apitest".toCharArray());
final HttpPost post = ZonkoidConfirmationProvider.getRequest(r, loanId, 200, "https", "somewhere");
SoftAssertions.assertSoftly(softly -> {
softly.assertThat(post.getFirstHeader("Accept").getValue()).isEqualTo("text/plain");
softly.assertThat(post.getFirstHeader("Authorization").getValue())
.isNotEmpty()
.isEqualTo(ZonkoidConfirmationProvider.getAuthenticationString(r, loanId));
softly.assertThat(post.getFirstHeader("Content-Type").getValue()).isEqualTo(
"application/x-www-form-urlencoded");
softly.assertThat(post.getEntity()).isInstanceOf(UrlEncodedFormEntity.class);
softly.assertThat(post.getFirstHeader("User-Agent").getValue()).isEqualTo(Defaults.ROBOZONKY_USER_AGENT);
});
}
代码示例来源:origin: RoboZonky/robozonky
@Test
void properId() {
final ZonkoidConfirmationProvider p = new ZonkoidConfirmationProvider();
assertThat(p.getId()).contains("Zonkoid").contains("Zonkios");
}
}
代码示例来源:origin: com.github.robozonky/robozonky-integration-zonkoid
@Override
public boolean requestConfirmation(final RequestId requestId, final int loanId, final int amount) {
return requestConfirmation(requestId, loanId, amount, rootUrl, PROTOCOL_MAIN);
}
代码示例来源:origin: RoboZonky/robozonky
@Test
void errorOverHttps() {
final boolean result = ZonkoidConfirmationProvider.handleError(null, 0, 0, "some", "https",
new RuntimeException());
assertThat(result).isFalse();
}
代码示例来源:origin: RoboZonky/robozonky
private static boolean requestConfirmation(final RequestId requestId, final int loanId, final int amount,
final String rootUrl, final String protocol) {
return Try.withResources(HttpClients::createDefault)
.of(httpClient -> {
LOGGER.debug("Requesting notification of {} CZK for loan #{}.", amount, loanId);
final HttpPost post = getRequest(requestId, loanId, amount, protocol, rootUrl);
return httpClient.execute(post, ZonkoidConfirmationProvider::respond);
})
.getOrElseGet(t -> handleError(requestId, loanId, amount, rootUrl, protocol, t));
}
代码示例来源:origin: RoboZonky/robozonky
@Override
public boolean requestConfirmation(final RequestId requestId, final int loanId, final int amount) {
return requestConfirmation(requestId, loanId, amount, rootUrl, PROTOCOL_MAIN);
}
代码示例来源:origin: RoboZonky/robozonky
@Test
void errorOverHttp() {
final boolean result = ZonkoidConfirmationProvider.handleError(null, 0, 0, "some", "http",
new RuntimeException());
assertThat(result).isFalse();
}
代码示例来源:origin: RoboZonky/robozonky
static HttpPost getRequest(final RequestId requestId, final int loanId, final int amount, final String protocol,
final String rootUrl) throws UnsupportedEncodingException {
final String auth = getAuthenticationString(requestId, loanId);
final HttpPost httpPost = new HttpPost(protocol + "://" + rootUrl + PATH);
httpPost.addHeader("Accept", "text/plain");
httpPost.addHeader("Authorization", auth);
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.addHeader("User-Agent", Defaults.ROBOZONKY_USER_AGENT);
httpPost.setEntity(getFormData(requestId, loanId, amount));
return httpPost;
}
代码示例来源:origin: com.github.robozonky/robozonky-integration-zonkoid
static boolean handleError(final RequestId requestId, final int loanId, final int amount, final String domain,
final String protocol, final Throwable t) {
switch (protocol) {
case PROTOCOL_MAIN:
LOGGER.warn("HTTPS communication with Zonkoid failed, trying HTTP.");
return requestConfirmation(requestId, loanId, amount, domain, PROTOCOL_FALLBACK);
case PROTOCOL_FALLBACK:
LOGGER.info("Communication with Zonkoid failed.", t);
return false;
default:
throw new IllegalStateException("Can not happen.");
}
}
代码示例来源:origin: com.github.robozonky/robozonky-integration-zonkoid
static String getAuthenticationString(final RequestId requestId, final int loanId) {
final String auth = new StringJoiner("|")
.add(String.valueOf(requestId.getPassword()))
.add(CLIENT_APP)
.add(requestId.getUserId())
.add(String.valueOf(loanId))
.toString();
try {
return md5(auth);
} catch (final NoSuchAlgorithmException ex) {
throw new IllegalStateException("Your Java Runtime Environment does not support MD5!", ex);
}
}
代码示例来源:origin: RoboZonky/robozonky
@Test
void errorOverUnknown() {
assertThatThrownBy(() -> ZonkoidConfirmationProvider.handleError(null, 0, 0, "some",
UUID.randomUUID().toString(),
new RuntimeException()))
.isInstanceOf(IllegalStateException.class);
}
代码示例来源:origin: RoboZonky/robozonky
@Override
public Optional<ConfirmationProvider> find(final String providerId) {
if ("zonkoid".equals(providerId) || "zonkios".equals(providerId)) {
return Optional.of(new ZonkoidConfirmationProvider());
} else {
return Optional.empty();
}
}
}
代码示例来源:origin: RoboZonky/robozonky
static boolean handleError(final RequestId requestId, final int loanId, final int amount, final String domain,
final String protocol, final Throwable t) {
switch (protocol) {
case PROTOCOL_MAIN:
LOGGER.warn("HTTPS communication with Zonkoid failed, trying HTTP.");
return requestConfirmation(requestId, loanId, amount, domain, PROTOCOL_FALLBACK);
case PROTOCOL_FALLBACK:
LOGGER.info("Communication with Zonkoid failed.", t);
return false;
default:
throw new IllegalStateException("Can not happen.");
}
}
代码示例来源:origin: RoboZonky/robozonky
@Test
void md5() throws NoSuchAlgorithmException {
final String in = "654321|ROBOZONKY|name@surname.cz|12345";
final String out = "cd15efe487e98e83a215091221568eda";
assertThat(ZonkoidConfirmationProvider.md5(in)).isEqualTo(out);
}
内容来源于网络,如有侵权,请联系作者删除!