1

Folks...

the curl line: curl https://api.storify.com/v1/stories/storify

produces a lengthy JSON response from storify. My attempt to translate this to Spring's RestTemplate looks like this:

@Test
public void test() {
    RestTemplate template = new RestTemplate();
    URI uri=URI.create("https://api.storify.com/v1/stories/storify");
    ResponseEntity<String> response = template.getForEntity(uri,String.class);
    System.out.println("<<<<<<<<<<");
    System.out.println(response.getStatusCode()+" "+response.hasBody());
    System.out.println("<<<<<<<<<<");

    String text = response.getBody();
    System.out.println(response.getBody());
    System.out.println("<<<<<<<<<<");
}

While the resulting status code is 200, and hasBody() is true, the getBody() isn't returning anything but seemingly an empty line. How can I replicate the results of the curl using RestTemplate?

Thanks, GeePaw

GeePawHill
  • 29
  • 1
  • 7

2 Answers2

2

It is working for me, However Can you try running the following code, Might help

 RestTemplate restTemplate = new RestTemplate();
 String result = restTemplate.getForObject("https://api.storify.com/v1/stories/storify", String.class);
 System.out.println(result);

Also If you are behind proxy ( Might be an office network ), Then dont forget to add proxy details to your RestTemplate. Here is snippet to add "10.1.2.3" as Host for port no. 80

SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
InetSocketAddress address = new InetSocketAddress("10.1.2.3", 80);
Proxy proxy = new Proxy(Proxy.Type.HTTP,address);
factory.setProxy(proxy);

restTemplate.setRequestFactory(factory);
thatman
  • 333
  • 3
  • 14
-1

I finally got this one. Thanks for the support, Piyush, you gave me the confidence that it really was just me.

The upshot: the amoeba was fine, my microscope was cracked. The output from that println is a massive single line of JSON. I was printing it from Eclipse. The Eclipse console does not handle that sort of thing the way an ordinary shell does. I got no output because Eclipse gave me none. Running in the shell works fine on this variant, and likely the other 15 variants I tried, too. :)

Thanks, GeePaw

GeePawHill
  • 29
  • 1
  • 7