java.io.IOException: UT010029: Stream is closed

Blade 未结 4 2016
Jalena
Jalena 剑圣 2020-03-09 15:19



一、该问题的重现步骤是什么?

1. 使用了ApiLog

2. 方法执行中调用了一个异步请求方法(不需要返回结果)且该方法已正确执行。


二、你期待的结果是什么?实际看到的又是什么?

测试过程中移除掉@Apilog该异常没有出现,使用即出现。


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

SpringBlade 2.6.2


Mac及centos均出现该问题


四、请提供详细的错误堆栈信息,这很重要。

java.io.IOException: UT010029: Stream is closed
	at io.undertow.servlet.spec.ServletInputStreamImpl.read(ServletInputStreamImpl.java:160)
	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
	at java.io.InputStreamReader.read(InputStreamReader.java:184)
	at java.io.BufferedReader.fill(BufferedReader.java:161)
	at java.io.BufferedReader.readLine(BufferedReader.java:324)
	at java.io.BufferedReader.readLine(BufferedReader.java:389)
	at org.springblade.core.tool.support.xss.XssHttpServletRequestWrapper.inputHandlers(XssHttpServletRequestWrapper.java:102)
	at org.springblade.core.tool.support.xss.XssHttpServletRequestWrapper.getInputStream(XssHttpServletRequestWrapper.java:71)
	at org.springblade.core.tool.utils.WebUtil.getRequestBytes(WebUtil.java:235)
	at org.springblade.core.tool.utils.WebUtil.getRequestStr(WebUtil.java:217)
	at org.springblade.core.tool.utils.WebUtil.getRequestParamString(WebUtil.java:199)
	at org.springblade.core.log.utils.LogAbstractUtil.addRequestInfoToLog(LogAbstractUtil.java:48)
	at org.springblade.core.log.publisher.ApiLogPublisher.publishEvent(ApiLogPublisher.java:51)
	at org.springblade.core.log.aspect.ApiLogAspect.around(ApiLogAspect.java:48)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
	at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
	at org.springblade.data.controller.CargoLocationController$$EnhancerBySpringCGLIB$$92f681f4.saveOrUpdate(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:523)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
	at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
	at com.github.xiaoymin.knife4j.spring.filter.ProductionSecurityFilter.doFilter(ProductionSecurityFilter.java:53)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at com.github.xiaoymin.knife4j.spring.filter.SecurityBasicAuthFilter.doFilter(SecurityBasicAuthFilter.java:90)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at org.springblade.core.tool.support.xss.XssFilter.doFilter(XssFilter.java:48)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:124)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:109)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
	at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
	at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
	at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
	at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
	at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
	at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
	at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
	at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
	at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
	at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
	at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
	at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)
	at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
	at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
	at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
	at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
	at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
	at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
	at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
	at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:376)
	at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

初步跟踪异常在 org.springblade.core.tool.utils.WebUtil 235行抛出


五、若有更多详细信息,请在下面提供。

controller方法

@ApiLog("货位增加及更新")
@PostMapping("/batchSavaOrUpdate")
public void saveOrUpdate(@RequestBody List<CargoLocationEntity> entities) {

   List<CargoLocationCallBackDTO> resultList = new ArrayList<>();
   for (CargoLocationEntity entity : entities) {
      CargoLocationCallBackDTO result = new CargoLocationCallBackDTO();
      result.setLgnum(entity.getLgnum());
      result.setLgpla(entity.getLgpla());

      try {
         long integer = service.InsertOrUpdate(entity);
         if (integer > 0) {
            result.setMsgtyp("S");
            result.setMessage("处理成功");
         }
      } catch (Exception e) {
         result.setMsgtyp("E");
         result.setMessage("处理失败" + e.getMessage());
      }

      resultList.add(result);
   }

   Map<String, List<CargoLocationCallBackDTO>> ret = new HashMap<>();
   ret.put("ArrayLines", resultList);

   ObjectMapper objectMapper = new ObjectMapper();
   try {
      String respJson = objectMapper.writeValueAsString(ret);
      String warehouseCode = entities.stream().findFirst().orElseThrow(() -> new Exception("Entity没有找到")).getLgnum();
      String targetService = Utils.getCallBackConfiguration(getFactory(warehouseCode).getFactoryCode());
      sapCallback.CallBackProcess(targetService, "/RESTAdapter/CANGWEI_RESP", respJson);
   } catch (Exception e) {
      log.warn(e.getMessage());
   }
}

