1

问题:我无法让 RestEasy 自动跟随重定向

我正在使用 RestEasy 客户端框架 2.3.4 来使用 RESTful JSON 服务。我正在使用其余简单的客户端 spring 集成。如果我没有使用 spring RestClientProxyFactoryBean 创建我的服务,我会在客户端请求工厂上设置自动重定向标志

我已经尝试在我的 HTTP 客户端上设置跟随重定向并在调试之后我可以看到这个值被 Rest Easy 覆盖为 false。

查看源代码,我需要访问 spring 代理工厂创建的客户端调用程序,但它没有公开它。

这就像一个非常常见的任务,我肯定错过了什么吗?干杯。

4

1 回答 1

0

You should be able to set a custom client executor on the proxybean factory but that also didn't work e.g

              @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); 
        ...
于 2013-08-10T01:49:04.157 回答