本文整理了Java中reactor.core.publisher.Mono.cast()
方法的一些代码示例,展示了Mono.cast()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.cast()
方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:cast
[英]Cast the current Mono produced type into a target produced type.
[中]将当前单声道生成的类型转换为目标生成的类型。
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Object> resolveArgument(
MethodParameter parameter, BindingContext context, ServerWebExchange exchange) {
Object errors = getErrors(parameter, context);
if (Mono.class.isAssignableFrom(errors.getClass())) {
return ((Mono<?>) errors).cast(Object.class);
}
else if (Errors.class.isAssignableFrom(errors.getClass())) {
return Mono.just(errors);
}
else {
throw new IllegalStateException("Unexpected Errors/BindingResult type: " + errors.getClass().getName());
}
}
代码示例来源:origin: spring-projects/spring-security
/**
* Attempts to load the client registration id from the current {@link Authentication}
* @return
*/
private Mono<String> clientRegistrationId(Mono<Authentication> authentication) {
return authentication
.filter(t -> this.defaultOAuth2AuthorizedClient && t instanceof OAuth2AuthenticationToken)
.cast(OAuth2AuthenticationToken.class)
.map(OAuth2AuthenticationToken::getAuthorizedClientRegistrationId);
}
代码示例来源:origin: spring-projects/spring-security
/**
* Attempts to load the client registration id from the current {@link Authentication}
* @return
*/
private Mono<String> clientRegistrationId(Mono<Authentication> authentication) {
return authentication
.filter(t -> this.defaultOAuth2AuthorizedClient && t instanceof OAuth2AuthenticationToken)
.cast(OAuth2AuthenticationToken.class)
.map(OAuth2AuthenticationToken::getAuthorizedClientRegistrationId);
}
代码示例来源:origin: spring-projects/spring-security
@Override
public Mono<Authentication> authenticate(Authentication authentication) {
return Mono.justOrEmpty(authentication)
.filter(a -> a instanceof BearerTokenAuthenticationToken)
.cast(BearerTokenAuthenticationToken.class)
.map(BearerTokenAuthenticationToken::getToken)
.flatMap(this.jwtDecoder::decode)
.flatMap(this.jwtAuthenticationConverter::convert)
.cast(Authentication.class)
.onErrorMap(JwtException.class, this::onError);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<Object> readMono(
ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
// We're ahead of String + "*/*"
// Let's see if we can aggregate the output (lest we time out)...
if (elementType.resolve() == String.class) {
Flux<DataBuffer> body = message.getBody();
return stringDecoder.decodeToMono(body, elementType, null, null).cast(Object.class);
}
return Mono.error(new UnsupportedOperationException(
"ServerSentEventHttpMessageReader only supports reading stream of events as a Flux"));
}
代码示例来源:origin: spring-projects/spring-security
@Override
public Mono<OAuth2AuthorizationRequest> resolve(ServerWebExchange exchange) {
return this.authorizationRequestMatcher.matches(exchange)
.filter(matchResult -> matchResult.isMatch())
.map(ServerWebExchangeMatcher.MatchResult::getVariables)
.map(variables -> variables.get(DEFAULT_REGISTRATION_ID_URI_VARIABLE_NAME))
.cast(String.class)
.flatMap(clientRegistrationId -> resolve(exchange, clientRegistrationId));
}
代码示例来源:origin: spring-projects/spring-security
@Override
public Mono<Void> handle(ServerWebExchange exchange, AccessDeniedException denied) {
Map<String, String> parameters = new LinkedHashMap<>();
if (this.realmName != null) {
parameters.put("realm", this.realmName);
}
return exchange.getPrincipal()
.filter(AbstractOAuth2TokenAuthenticationToken.class::isInstance)
.cast(AbstractOAuth2TokenAuthenticationToken.class)
.map(token -> errorMessageParameters(token, parameters))
.switchIfEmpty(Mono.just(parameters))
.flatMap(params -> respond(exchange, params));
}
代码示例来源:origin: org.springframework/spring-web
@Override
public Mono<Object> readMono(
ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
// We're ahead of String + "*/*"
// Let's see if we can aggregate the output (lest we time out)...
if (elementType.resolve() == String.class) {
Flux<DataBuffer> body = message.getBody();
return stringDecoder.decodeToMono(body, elementType, null, null).cast(Object.class);
}
return Mono.error(new UnsupportedOperationException(
"ServerSentEventHttpMessageReader only supports reading stream of events as a Flux"));
}
代码示例来源:origin: reactor/reactor-core
@Test(expected = NullPointerException.class)
public void sourceNull() {
Mono.just(1)
.cast(null);
}
代码示例来源:origin: spring-projects/spring-framework
return parts.next().cast(Object.class);
MethodParameter elementType = parameter.nested();
if (Part.class.isAssignableFrom(elementType.getNestedParameterType())) {
return parts.collectList().cast(Object.class);
.collectList().cast(Object.class);
.next().cast(Object.class);
代码示例来源:origin: spring-projects/spring-security
private BearerTokenAuthenticationToken convertToToken(MockServerHttpRequest request) {
MockServerWebExchange exchange = MockServerWebExchange.from(request);
return this.converter.convert(exchange).cast(BearerTokenAuthenticationToken.class).block();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-15331
public void decodeFullContentAsString() {
String body = "data:foo\ndata:bar\n\ndata:baz\n\n";
MockServerHttpRequest request = MockServerHttpRequest.post("/")
.body(Mono.just(stringBuffer(body)));
String actual = messageReader
.readMono(ResolvableType.forClass(String.class), request, Collections.emptyMap())
.cast(String.class)
.block(Duration.ZERO);
assertEquals(body, actual);
}
代码示例来源:origin: spring-projects/spring-data-redis
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Mono<RedisReactiveCommands<ByteBuffer, ByteBuffer>> getCommands(RedisNode node) {
if (StringUtils.hasText(node.getId())) {
return getConnection().cast(StatefulRedisClusterConnection.class)
.map(it -> it.getConnection(node.getId()).reactive());
}
return getConnection().flatMap(it -> Mono.fromCompletionStage(it.getConnectionAsync(node.getHost(), node.getPort()))
.map(StatefulRedisConnection::reactive));
}
}
代码示例来源:origin: reactor/reactor-core
@Test
public void error() {
StepVerifier.create(Mono.just(1)
.cast(String.class))
.verifyError(ClassCastException.class);
}
代码示例来源:origin: spring-projects/spring-security
@Override
public Mono<Authentication> authenticate(Authentication authentication) {
return Mono.defer(() -> {
OAuth2AuthorizationCodeAuthenticationToken token = (OAuth2AuthorizationCodeAuthenticationToken) authentication;
// Section 3.1.2.1 Authentication Request - http://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
// scope REQUIRED. OpenID Connect requests MUST contain the "openid" scope value.
if (token.getAuthorizationExchange()
.getAuthorizationRequest().getScopes().contains("openid")) {
// This is an OpenID Connect Authentication Request so return null
// and let OidcAuthorizationCodeReactiveAuthenticationManager handle it instead once one is created
// FIXME: Once we create OidcAuthorizationCodeReactiveAuthenticationManager uncomment below
// return Mono.empty();
}
return this.authorizationCodeManager.authenticate(token)
.onErrorMap(OAuth2AuthorizationException.class, e -> new OAuth2AuthenticationException(e.getError(), e.getError().toString()))
.cast(OAuth2AuthorizationCodeAuthenticationToken.class)
.flatMap(this::onSuccess);
});
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void transformExtLinksNotAllowed() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/external.css"));
List<ResourceTransformer> transformers = Collections.singletonList(new CssLinkResourceTransformer());
ResourceResolverChain mockChain = Mockito.mock(DefaultResourceResolverChain.class);
ResourceTransformerChain chain = new DefaultResourceTransformerChain(mockChain, transformers);
Resource resource = getResource("external.css");
String expected = "@import url(\"http://example.org/fonts/css\");\n" +
"body { background: url(\"file:///home/spring/image.png\") }\n" +
"figure { background: url(\"//example.org/style.css\")}";
StepVerifier.create(chain.transform(exchange, resource)
.cast(TransformedResource.class))
.consumeNextWith(transformedResource -> {
String result = new String(transformedResource.getByteArray(), StandardCharsets.UTF_8);
result = StringUtils.deleteAny(result, "\r");
assertEquals(expected, result);
})
.expectComplete()
.verify();
List<Resource> locations = Collections.singletonList(resource);
Mockito.verify(mockChain, Mockito.never()).resolveUrlPath("http://example.org/fonts/css", locations);
Mockito.verify(mockChain, Mockito.never()).resolveUrlPath("file:///home/spring/image.png", locations);
Mockito.verify(mockChain, Mockito.never()).resolveUrlPath("//example.org/style.css", locations);
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void findByUsernameWhenClearCredentialsThenFindByUsernameStillHasCredentials() {
User foundUser = users.findByUsername(USER_DETAILS.getUsername()).cast(User.class).block();
assertThat(foundUser.getPassword()).isNotEmpty();
foundUser.eraseCredentials();
assertThat(foundUser.getPassword()).isNull();
foundUser = users.findByUsername(USER_DETAILS.getUsername()).cast(User.class).block();
assertThat(foundUser.getPassword()).isNotEmpty();
}
代码示例来源:origin: spring-projects/spring-security
private static Mono<AccessTokenResponse> oauth2AccessTokenResponse(TokenResponse tokenResponse) {
if (tokenResponse.indicatesSuccess()) {
return Mono.just(tokenResponse)
.cast(AccessTokenResponse.class);
}
TokenErrorResponse tokenErrorResponse = (TokenErrorResponse) tokenResponse;
ErrorObject errorObject = tokenErrorResponse.getErrorObject();
OAuth2Error oauth2Error;
if (errorObject == null) {
oauth2Error = new OAuth2Error(OAuth2ErrorCodes.SERVER_ERROR);
} else {
oauth2Error = new OAuth2Error(
errorObject.getCode() != null ? errorObject.getCode() : OAuth2ErrorCodes.SERVER_ERROR,
errorObject.getDescription(),
errorObject.getURI() != null ? errorObject.getURI().toString() : null);
}
return Mono.error(new OAuth2AuthorizationException(oauth2Error));
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normal() {
StepVerifier.create(Mono.just(1)
.cast(Number.class))
.expectNext(1)
.verifyComplete();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void transform() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/static/main.css"));
Resource css = getResource("main.css");
String expected = "\n" +
"@import url(\"/static/bar-11e16cf79faee7ac698c805cf28248d2.css?#iefix\");\n" +
"@import url('/static/bar-11e16cf79faee7ac698c805cf28248d2.css#bla-normal');\n" +
"@import url(/static/bar-11e16cf79faee7ac698c805cf28248d2.css);\n\n" +
"@import \"/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css\";\n" +
"@import '/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css';\n\n" +
"body { background: url(\"/static/images/image-f448cd1d5dba82b774f3202c878230b3.png?#iefix\") }\n";
StepVerifier.create(this.transformerChain.transform(exchange, css)
.cast(TransformedResource.class))
.consumeNextWith(transformedResource -> {
String result = new String(transformedResource.getByteArray(), StandardCharsets.UTF_8);
result = StringUtils.deleteAny(result, "\r");
assertEquals(expected, result);
})
.expectComplete()
.verify();
}
内容来源于网络,如有侵权,请联系作者删除!