异步回调方法

package org.springblade.data.callbak;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.data.prop.SapInterfaceProperties;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Base64;

@Slf4j
@Component
@AllArgsConstructor
public class SapCallback {

    private SapInterfaceProperties sapInterfaceProperties;

    /**
     * @param targetService 目标服务
     * @param interfacePath 接口路径
     * @param json 发送的JSon参数
     */
    @Async
    public void CallBackProcess(String targetService, String interfacePath, String json) {

        // 根据配置获取SAP回调地址
        SapInterfaceProperties.InterfaceConfiguration configuration = sapInterfaceProperties.getConfiguration().get(targetService);
        String url = configuration.getAddress() + interfacePath;

        // 设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        // 处理密码验证
        String sapUser = configuration.getUser();
        String sapPassword = configuration.getPassword();
        String authorization = String.format("%s:%s", sapUser, sapPassword);
        String auth = "Basic " + Base64.getEncoder().encodeToString(authorization.getBytes());
        headers.add("Authorization", auth);

        HttpEntity<String> entity = new HttpEntity<>(json, headers);

        try {
            RestTemplate restTemplate = new RestTemplate();
            restTemplate.postForObject(url, entity, String.class);
            log.debug("SAP回调完成。targetService ==> " + targetService);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

    }
}



4条回答
  • 2020-08-26 10:27

    这个问题修复了吗

    3 讨论(0)
  • 试着写一个最简单的可以重现的demo,不需要加上业务代码和其他的代码,尽可能精简。然后传到帖子让我下载。这样我方便进行调试

    作者追问:2020-03-09 15:36

    @ApiLog("test")
    @PostMapping("/test")
    public void test(@RequestBody List entities) {
       log.debug(entities.toString());
    }


    数据

    POST http://127.0.0.1:8200/api/cargolocation/test
    Content-Type: application/json
    
    [
      {
        "lgnum": "X01",
        "lgtyp": "902",
        "lgpla": "4500004396",
        "lgber": "001",
        "zkzue": false,
        "zkzua": false
      },
      {
        "lgnum": "X01",
        "lgtyp": "902",
        "lgpla": "8000002539",
        "lgber": "001",
        "zkzue": false,
        "zkzua": false
      }
    ]


    回答: 2020-03-11 15:23

    已记录,后续会修复

    回答: 2020-04-23 14:03

    等了很久你仍然没有给出可完整运行的demo给我。我需要做的事情没多,抽不出时间一个一个自己搭建然后复制代码,引入依赖。我只需要你给一个最简单可运行的demo给我,这样我就可以直接导入然后排查。

    看到你群里发了很多遍,连更新新闻都发了,但是我每次回过来看这帖子的时候你仍然没有上传demo代码。你想别人方便你,那你有没有方便别人呢?

    0 讨论(1)
  • 2020-07-30 17:42

    不好意思,可能我发给你的代码你没注意看,我现在重新发一个给你。


    错误的重现很简单,在任意一个 Controller 中写一个参数为 @RequestBody 的方法并使用 @ApiLog 注解即触发该异常。


    package org.springblade.test.controller
    
    @Slf4j
    @RestController
    public class TestController {
    
        @ApiLog("test")
        @PostMapping("/test")
        public void UT010029(@RequestBody List<String> data) {
            log.debug(data.toString());
        }
    }


    测试方式

    POST http://127.0.0.1/blade-test/test
    Content-Type: application/json
    
    ["1", "2"]


    测试截图

    截屏2020-07-30 17.51.48.png

    截屏2020-07-30 17.50.02.png

    0 讨论(0)
  • 2021-07-12 16:48

    同问,这个问题解决了吗?

    0 讨论(0)
提交回复