
com.github.mkopylec.charon.forwarding.interceptors.HttpRequestExecution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of charon-spring-webflux Show documentation
Show all versions of charon-spring-webflux Show documentation
Reverse proxy implementation in form of Spring Boot starter
The newest version!
package com.github.mkopylec.charon.forwarding.interceptors;
import io.netty.channel.ChannelException;
import org.springframework.web.reactive.function.client.ExchangeFunction;
import reactor.core.publisher.Mono;
import static com.github.mkopylec.charon.forwarding.RequestForwardingException.requestForwardingError;
public class HttpRequestExecution {
private String mappingName;
private ExchangeFunction exchange;
HttpRequestExecution(String mappingName, ExchangeFunction exchange) {
this.mappingName = mappingName;
this.exchange = exchange;
}
public Mono execute(HttpRequest request) {
return exchange.exchange(request)
.map(response -> response instanceof HttpResponse
? (HttpResponse) response
: new HttpResponse(response, request))
.doOnError(ChannelException.class, e -> {
throw requestForwardingError("Error executing request: " + e.getMessage(), e);
});
}
public String getMappingName() {
return mappingName;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy