0

In our application we're using

public class CustomRestTemplateCreator {    
public CustomRestTemplate create(String user, String password) {  
return new RestTemplateBuilder()
                .basicAuthentication(user, password)
                .requestFactory(() -> new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()))
                .build(CustomRestTemplate .class);

Which is used by

    public CustomClient create(Server server)  {
        String ipAddress = server.getAddress();
        AccessDTO accessDTO = AccessInterceptor.getAcces(ipAddress);
        CustomRestTemplate customRestTemplate = customRestTemplateCreator.create(accessDTO.getUsername(), accessDTO.getPassword());
        ServerUrl serverUrl = new ServerUrl(HTTP, accessDTO.getAddress(), port);
        return new CustomClientImpl(serverUrl, customRestTemplate);
    }

And CustomClientImpl have isComponentAvaliable() method, which is restTemplate.getForObject() and returns true or false.

Problem is that some servers forcing HTTPS connection, and we're getting following error:

org.springframework.web.client.UnknownContentTypeException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.some.class] and content type [text/html]

When we're trying the same endpoint manually or by postman everything is fine, but Spring look like have problem with redirecting between protocols.

Is there some way to automatically follow that redirection ?

Mike S
  • 11
  • 2
  • The protocol should not have any impact on the response content type. Moreover, your question is not very clear: which redirection? What code are you using? – Gaël J Jul 14 '21 at 17:10
  • have a look at: https://stackoverflow.com/questions/29418583/follow-302-redirect-using-spring-resttemplate – Ralph Jul 14 '21 at 18:09
  • @Ralph been there, but one of answers is deprecated and the other one just confirms that by default HTTP request are not redirected to HTTPS. – Mike S Jul 14 '21 at 18:56

0 Answers0