-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to dynamic determine route uri at runtime? #276
Comments
You can write custom GatewayFilte. @Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest request = exchange.getRequest();
String requestPath = request.getPath().pathWithinApplication().value();
......
} |
I found I can write a customer GatewayFilter whose order is before public class CustomerFilter implements GatewayFilter, Ordered {
@Override
public int getOrder() {
return 10001;
}
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
try {
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, new URI("https://www.google.com"));
} catch (URISyntaxException e) {
e.printStackTrace();
}
return chain.filter(exchange);
}
} Can someone tell me whether it is wise to do in this way? Any suggestions are grateful! |
Actually there are a lot of attributes you can use.
|
How can the filter be setup via |
@dave-fl it is currently required. You can put a uri like |
Thank you @spencergibb it seems that the DSL should allow for the AsyncBuilder to be generated after the call to Is |
|
Ok, this works with The missing sauce was having to set a value for order greater than |
.predicate(route.getPredicate()) has proteced access, so can not visited except for put under the same package |
I have a similar requirement and i am able to dynamically create based on input path. I also have to add rewritePath dynamically. How can i use RewritePath within above mentioned code . I don't want to write multiple Rewritepath within my application.yml rather make it dynamic the way i make uri dynamic. TIA |
Please see my query and respond @spencergibb |
Thank you for all your posts. I have a case not mentionned here : what if we want to replace the lb://maplaceholder by a placeholder value. |
@laugues #286 (comment) I hope this will help some! |
Hi, I have a gateway url I want to dynamically call the EUREKA via load balancer. and pass the remaining path using a host predicate. Here is a implementation that works well for me. Below is my App.yml Below is my Code for custom filter `package com.example.apigateway.filters; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR; import java.net.URI; import org.springframework.cloud.gateway.filter.GatewayFilter; @component
} |
Is there a way to set the route uri dynamically based on a value in the request body during runtime? |
Even I am looking for the same. Did you find the solution? |
I faced with the same issue. |
Even I am getting error: Could you help here? |
I want to determine the uri of the specified route at runtime,maybe depends on parameters or others. How to do it , a example code will be grateful.
The text was updated successfully, but these errors were encountered: