问题:我无法让RestEasy自动关注重定向
我正在使用RestEasy客户端框架2.3.4来使用RESTful JSON服务。我正在使用 rest easy client spring integration。如果我没有使用Spring RestClientProxyFactoryBean来创建我的服务,我会设置auto redirect flag on the client request factory
我已经尝试在我的HTTP客户端上设置跟随重定向,并且在调试后我可以看到Rest Easy将此值覆盖为false。
Looking at the source code我需要访问spring代理工厂创建的client invoker,但不会公开它。
这就像一个非常常见的任务,我肯定错过了什么?欢呼声。
答案 0 :(得分:0)
您应该能够在proxybean工厂上设置自定义客户端执行程序,但这也不起作用,例如
@Override
public ClientRequest createRequest(String uriTemplate) {
ClientRequest clientRequest = new ClientRequest(uriTemplate, this);
clientRequest.followRedirects(true);
return clientRequest;
}
@Override
public ClientRequest createRequest(UriBuilder uriBuilder) {
ClientRequest clientRequest = super.createRequest(uriBuilder);
clientRequest.followRedirects(true);
return clientRequest;
}
}
proxyFactoryBean.setClientExecutor(new FollowRedirectsClientExecutor());
In end extending and overriding the Http client (in this case HTTP Component) was needed to make this work e.g.
public HttpUriRequest followRedirects(HttpUriRequest request) {
if (logger.isDebugEnabled()) {
logger.debug("Setting allow redirects");
}
HttpParams p = request.getParams();
HttpClientParams.setRedirecting(p, true);
request.setParams(p);
return request;
}
}
...
@Override
public <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler) throw
s IOException,
ClientProtocolException { ClientProtocolException {
request = followRedirects(request);
...