feign.RetryableException: null executing POST

转 https://blog.csdn.net/quyan2017/article/details/120779994

feign.RetryableException: null executing POST http://xxx
	at feign.FeignException.errorExecuting(FeignException.java:132)
	at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:113)
	at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:78)
	at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
	at com.sun.proxy.$Proxy204.closeWaybill(Unknown Source)
	at com.zrtl.tms.order.service.impl.OrderServiceImpl.cancelOrder(OrderServiceImpl.java:659)
	at com.zrtl.tms.order.service.impl.OrderServiceImpl$$FastClassBySpringCGLIB$$4bb84797.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)

@PatchMapping(value = “/{orderNo}”)
使用fegin调用其他微服务 post请求
解决方案1:
请求改为 post

解决方案2:
CXF能够正常接入数据,但是接入后调用微服务内部的feign报错
原因webservice客户端请求时,携带了这个header信息:transfer-encoding:chunked
而springcloud会把请求过来的http header信息转嫁给下一次发生调用的feign中,源码详见feign.SynchronousMethodHandler#targetRequest
这样就需要我们定值一个RequestInterceptor去简化一下header

@Component
@Slf4j
public class FeignRequestInterceptor implements RequestInterceptor {
final static String TRANSFER_ENCODING = "transfer-encoding";

@Override
public void apply(RequestTemplate requestTemplate) {
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    if(attributes==null)
        return ;
    HttpServletRequest request= attributes.getRequest();
    Enumeration<String> headerNames = request.getHeaderNames();
    
    if (headerNames != null) {
        while (headerNames.hasMoreElements()) {
            String name = headerNames.nextElement();
            String values = request.getHeader(name);
    
            if(isOverLapHeader(requestTemplate,name))
                requestTemplate.header(name, values);
        }
    }
}
//是否允许覆盖requestTemplate中的header
private boolean isOverLapHeader(RequestTemplate requestTemplate,String headerName)
{
    Map<String, Collection<String>> headers= requestTemplate.headers();
    if(headers==null)
    {
        return true;
    }
    if (TRANSFER_ENCODING.equalsIgnoreCase(headerName)) {
        return false;
    }
    return true;

}

这样内部的feign调用时就不会有问题了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值