0

Checking the headers HttpRequestExecutingMessageHandler i notice a common header, accept-encoding, gzip which throws an Exception on response during the convertion phase, i.e. the message could not be converted throwing an error on response. Which is my guess related to the undelaying HttpClient used.

Is there any reason to put this header on the RestTemplate by default? Removing the header with the header filter the Rest request ran normally.

Also i tried to use a RestTemplate - but the header remains there, so just the header filter worked.

But when testing internally (using the HTTP Rest to connect distinct Integration instances) things worked normally, i.e. the header message is handled normally(and i don't know the reason since the out. problem occurred with outbound RestServers.

The flow as example is bellow.

Regards,

**

IntegrationFlows.from("theRequestChannel")
                    .transform(Transformers.fromJson(MyClass.class))
                    .enrichHeaders(m -> m.header("app_id", "appid"))
                    .enrichHeaders(m -> m.header("app_key", "app_key"))
                    .headerFilter("accept-encoding")
                    .handle(myHandler())
                    .get();

**

1 Answers1

0

Fully unclear what you are asking. There is no an accept-encoding auto header in Spring Integration. I may assume that you have an HTTP Inbound Channel Adapter and this header is sent by the outside client to you application.

If the REST Service you need to call really doesn't like that headers, that us really a good choice to filter such a header before performing a request. Such a header is not configured on the RestTemplate, since you don't exclude it from there, but filter before reaching that RestTemplate.

Another option you can consider is a DefaultHttpHeaderMapper with its setOutboundHeaderNames() to configure a set of header patterns to transfer from the message to HTTP request. Of course, excluding the mentioned accept-encoding.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Indeed i used a setOutboundHeaderNames..and put the headers to "*"... and in fact the UnitTest uses an HC... like CloseableHttpClient httpclient = HttpClients.createDefault(); and i dont set any header on the HC client. – Jose Carlos Canova May 21 '18 at 18:09
  • Will change the test to SOAPUI and see what happens. – Jose Carlos Canova May 21 '18 at 18:10
  • You are right... the SOAPUI using HCHttpComponents is adding the content-encoding:gzip,deflate... POST http://localhost:8080/enroll HTTP/1.1 Accept-Encoding: gzip,deflate Content-Type: application/json Content-Length: 108 Host: localhost:8080 Connection: Keep-Alive User-Agent: Apache-HttpClient/4.1.1 (java 1.5) – Jose Carlos Canova May 21 '18 at 18:14
  • But what is not fully undestand is why i need to filter the request to avoid the exception on response. since is throwing the exception when will convert the response from JSON to Object. – Jose Carlos Canova May 21 '18 at 18:15
  • Because incoming HTTP headers are mapped to the message headers by default. And when we send HTTP request we also map all headers by default. As I said: you receive that header to you app from the external request. Why such a `gzip` `accept-encoding` doesn't work for you is a different story and you should consult with the vendor of your REST service. – Artem Bilan May 21 '18 at 18:35