Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring引导REST应用程序中处理gzip请求_Java_Spring_Rest_Spring Boot - Fatal编程技术网

Java 在Spring引导REST应用程序中处理gzip请求

Java 在Spring引导REST应用程序中处理gzip请求,java,spring,rest,spring-boot,Java,Spring,Rest,Spring Boot,我有一个SpringBootREST应用程序(1.5.6.RELEASE)。我想gzip压缩传入和传出。根据此文档,我已设置 server.compression.enabled=true server.compression.mime-types=... 但这似乎只适用于从我的服务中压缩响应(文档实际上是这么说的“#如果启用了响应压缩”) 我的问题是传入的gzip请求没有被解压缩,导致JSON解析错误 有人知道我如何在Spring Boot应用程序中打开请求解压缩吗 编辑示例: POM代码段

我有一个SpringBootREST应用程序(1.5.6.RELEASE)。我想gzip压缩传入和传出。根据此文档,我已设置

server.compression.enabled=true
server.compression.mime-types=...
但这似乎只适用于从我的服务中压缩响应(文档实际上是这么说的“#如果启用了响应压缩”)

我的问题是传入的gzip请求没有被解压缩,导致JSON解析错误

有人知道我如何在Spring Boot应用程序中打开请求解压缩吗

编辑示例:

POM代码段:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
gzip调用失败,并显示以下消息:

{"timestamp":1505843443456,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"JSON parse error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens\n at [Source: java.io.PushbackInputStream@50ebec25; line: 1, column: 2]","path":"/"}

server.compression.*
配置键仅与HTTP响应压缩有关。我不知道有什么通用的解决方案,也不知道服务器是否在本机上支持这种解决方案


您可以通过使用一个Servlet过滤器来支持这一点,但Spring Boot不提供这一功能。

如何发出压缩请求?请参阅,@diginoise我不控制客户端显示一些代码!你的控制器看起来像什么?客户端发送的是什么(HTTP头和正文),出现了什么错误,etc@BrianClozel,doneor,或者你把servlet容器放在Apache后面,让Apache来处理:好吧,我看到了一些关于nginx是否做到这一点的问题——从2011年开始。但是我找不到比这更近的东西了,它说nginx现在允许请求压缩(通过nginx文档搜索
内容编码
)是的,你现在最好的选择是使用HTTP/2。真的有点沮丧,因为我已经在使用nginx进行响应压缩和SSL了。但我还没看完。
$ echo '{ "key":"hello" }' > body
$ curl -X POST -H "Content-Type: application/json" --data-binary @body http://localhost:8080 # prints 'hello'
$ echo '{ "key":"hello" }' | gzip > body.gz
$ curl -X POST -H "Content-Type: application/json" -H "Content-Encoding: gzip" --data-binary @body.gz http://localhost:8080 # fails
{"timestamp":1505843443456,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"JSON parse error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens\n at [Source: java.io.PushbackInputStream@50ebec25; line: 1, column: 2]","path":"/"}