4/19/2019

Disable encoding URL Using RestTemplate in Spring

The RestTemplate is smart to convert the URL with specific characters to URL encoded. But sometimes, we need to disable URL encoding in order to some specific characters are available on server side as its business requirement.
It's a legacy web service and bad design, but customer don't want to change for some reasons.

Disable Encoding URL

Set encoding encoding mode when initialing rest template.

DefaultUriBuilderFactory defaultUriBuilderFactory = new DefaultUriBuilderFactory();
defaultUriBuilderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE);
      
RestTemplate restTemplate = new RestTemplate();
restTemplate.setUriTemplateHandler(defaultUriBuilderFactory);

Using other encoding mode to satisfy different integration strategies.

TEMPLATE_AND_VALUES, VALUES_ONLY, URI_COMPONENT, NONE

4/10/2019

3 Type of Timeouts in Http client

There are three type of timeouts in Http Client which could be considered to be adjusted when encountering unreliable destination endpoint.

  1. ConnectionTimeout
    Set the timeout in milliseconds used when requesting a connection from the connection manager.
  2. ConnectionRequestTimeout
    Determines the timeout in milliseconds until a connection is established. A timeout value of zero is interpreted as an infinite timeout.
  3. SocketTimeout
    Determines the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets).