use of org.springframework.core.io.buffer.NettyDataBufferFactory in project spring-framework by spring-projects.
the class ReactorHttpHandlerAdapter method apply.
@Override
public Mono<Void> apply(HttpServerRequest reactorRequest, HttpServerResponse reactorResponse) {
NettyDataBufferFactory bufferFactory = new NettyDataBufferFactory(reactorResponse.alloc());
try {
ReactorServerHttpRequest request = new ReactorServerHttpRequest(reactorRequest, bufferFactory);
ServerHttpResponse response = new ReactorServerHttpResponse(reactorResponse, bufferFactory);
if (request.getMethod() == HttpMethod.HEAD) {
response = new HttpHeadResponseDecorator(response);
}
return this.httpHandler.handle(request, response).doOnError(ex -> logger.trace(request.getLogPrefix() + "Failed to complete: " + ex.getMessage())).doOnSuccess(aVoid -> logger.trace(request.getLogPrefix() + "Handling completed"));
} catch (URISyntaxException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to get request URI: " + ex.getMessage());
}
reactorResponse.status(HttpResponseStatus.BAD_REQUEST);
return Mono.empty();
}
}
use of org.springframework.core.io.buffer.NettyDataBufferFactory in project spring-framework by spring-projects.
the class ReactorNettyRequestUpgradeStrategy method upgrade.
@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, @Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {
ServerHttpResponse response = exchange.getResponse();
HttpServerResponse reactorResponse = ServerHttpResponseDecorator.getNativeResponse(response);
HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
NettyDataBufferFactory bufferFactory = (NettyDataBufferFactory) response.bufferFactory();
URI uri = exchange.getRequest().getURI();
// Trigger WebFlux preCommit actions and upgrade
return response.setComplete().then(Mono.defer(() -> {
WebsocketServerSpec spec = buildSpec(subProtocol);
return reactorResponse.sendWebsocket((in, out) -> {
ReactorNettyWebSocketSession session = new ReactorNettyWebSocketSession(in, out, handshakeInfo, bufferFactory, spec.maxFramePayloadLength());
return handler.handle(session).checkpoint(uri + " [ReactorNettyRequestUpgradeStrategy]");
}, spec);
}));
}
use of org.springframework.core.io.buffer.NettyDataBufferFactory in project spring-framework by spring-projects.
the class DefaultRSocketRequesterBuilder method initConnector.
@SuppressWarnings("deprecation")
private RSocketConnector initConnector(List<RSocketConnectorConfigurer> connectorConfigurers, MimeType metaMimeType, MimeType dataMimeType, RSocketStrategies rsocketStrategies) {
RSocketConnector connector = RSocketConnector.create();
connectorConfigurers.forEach(c -> c.configure(connector));
if (rsocketStrategies.dataBufferFactory() instanceof NettyDataBufferFactory) {
connector.payloadDecoder(PayloadDecoder.ZERO_COPY);
}
connector.metadataMimeType(metaMimeType.toString());
connector.dataMimeType(dataMimeType.toString());
Mono<Payload> setupPayloadMono = getSetupPayload(dataMimeType, metaMimeType, rsocketStrategies);
if (setupPayloadMono != EMPTY_SETUP_PAYLOAD) {
connector.setupPayload(setupPayloadMono);
}
return connector;
}
use of org.springframework.core.io.buffer.NettyDataBufferFactory in project spring-framework by spring-projects.
the class MetadataEncoderTests method defaultDataBufferFactory.
@Test
public void defaultDataBufferFactory() {
DefaultDataBufferFactory bufferFactory = DefaultDataBufferFactory.sharedInstance;
RSocketStrategies strategies = RSocketStrategies.builder().dataBufferFactory(bufferFactory).build();
DataBuffer buffer = new MetadataEncoder(COMPOSITE_METADATA, strategies).route("toA").encode().block();
ByteBuf byteBuf = new NettyDataBufferFactory(ByteBufAllocator.DEFAULT).wrap(buffer.asByteBuffer()).getNativeBuffer();
CompositeMetadata entries = new CompositeMetadata(byteBuf, false);
Iterator<CompositeMetadata.Entry> iterator = entries.iterator();
assertThat(iterator.hasNext()).isTrue();
CompositeMetadata.Entry entry = iterator.next();
assertThat(entry.getMimeType()).isEqualTo(WellKnownMimeType.MESSAGE_RSOCKET_ROUTING.getString());
assertRoute("toA", entry.getContent());
assertThat(iterator.hasNext()).isFalse();
}
use of org.springframework.core.io.buffer.NettyDataBufferFactory in project spring-framework by spring-projects.
the class DefaultRSocketRequesterBuilderTests method frameDecoderMatchesDataBufferFactory.
@Test
public void frameDecoderMatchesDataBufferFactory() throws Exception {
testPayloadDecoder(new NettyDataBufferFactory(ByteBufAllocator.DEFAULT), PayloadDecoder.ZERO_COPY);
testPayloadDecoder(DefaultDataBufferFactory.sharedInstance, PayloadDecoder.DEFAULT);
}
Aggregations