Spring boot embedded tomcat - 413 запрос слишком большой объект - PullRequest
0 голосов
/ 09 июля 2020

Я работаю в облаке IBM publi c. У меня есть apu connect, чтобы получить доступ к микросервису dry cloud. Я просмотрел много сообщений и пробовал разные вещи, и мне кажется, что это не работает. Вот мои настройки конфигурации файла свойств для весенней загрузки:

# The name of the application
spring.application.name=xxxxx

# web base path
management.endpoints.web.base-path=/

# Embedded tomcat config
server.tomcat.max-swallow-size=256MB
server.tomcat.max-http-post-size=256MB

# File size values
spring.servlet.multipart.max-file-size=256MB
spring.servlet.multipart.max-request-size=256MB
spring.servlet.multipart.enabled=true
    
# Server specific values
input.server=xxx
input.rtm.bucket=xxx
storage.server.base=xxx

# Cloudant database info
input.events.db.name=xxxx
input.ait.info.db.name=xxxx
letter.number.db.name=xxxx
letter.gen.data.db.name=xxxx


# Query index design documents
query.pad.ait.info.index.name=xxxx
query.pad.ait.info.deisgn.doc=_xxxx
query.rfa.ltr.index.name=xxxx
query.rfa.ltr.design.doc=xxxx

# The logging levels of the application
logging.level.application=DEBUG
#logging.level.root=DEBUG
#logging.level.org.springframework.web=INFO

# Testing
unit.testing=false
integration.testing=true

# Jackson json config
spring.jackson.mapper.accept-case-insensitive-properties=true

Вот функция REST api для публикации файла

    @PostMapping(value = "/send/rtm/document/{errata}")
    public @ResponseBody ResponseEntity<Object> receiveRtmDocument(@PathVariable("errata") String errata, @RequestParam("file") MultipartFile file)

Я использую весеннюю загрузку 2.1.6 и имею ничего не обновлял в файле POM. Я пытаюсь отправить файл размером 5,8 МБ в api, и это дает мне эту ошибку:

com.ibm.tools.cloud.exceptions.DataNotJsonException: <html>
<head><title>413 Request Entity Too Large</title></head>
<body bgcolor="white">
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>openresty</center>
</body>
</html>

    at com.ibm.msc.gasm.sapt.input.AitInputManagement.sendRtmDocument(AitInputManagement.java:182)
    at com.ibm.msc.gasm.sapt.test.InputServiceTester.performTest(InputServiceTester.java:142)
    at com.ibm.msc.gasm.sapt.test.InputServiceTester.main(InputServiceTester.java:96)

Вот код отправки, который я использую в java для multipart. Единственные другие заголовки, которые я использую, но не перечисленные здесь, - это мои заголовки авторизации.

        // Create the URL connection
        HttpURLConnection conn = (HttpURLConnection) (new URL(requestUri)).openConnection();
        if (content != null || multipartFile) conn.setDoOutput(true);
        conn.setRequestMethod(method.toString());
        
        // Set the headers
        Enumeration<String> keys = headers.keys();
        while (keys.hasMoreElements())
        {
            // Pull out the key
            String key = keys.nextElement();
            
            // Set the header
            conn.setRequestProperty(key, headers.get(key));
        }
        
        // Set the accept header
        if (acceptHeader != null) conn.setRequestProperty("Accept", acceptHeader);
        
        // Set the content header
        if (contentTypeHeader != null) conn.setRequestProperty("Content-Type", contentTypeHeader);

        if (content != null)
        {
            // Set the content
            DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
            if (content.isFileContent()) dos.write(content.getFileContentAsByteArray());
            else if (content.isByteArrayContent()) dos.write(content.getContentAsByteArray());
            else if (content.isStringContent()) dos.write(content.getStringContentAsByteArray());

            // close the stream
            dos.flush();
            dos.close();
        }
        
        // Set the multipart file
        if (multipartFile)
        {
            // Set the properties
            conn.setUseCaches(false);
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setRequestProperty("Cache-Control", "no-cache");
            conn.setRequestProperty("Content-Type", "multipart/form-data;boundry=" + MP_BOUNDRY);
            
            // Set the content
            DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
            dos.writeBytes(MP_HYPHENS + MP_BOUNDRY + StringUtils.crlf);
            dos.writeBytes("Content-Disposition: form-data: name=\"" + this.mpName + "\";filename=\"" + this.mpFileName + "\"" + StringUtils.crlf);
            dos.writeBytes(StringUtils.crlf);
            dos.write(IOUtils.toByteArray(new FileInputStream(this.mpFileNamePath)));
            dos.writeBytes(StringUtils.crlf);
            dos.writeBytes(MP_HYPHENS + MP_BOUNDRY + MP_HYPHENS + StringUtils.crlf);

            // close the stream
            dos.flush();
            dos.close();
        }
        
        // Get the response
        HttpResponseMessage response = null;
        try 
        {
            // Extract the stream
            InputStream is = (conn.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST) ? conn.getErrorStream() : conn.getInputStream();
            
            // Pull out the information
            byte[] data = IOUtils.toByteArray(is);
            
            // Set the response
            response = new HttpResponseMessage(requestUri, HttpStatusCode.getType(conn.getResponseCode()), acceptHeader, data, conn.getResponseMessage());
        }
        catch (Throwable e)
        {
            throw new IOException(String.format("Error reading results from %s", requestUri), e);
        }
        
        // Close the request
        conn.disconnect();

        // Send request
        return response;

Я пробовал несколько вещей, но не уверен, что мне не хватает. У кого-нибудь есть идеи, как это исправить?

1 Ответ

0 голосов
/ 09 июля 2020

Попробуйте эти два в своем application.properties

server.tomcat.max-swallow-size=XMB //maximum size of the request body/payload
server.tomcat.max-http-post-size=XMB //maximum size of entire POST request

X - желаемое целое число, представляющее мегабайт.

...