Correct way to implement HTTP Connection Pooling

Beware of how HTTP Client pools work, it may be improving performance during a short period of time. Check the analysis below: From PoolingHttpClientConnectionManager javadocs The handling of stale connections was changed in version 4.4. Previously, the code would check every connection by default before re-using it. The code now only checks the connection if … Read more

RestTemplate with pem certificate

So knowledge about using pem certificate with RestTemplate is distracted. Steps which must be done: Add server certificate to trustStore, using keytool or portecle. When you want to use custom trusttore use this script Next configure ssl to RestTemplate. It may be done like below: @Configuration public class SSLConfiguration { @Value(“${certificate.name}”) private String name; @Bean(name … Read more

SSLHandshakeException: Received fatal alert: handshake_failure when setting ciphers on tomcat 7 server

Well, I got this issue solved. It appears that by creating a self-signed certificate, using keytool, without providing -keyalg parameter makes the key-pair algorithm default to DSA. None of my ciphers suite included DSA algorithm. In that case, although the client and the server had intersection between their cipher-suites, neither was suitable for the key … Read more

spring resttemplate url encoding

There is no easy way to do this. URI template variables are usually meant for path elements or a query string parameters. You’re trying to pass a host. Ideally, you’d find a better solution for constructing the URI. I suggest Yuci’s solution. If you still want to work with Spring utilities and template expansion, one … Read more

How to parse gzip encoded response with RestTemplate in Spring-Web

Replace the default requestFactory with one from Apache HttpClient (which decodes GZIP on the fly): HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create().build()); RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory); Add Apache Http Client into pom.xml <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <!–Version is not needed when used with Spring Boot parent pom file –> <version>4.5.1</version> </dependency>

How to autowire RestTemplate using annotations

Errors you’ll see if a RestTemplate isn’t defined Consider defining a bean of type ‘org.springframework.web.client.RestTemplate’ in your configuration. or No qualifying bean of type [org.springframework.web.client.RestTemplate] found How to define a RestTemplate via annotations Depending on which technologies you’re using and what versions will influence how you define a RestTemplate in your @Configuration class. Spring >= … Read more

How to forward large files with RestTemplate?

Edit: The other answers are better (use Resource) https://stackoverflow.com/a/36226006/116509 My original answer: You can use execute for this kind of low-level operation. In this snippet I’ve used Commons IO’s copy method to copy the input stream. You would need to customize the HttpMessageConverterExtractor for the kind of response you’re expecting. final InputStream fis = new … Read more