Getting 500 undocumented error as "Connection prematurely closed DURING response" after executing rest api for file upload

huangapple go评论61阅读模式
英文:

Getting 500 undocumented error as "Connection prematurely closed DURING response" after executing rest api for file upload

问题

以下是翻译好的部分:

在Spring Boot应用程序中创建了一个REST API,该API通过POST请求接收文件,然后进行一些处理并返回一些响应。但是,当执行该POST API时,出现以下错误:

在响应过程中连接被提前关闭

RestController的代码片段如下所示:

@CrossOrigin(origins="*")
@RestController
@RequestMapping("/")
public class Script {

    @Autowired
    ScriptService service;

    private static final Logger logger = (Logger) LoggerFactory.getLogger(LensMigration.class);

    @PostMapping("/api/v1/execute/script")
    public ResponseEntity<Map<String, Integer>> executeScript(@RequestParam(value = "file") MultipartFile file)
            throws IOException {

        logger.info("内部端点!!!");

        if (file.isEmpty()) {
            throw new FileNotFoundException("文件不存在!");
        } else {
            BufferedReader csvReader = new BufferedReader(new InputStreamReader(file.getInputStream()));
            return new ResponseEntity<>(service.migrateOldRecords(csvReader), HttpStatus.OK);
        }
    }
}

我在控制器的开头使用了一些日志记录器来检查是否正在执行,但没有看到任何打印的日志。

可能是由于响应时间引起的问题,
因此我尝试增加响应时间,使用了servlet属性,但没有起作用。

server.connection-timeout=60000

有人能在这里帮助我吗?

英文:

Created a rest api in Springboot application which takes file through POST rest api and do some processing and returns some response.
but when executed that post api it shows an error below as..

Connection prematurely closed during response

Code snippet for the restcontroller is as follows.

@CrossOrigin(origins=&quot;*&quot;)
@RestController
@RequestMapping(&quot;/&quot;)
public class Script{

@Autowired 
ScriptService sevice;

private static final Logger logger = (Logger) LoggerFactory.getLogger(LensMigration.class);

@PostMapping(&quot;/api/v1/execute/script&quot;)
public ResponseEntity&lt;Map&lt;String, Integer&gt;&gt; executeScript(@RequestParam(value = &quot;file&quot;) MultipartFile file)
			throws IOException {

logger.info(&quot;inside endpoint!!!&quot;);

		if (file.isEmpty()) {
			throw new FileNotFoundException(&quot;file doen not exists!!&quot;);
		} else {
			BufferedReader csvReader = new BufferedReader(new InputStreamReader(file.getInputStream()));
			return new ResponseEntity&lt;&gt;(service.migrateOldRecords(csvReader), HttpStatus.OK);

		}
	}



}

I have used some loggers at start of controller to check if it is executing, but didn't get any logs printed.

May be error due to response time
so I have tried to increase the response time using servlet property but it didn't worked

server.connection-timeout=60000

could anyone help me here please.

答案1

得分: 1

事实上,对我来说非常奇怪的是,只需将@RequestMapping注解添加到不同的路径,问题就得以解决。

问题的根本原因是控制器内部的端点不可见。我预期的实际错误是针对这个特定的POST API 返回404未找到。

对于我刚刚在这个POST API下方编写的另一个GET端点,确实出现了404未找到的错误。

因此,由于出现了404错误,我在寻找端点的可见性,并且问题得到了解决。

英文:

Actually it is very strange to me that it gets solved by just adding the @RequestMapping annotation to different path.

The root cause of the issue was the endpoint inside controller was not visible. The actual error I was expecting is that 404 not found for this particular POST api.

I did get 404 not found error for another GET endpoint which I just written below this POST api.

So due to this 404 I was looking for visibility of the endpoint
and its gets resolved.

huangapple
  • 本文由 发表于 2020年8月15日 16:55:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63424281.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定