List of usage examples for org.springframework.web.client HttpServerErrorException printStackTrace
public void printStackTrace()
From source file:org.encuestame.oauth1.support.OAuth1Support.java
/** * * @param tokenUrl//from w w w . jav a 2 s . com * @param tokenRequestParameters * @param additionalParameters * @param tokenSecret * @return * @throws EnMeOAuthSecurityException */ protected OAuth1Token getTokenFromProvider(String tokenUrl, Map<String, String> tokenRequestParameters, Map<String, String> additionalParameters, String tokenSecret) throws EnMeOAuthSecurityException { log.debug("getTokenFromProvider TOKEN " + tokenUrl); log.debug("getTokenFromProvider TOKEN " + tokenRequestParameters); log.debug("getTokenFromProvider TOKEN " + additionalParameters); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", getAuthorizationHeaderValue(tokenUrl, tokenRequestParameters, additionalParameters, tokenSecret)); MultiValueMap<String, String> bodyParameters = new LinkedMultiValueMap<String, String>(); bodyParameters.setAll(additionalParameters); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>( bodyParameters, headers); Map<String, String> responseMap = null; /* * org.springframework.web.client.HttpServerErrorException: 503 Service Unavailable * Sometimes, api service are unavailable, like the famous twitter over capacity */ try { ResponseEntity<String> response = getRestTemplate().exchange(tokenUrl, HttpMethod.POST, request, String.class); responseMap = parseResponse(response.getBody()); } catch (HttpServerErrorException e) { e.printStackTrace(); throw new EnMeOAuthSecurityException(e); } catch (HttpClientErrorException e) { // normally if the social credentials are wrong e.printStackTrace(); throw new EnMeBadCredentialsException(e.getMessage()); } catch (Exception e) { // another kind of error, possible wrong configuration //TODO : only happends with twitter e.printStackTrace(); throw new EnMeBadCredentialsException(e.getMessage()); } return new OAuth1Token(responseMap.get("oauth_token"), responseMap.get("oauth_token_secret")); }