x.jsp로 리디렉션하는 다운 스트림 서비스가 있습니다.이 위치는 예를 들어 게이트웨이 경로에 없습니다.
gateway route --- localhost:8080/app - 192.168.1.1:80 (DownStream app)
사용자가 로그인하지 않은 경우 DownStream 앱 Location
에서 응답 헤더에있는 192.168.1.1:80/Login.jsp로 리디렉션됩니다 .
이 URL은 게이트웨이를 사용하지 않습니다.
예를 들어 Location
게이트웨이에 의해 zuul 필터 변경 헤더 에서 라우팅되는 각 URL에 대해 동적 zuul 경로를 매핑 하여이 리디렉션 URL을 변경하는 zuul 필터를 작성하고 싶습니다 . 어떻게 할 수 있습니까?
다운 스트림 앱은 x-forwarded- * 헤더를 존중해야하며 이와 같은 리디렉션을 생성하지 않아야합니다. 그러나 다음 필터는 어쨌든 리디렉션 위치를 변경합니다.
@Override
public String filterType() {
return "post";
}
@Override
public int filterOrder() {
return 0;
}
@Override
public boolean shouldFilter() {
int status = RequestContext.getCurrentContext().getResponseStatusCode();
return status >= 300 && status < 400;
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
Map<String, String> requestHeaders = ctx.getZuulRequestHeaders();
Optional<Pair<String, String>> locationHeader = ctx.getZuulResponseHeaders()
.stream()
.filter(stringStringPair -> LOCATION.equals(stringStringPair.first()))
.findFirst();
if (locationHeader.isPresent()) {
String oldLocation = locationHeader.get().second();
String newLocation = ...
locationHeader.get().setSecond(newLocation);
}
return null;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다