我有以下代码,它使用 WebClient 进行 HTTP 调用。
webClient.post()
.uri("/users/track")
.body(BodyInserters.fromObject(getUserTrackPayload(selection, customAttribute, partyId).toString()))
.header(CONTENT_TYPE, APPLICATION_JSON)
.retrieve()
.onStatus(httpStatus -> !CREATED.equals(httpStatus),
response -> response.bodyToMono(String.class)
.flatMap(body -> buildErrorMessage(response.statusCode().value(), body, partyId,
customAttribute)
.flatMap(e -> Mono.error(new MyException(e)))))
.bodyToMono(Object.class)
.map(o -> (JsonObject)new Gson().toJsonTree(o))
.flatMap(body -> body.get("message") != null && body.get("message").getAsString().equalsIgnoreCase("success")
&& body.get("attributes_processed") != null && body.get("attributes_processed").getAsInt() == 1
? Mono.just(body)
: buildErrorMessage(CREATED.value(), body.toString(), partyId, customAttribute)
.flatMap(e -> Mono.error(new MyException(e))));
Run Code Online (Sandbox Code Playgroud)
一段时间后(比如 10 分钟)第一次调用此代码时,我收到以下日志。但是,调用成功并输出了正确的结果。
io.netty.channel.unix.Errors$NativeIoException: syscall:read(..) failed: Connection reset by peer at io.netty.channel.unix.FileDescriptor.readAddress(..)(Unknown Source)
2019-03-19 03:11:45,625 WARN [:::] [reactor-http-epoll-8] reactor.netty.http.client.HttpClientConnect : …Run Code Online (Sandbox Code Playgroud) 我正在实现自定义“ AuthenticationProvider”。如果未通过身份验证,则会在“ authenticate”功能内引发异常,如下所示。
public class DelegatingLdapAuthenticationProvider implements AuthenticationProvider {
private ActiveDirectoryLdapAuthenticationProvider primaryProvider;
private List<ActiveDirectoryLdapAuthenticationProvider> secondaryProviders = new ArrayList<>();
public DelegatingLdapAuthenticationProvider() {
}
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
Authentication result = null;
AuthenticationException exception = null;
try {
result = primaryProvider.authenticate(authentication);
} catch (AuthenticationException e) {
exception = e;
for (ActiveDirectoryLdapAuthenticationProvider secondaryProvider : secondaryProviders) {
try {
result = secondaryProvider.authenticate(authentication);
if (result.isAuthenticated()) {
break;
}
} catch (AuthenticationException e1) {
exception = e;
}
}
}
if (result …Run Code Online (Sandbox Code Playgroud) 我是 RxJava 和 Spring webflux 的新手。有没有办法将 RxJava Single 转换为 Mono?
我想Mono<String>从以下函数返回 a 。
private Single<String> toNotification(PU update, Tx<PP> tx) {
return findChannels(update.partyId(), update.notificationId(), tx)
.toList()
.flatMap(f -> Single.just("test"));
}
Run Code Online (Sandbox Code Playgroud)
findChannels 回报可流动