forked from jeffsheets/MockRestServiceServerExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleRestService.java
More file actions
26 lines (23 loc) · 940 Bytes
/
SimpleRestService.java
File metadata and controls
26 lines (23 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.jeffsheets.rest;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
@Service
public class SimpleRestService {
@Autowired
private RestTemplate restTemplate;
public String getMessage() {
String result;
try {
String httpResult = restTemplate.getForObject("http://google.com", String.class);
result = "Message SUCCESS result: " + httpResult;
} catch (HttpStatusCodeException e) {
result = "Get FAILED with HttpStatusCode: " + e.getStatusCode() + "|" + e.getStatusText();
} catch (RuntimeException e) {
result = "Get FAILED\n" + ExceptionUtils.getFullStackTrace(e);
}
return result;
}
}