Search in sources :

Example 26 with DataBufferFactory

use of org.springframework.core.io.buffer.DataBufferFactory in project spring-framework by spring-projects.

the class AbstractEncoderMethodReturnValueHandler method handleReturnValue.

@Override
public Mono<Void> handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, Message<?> message) {
    if (returnValue == null) {
        return handleNoContent(returnType, message);
    }
    DataBufferFactory bufferFactory = (DataBufferFactory) message.getHeaders().getOrDefault(HandlerMethodReturnValueHandler.DATA_BUFFER_FACTORY_HEADER, DefaultDataBufferFactory.sharedInstance);
    MimeType mimeType = (MimeType) message.getHeaders().get(MessageHeaders.CONTENT_TYPE);
    Flux<DataBuffer> encodedContent = encodeContent(returnValue, returnType, bufferFactory, mimeType, Collections.emptyMap());
    return new ChannelSendOperator<>(encodedContent, publisher -> handleEncodedContent(Flux.from(publisher), returnType, message));
}
Also used : DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory) MimeType(org.springframework.util.MimeType) DataBuffer(org.springframework.core.io.buffer.DataBuffer)

Example 27 with DataBufferFactory

use of org.springframework.core.io.buffer.DataBufferFactory in project spring-security by spring-projects.

the class LoginPageGeneratingWebFilter method createBuffer.

private Mono<DataBuffer> createBuffer(ServerWebExchange exchange) {
    Mono<CsrfToken> token = exchange.getAttributeOrDefault(CsrfToken.class.getName(), Mono.empty());
    return token.map(LoginPageGeneratingWebFilter::csrfToken).defaultIfEmpty("").map((csrfTokenHtmlInput) -> {
        byte[] bytes = createPage(exchange, csrfTokenHtmlInput);
        DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();
        return bufferFactory.wrap(bytes);
    });
}
Also used : CsrfToken(org.springframework.security.web.server.csrf.CsrfToken) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory)

Example 28 with DataBufferFactory

use of org.springframework.core.io.buffer.DataBufferFactory in project spring-security by spring-projects.

the class LogoutPageGeneratingWebFilter method createBuffer.

private Mono<DataBuffer> createBuffer(ServerWebExchange exchange) {
    Mono<CsrfToken> token = exchange.getAttributeOrDefault(CsrfToken.class.getName(), Mono.empty());
    return token.map(LogoutPageGeneratingWebFilter::csrfToken).defaultIfEmpty("").map((csrfTokenHtmlInput) -> {
        byte[] bytes = createPage(csrfTokenHtmlInput);
        DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();
        return bufferFactory.wrap(bytes);
    });
}
Also used : CsrfToken(org.springframework.security.web.server.csrf.CsrfToken) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory)

Aggregations

DataBufferFactory (org.springframework.core.io.buffer.DataBufferFactory)28 DataBuffer (org.springframework.core.io.buffer.DataBuffer)14 Mono (reactor.core.publisher.Mono)12 Flux (reactor.core.publisher.Flux)11 List (java.util.List)9 Publisher (org.reactivestreams.Publisher)8 Nullable (org.springframework.lang.Nullable)8 IOException (java.io.IOException)7 MediaType (org.springframework.http.MediaType)7 Assert (org.springframework.util.Assert)7 HandshakeInfo (org.springframework.web.reactive.socket.HandshakeInfo)7 Collections (java.util.Collections)6 Resource (org.springframework.core.io.Resource)6 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Supplier (java.util.function.Supplier)5 ResolvableType (org.springframework.core.ResolvableType)5 DataBufferUtils (org.springframework.core.io.buffer.DataBufferUtils)5 Test (org.junit.Test)4