我使用具有低於頭Spring框架:獲取狀態響應(如400,500)
import org.springframework.web.client.RestTemplate;
我想獲取的狀態代碼來寫我的記錄器。我如何獲得restTemplate的響應?
public boolean performTransition(String transitionId,String jiraId){
JiraID id = new JiraID(transitionId);
JiraTransition transition = new JiraTransition();
transition.setTransition(id);
String transitionUrlFormat = String.format(transitionUrl,jiraId);
RestTemplate template = new RestTemplate();
HttpEntity epicEntityRequest = new HttpEntity(transition,createHttpHeaders());
HttpEntity<String> epicEntityResponse= template.exchange(transitionUrlFormat , HttpMethod.POST, epicEntityRequest, String.class);
//TODO: verify code 204
ResponseEntity<String> responseEntity= (ResponseEntity<String>) epicEntityResponse;
epicEntityResponse.getBody();
//System.out.println("LOG" +responseEntity);
//responseEntity.getStatusCode();
HttpStatus statusCode = responseEntity.getStatusCode();
return true;
}
此外,我想檢查400以上的響應代碼我想寫log.warning()。
顯示您的代碼片段 – pvpkiran
編輯答案。 –