【问题标题】:RestEasy client spring integration: can not auto follow redirectsRestEasy客户端弹簧集成:不能自动跟随重定向
【发布时间】:2013-06-14 10:25:39
【问题描述】:

问题:我无法让 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,但它不会公开它。

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

【问题讨论】:

    标签: spring redirect client resteasy


    【解决方案1】:

    您应该能够在 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); 
            ...
    

    【讨论】:

      猜你喜欢
      • 2018-01-04
      • 2021-07-06
      • 2020-07-02
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-15
      • 1970-01-01
      相关资源
      最近更新 更多