-2

I am using microservices using spring boot in my application, I use RestTemplate to call other component services from "org.springframework.web.client.RestTemplate".
I have a common service from my component which calls other components to fetch data.

Whenever my search text has a backslash like "test\" my API call fails. After debugging I came to the conclusion that till restTemplete.exchange API is not failing and I am not getting any requests in other component API methods.

// restTemplete.exchange(serviceUrl, HttpMethod.POST, request, responseType);

If I put 'text\t' API call is successful and control is reaching the other component not sure if I am missing anything on this. How do I escape the escape character?

I have tried text.replace("\\", "\\\\");, but still no success.

DuckDuck
  • 1
  • 1

2 Answers2

0

You can use something called UriComponentsBuilder. https://stackoverflow.com/a/28183190/8278152

Building your url using above component should help you.

Sandip Jangra
  • 145
  • 2
  • 9
  • i am already using UriComponentsBuilder for serviceUrl , the issue is with request body, not sure how to handle this. – DuckDuck Nov 17 '20 at 14:11
-2

The better approach to utilize the REST API's of the microservices, registered under the same architecture, is to use Feign Client. For more details click here