I am using spring webflux and webfilter in my spring boot application and i'm bundling angular and spring boot into a single jar file and i am able to access angular at "/".
My use case is i want to support multi-tenant and when i access my application using "localhost:8080/tenant/tenantname/" it is considered as new tenant with name "tenantname" and i need to open the home page of angular which is at "/" by keeping the uri in the search bar as "localhost:8080/tenant/tenantname/".
So to achieve it i have implemented a webfilter and modifying the path to "/" if the uri has "tenant", but when we send the modified uri to chain.filter(), the uri in the search box is getting to "localhost:8080/" i dont want it happen i want the uri in search box should be same "localhost:8080/tenant/tenantname/".
@Component
public class TenantFilter implements WebFilter {
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
String uri = exchange.getRequest().getURI().getPath();
ServerWebExchange updatedExchange = exchange;
if(uri.contains("tenant")){
updatedExchange = exchange.mutate().request(request->{
request.path("/");
}).build();
}
return chain.filter(updatedExchange);
}
}
In my old POC i have use servlet filter it was working fine there.
Servlet filter example:
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestURI = httpRequest.getRequestURI();
if(requestURI.contains("/tenant")){
request.getRequestDispatcher(URLDecoder.decode(uri, "UTF-8")).forward(request, response);
}
chain.doFilter(request, response);
}
in servlet filter i have use request.getRequestDispatcher().forward(request,response). is there anything same in spring webflux webfilter or do i need to change anything in my webFlux WebFilter.