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 comments:

  1. It’s difficult to find knowledgeable people with this topic, however you seem like there’s more you are referring to! Thanks.url

    ReplyDelete
  2. Great!!. This is very much useful when we are handling legacy application to be upgraded partially.

    ReplyDelete
  3. Brilliant , could not find this anywhere else ,, thanks

    ReplyDelete
  4. As well as adding new usefulness to your current kinds of content, some WordPress modules are intended to suit explicit sorts of site. http://wordpressctapro.com/

    ReplyDelete