2

I am getting the following error getting a response of a post method via WebClient(org.springframework.web.reactive.function.client)

org.springframework.core.codec.DecodingException: JSON decoding 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
at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 2]
at org.springframework.http.codec.json.AbstractJackson2Decoder.processException(AbstractJackson2Decoder.java:215)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Ȁ

I have tried changing the headers of the request as under with failure :-

headers.put("Accept-Encoding", "gzip");

or

headers.put("Accept-Encoding", "identity");

Is it that webclient is unable to process the gzipped response for any reason!!

Thanks in advance!!

6
  • Have you read this? stackoverflow.com/questions/42621547/… Commented Aug 27, 2020 at 3:45
  • yes. Basically i am getting the issue from webclient. The issue is basically how to resolve the same JSonParseException in webclient. Commented Aug 27, 2020 at 4:01
  • Can you parse the payload manually? set a debugger or inspect what the client is sending and try to parse it. also try sending the same post request using a different client "postman, curl..etc" Commented Aug 27, 2020 at 4:03
  • Yes when the endpoint is POSTed in postman, it gives JSON response. Commented Aug 27, 2020 at 4:06
  • Can test if the token is valid using something like this: gist.github.com/thomasdarimont/46358bc8167fce059d83a1ebdb92b0e7 Commented Aug 27, 2020 at 4:09

4 Answers 4

5

Remove header ("Accept-Encoding", "gzip") You will not get JSON decoding error: Illegal character ((CTRL-CHAR, code 31))

If the response length is increased beyond default threshold then response would be gziped and it will give JSON decoding error.

Sign up to request clarification or add additional context in comments.

Comments

0

I missed implementing Serializable to the response object.

1 Comment

I see where the issue is.
0

I have started getting this exception with Spring boot's feign dependency spring-cloud-openfeign-core when I upgrade the version of spring-cloud-openfeign-core to 2.2.5.RELEASE.

For those who upgrade to version 2.2.5.RELEASE or later version will face this issue if they already have the property feign.request.compression=true.

The technical reason behind this is, in FeignContentGzipEncodingAutoConfiguration class the conditional property annotation signature changed from @ConditionalOnProperty("feign.compression.request.enabled", matchIfMissing = false) to @ConditionalOnProperty(value = "feign.compression.request.enabled"), so by default FeignContentGzipEncodingInterceptor is triggered. GitHub reference

Workaround

If your calling a spring-boot service which doesn't have a mechanism to handle the compressed request then disable the feign request compression using the below property

feign.request.compression=false.

NOTE: Unfortunately, we still don't have the out-of-box solution in spring-boot to handle the compressed request refer

Comments

0

If you are using springcloud feign, you can set header as follows in FeignRequestInterceptor

requestTemplate.header("Accept-Encoding", "identity");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.