Skip to content
Advertisement

Tag: resttemplate

Custom RestTemplate using requestFactory of RestTemplateBuilder in SpringBoot 2.1.x is not backward compatible with version 1.5.x

In Spring Boot 1.5.x, I was creating a custom RestTemplate like below: But, after migrating to Spring Boot 2.1.x, the above code doesn’t compile. Looks like requestFactory doesn’t take HttpComponentsClientHttpRequestFactory as an input parameter. Can anyone suggest how can I make the above code work in Spring Boot 2.1.x? Answer After digging deeper into the source code of RestTemplateBuilder of

Spring RestTemplate message converter priority when posting

What is the most convenient way to influence the priority of the message converters Spring applies when POSTing with RestTemplate? Use case: I want to ensure a given entity is POSTed as JSON rather than e.g. XML when I do restTemplate.postForEntity(url, entity, Void.class). Default By default the entity is converted to XML because the MappingJackson2XmlHttpMessageConverter takes precedence over the MappingJackson2HttpMessageConverter.

How to send a multipart file to a service from another service

I have two endpoints api which are /uploadand /redirect /upload is where I directly upload the file. /redirect is where i receive the file and pass it to upload and get the JSON response from /upload.So below is my code: The endpoint /upload works pretty much fine.But when i call /redirect it throws an error of “exception”: “org.springframework.http.converter.HttpMessageNotWritableException”, “message”: “Could

RestTemplate: How to send URL and query parameters together

I am trying to pass path param and query params in a URL but I am getting a weird error. Below is the code. and my url is becoming http://test.com/Services/rest/%7Bid%7D/Identifier?name=myName What should I do to make it work? I am expecting http://test.com/Services/rest/{id}/Identifier?name=myName so that params will add id to the url. Answer I would use buildAndExpand from UriComponentsBuilder to pass

Advertisement