I am having few spring boot microservices, which are deployed to JBoss over a cloud environment. These boot services are Eureka clients which register itself in to the Eureka server. Following is an example:
eureka:
client:
healthcheck:
enabled: true
serviceUrl:
defaultZone: ${DISCOVERY_URL:http://localhost:8761}/eureka/
instance:
ip-address: 127.0.0.1
appname: user-regn-service-app
home-page-url-path: /user-regn-service-app
It registers the app with Eureka with the name user-regn-service-app Eureka Homepage
The wildfly server is running at 8080 and the user-regn-service-app is deployed at the context path /user-regn-service-app. So the rest api is as below
localhost:8080/user-regn-service-app/regnUser
When I am using zuul as api gateway, the config is as below
zuul:
prefix: /api
routes:
test:
path: /test/**
service-id: USER-REGN-SERVICE-APP
strip-prefix: true
ribbon:
eureka:
enabled: true
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
registerWithEureka: false
But whenever I am making call to zuul api gateway it is unable to recognize the context path and redirects to localhost:8080 instead of localhost:8080/user-regn-service-app.
http://localhost:8765/api/
-> 404 not found
http://localhost:8765/api/user-regn-service-app/
-> Wildfly default homepage
http://localhost:8765/api/user-regn-service-app/user-regn-service-app/regnUser
-> Redirects to user registration.
Expected behavior: http://localhost:8765/api/test/regnUser
should redirect to the user registration.
I have pretty much tried all combinations that I got from blogs between Zuul and Eureka to get the following done but no luck. Kindly advise if I am missing something.
I have tried using custom zuul custom filter as below but it doesn't forward to the Required Context path. Code is as below
@Component
public class ZuulApiFilter extends ZuulFilter{
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
System.out.println("original"+ ctx.get("requestURI"));
HttpServletRequest request = ctx.getRequest();
String requestURI = request.getRequestURI();
String contextAwareURI=requestURI.concat("user-regn-service-app/");
ctx.set("requestURI", contextAwareURI);
return null;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public int filterOrder() {
return 1;
}
@Override
public String filterType() {
return "pre";
}
}
The requestURI doesn't changes after setting the new URI as well ctx.set("requestURI", contextAwareURI); request.getRequestURI(); shows the old Request URI only.