私がしたいこと:
このようにある種の呼び出しをリダイレクトするサーバーが必要です。
http://localhost:8080/myapp/api/rest/category/method
の
http://localhost:8090/category/api/method
.
私がやったこと:
Zuul プロキシを次のように構成しました。
info:
component: Simple Zuul Proxy Server
cloud:
conablefig:
failFast: true
discovery:
end: true
zuul:
routes:
api: /myapp/api/rest/**
server:
port: 8080
logging:
level:
ROOT: INFO
org.springframework.web: INFO
info.tcb: DEBUG
私はこのようにルートフィルターを使用しています:
@Slf4j
public class SimpleRouteFilter extends ZuulFilter {
@Value("${unauthorized.url.redirect:http://localhost:8090/testcategory/api/available}")
private String urlRedirect;
@Override
public String filterType() {
return "route";
}
@Override
public int filterOrder() {
return 0;
}
@Override
public boolean shouldFilter() {
return true;
}
private boolean isAuthorizedRequest(HttpServletRequest request) {
return false;
}
private void setRouteHost(RequestContext ctx) throws MalformedURLException {
String urlS = ctx.getRequest().getRequestURL().toString();
URL url = new URL(urlS);
String protocol = url.getProtocol();
String rootHost = url.getHost();
int port = url.getPort();
String portS = (port > 0 ? ":" + port : "");
ctx.setRouteHost(new URL(protocol + "://" + rootHost + portS));
}
@Override
public Object run() {
log.debug("query interception");
RequestContext ctx = RequestContext.getCurrentContext();
try {
if (isAuthorizedRequest(ctx.getRequest())) {
log.debug("NOT redirecting...");
setRouteHost(ctx);
} else {
log.debug("redirecting to " + urlRedirect + " ...");
ctx.setRouteHost(new URL(urlRedirect));
}
} catch (MalformedURLException e) {
log.error("", e);
}
return null;
}
}
リダイレクトをテストするためだけに、このクラスでデフォルトの URL を使用しています。
私の問題は、たとえば呼び出すとhttp://localhost:8080/myapp/api/rest/testcategory/available
404 で終わるが、フィルターがリダイレクトを実行したことをログに記録していることです。
に電話した場合にのみ機能しますhttp://localhost:8080/myapp/api/rest/
。
私は何を間違っていますか?ダブル ** が他のすべての呼び出しで機能しないのはなぜですか?