0

I have a system who use spring boot. it use rest.

I try to call one of the service of this system with this code

public static void main(String[] args) {
    int timeout = 10000;
    final RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout * 1000).setConnectionRequestTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build();

    final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), new UsernamePasswordCredentials("bob", "smith"));
    final CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).setDefaultCredentialsProvider(credentialsProvider).build();

    final ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(client);
    RestTemplate restTemplate = new RestTemplate(requestFactory);

    Map < String, String > vars = new HashMap < String, String > ();
    vars.put("cardId", "E004010024ABF84C");

    boolean accessAllowed = restTemplate.getForObject("http://localhost:8080/rest/client/card/", Boolean.class, vars);
    System.out.println(accessAllowed);
}

I posted error here

http://pastebin.com/JBJT49Ry

Yvan Dupré
  • 51
  • 2
  • 10

1 Answers1

0

The URI you're providing to the client does not contain the host part.

Should it be something like this?

restTemplate.getForObject("http://example.org/rest/client/card/", Boolean.class, vars);

In case you want to configure a RestTemplate instance to always target the same host, you can configure it this way:

DefaultUriTemplateHandler uriTemplateHandler = new DefaultUriTemplateHandler();
uriTemplateHandler.setBaseUrl("http://example.org");
restTemplate. setUriTemplateHandler(uriTemplateHandler);
Brian Clozel
  • 56,583
  • 15
  • 167
  • 176