當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpStatusCodeException.getResponseBodyAsString方法代碼示例

本文整理匯總了Java中org.springframework.web.client.HttpStatusCodeException.getResponseBodyAsString方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatusCodeException.getResponseBodyAsString方法的具體用法?Java HttpStatusCodeException.getResponseBodyAsString怎麽用?Java HttpStatusCodeException.getResponseBodyAsString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.client.HttpStatusCodeException的用法示例。


在下文中一共展示了HttpStatusCodeException.getResponseBodyAsString方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getHttpErrorMessage

import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
/**
 * 
 * @param error
 * @return Error message containing description of the error. If no
 * description is found, it will return the exception error or HTTP status
 * text message, if present. May return null if no message can be resolved.
 */
protected static String getHttpErrorMessage(HttpStatusCodeException error) {
	String message = null;
	if (error instanceof CloudFoundryException) {
		message = ((CloudFoundryException) error).getDescription();
	}

	if (message == null) {
		message = error.getMessage();
		if (message == null) {
			message = error.getStatusText();
			if (message == null) {
				message = error.getResponseBodyAsString();
			}
		}
	}
	return message;
}
 
開發者ID:eclipse,項目名稱:cft,代碼行數:25,代碼來源:CloudErrorUtil.java

示例2: callDownstream

import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
private String callDownstream(String uri) {
    try {
        ResponseEntity<String> responseEntity = this.oAuth2RestTemplate.getForEntity(uri, String.class);
        return responseEntity.getBody();
    } catch(HttpStatusCodeException statusCodeException) {
        return statusCodeException.getResponseBodyAsString();
    }
}
 
開發者ID:bijukunjummen,項目名稱:oauth-uaa-sample,代碼行數:9,代碼來源:DownstreamServiceHandler.java

示例3: request

import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
private String request(RestTemplate template) {

		// Uninitialized and sealed can cause status 500
		try {
			ResponseEntity<String> responseEntity = template.exchange(url, HttpMethod.GET,
					null, String.class);
			return responseEntity.getBody();
		}
		catch (HttpStatusCodeException e) {
			return e.getResponseBodyAsString();
		}
	}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:13,代碼來源:ClientHttpRequestFactoryFactoryIntegrationTests.java

示例4: retrieveErrorMessage

import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
protected String retrieveErrorMessage(Throwable e) {
    if (e instanceof HttpStatusCodeException) {
        HttpStatusCodeException ex = (HttpStatusCodeException) e;
        return ex.getMessage() + ": " + ex.getResponseBodyAsString();
    }
    return e.getMessage();
}
 
開發者ID:mkopylec,項目名稱:charon-spring-boot-starter,代碼行數:8,代碼來源:LoggingListener.java

示例5: getMessage

import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
private String getMessage(String task, String url, HttpStatusCodeException e) {
    String message = e.getMessage();
    String jsonResponse = e.getResponseBodyAsString();
    if (StringUtils.hasText(jsonResponse)) {
        JsonNode json = POMUtils.parseJSONtoNode(jsonResponse);
        JsonNode firstError = json.path("error").path("errors").path(0);
        message += "; " + firstError.path("message").asText();
    }
    return "JDS error during " + task + " at \"" + url + "\": " + message;
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:11,代碼來源:DefaultJdsExceptionTranslator.java

示例6: handleHttpStatusCodeError

import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
/**
 * @param uriVariables
 * @param tryNumber
 * @param error
 * @throws RestApiException if tryNumber >= API_RETRY.
 */
protected void handleHttpStatusCodeError(Map<String, String> uriVariables, int tryNumber, HttpStatusCodeException error) {
    if (error.getStatusCode() == HttpStatus.UNAUTHORIZED) {
        resetBhRestToken(uriVariables);
    }
    log.error(
            "HttpStatusCodeError making api call. Try number:" + tryNumber + " out of " + API_RETRY + ". Http status code: "
                    + error.getStatusCode() + ". Response body: " + error.getResponseBodyAsString(), error);
    if (tryNumber >= API_RETRY) {
        throw new RestApiException("HttpStatusCodeError making api call with url variables " + uriVariables.toString()
                + ". Http status code: " + error.getStatusCode().toString() + ". Response body: " + error == null ? ""
                : error.getResponseBodyAsString());
    }
}
 
開發者ID:bullhorn,項目名稱:sdk-rest,代碼行數:20,代碼來源:StandardBullhornData.java

示例7: makeRequest

import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
/** Makes a generic request to the server with the specified attributes
 * 
 *  Automatically adds and requests the authentication to each request. Will automatically retry the request if the
 *  	Authentication token has expired	
 *  
 * @param url The URL to make the request on
 * @param method The HTTP method of the request
 * @param requestEntity The request Entity representing the request body and headers
 * @param responseType The expected response type of the request
 * @param urlVariables Any url parameters
 * @return The results from the request, or null if there were any errors
 * @throws RequestException If an error occurred while making the request
 */

protected AFTResponse<T> makeRequest(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... urlVariables) throws RequestException {	
	HttpEntity<?> entity = addAuthenticationHeaders(requestEntity);
	try {
		ResponseEntity<T> results = restTemplate.exchange(url, method, entity, responseType, urlVariables);
		return processSucessfulRequestResponse(results, url, method, requestEntity, responseType, urlVariables);
	}
	catch (HttpStatusCodeException e) {
		String responseBody = e.getResponseBodyAsString();
		HttpStatus status = e.getStatusCode();
		return processErrorRequestResponse(responseBody, status, url, method, requestEntity, responseType, urlVariables);
	}
}
 
開發者ID:mwcaisse,項目名稱:AndroidFT,代碼行數:27,代碼來源:AbstractRequest.java

示例8: executeHttpCmd

import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
private ResponseEntity<String> executeHttpCmd(
        HttpCommand cmd,
        BulbCmdTranslator_HTTP cmdTranslator)throws BulbBridgeHwException{
    if(log.isDebugEnabled()){
        log.debug("|- Invocing HTTP Cmd: " + cmd);
    }
    try{
        ResponseEntity<String> resp = restClient.exchange(
                cmd.getUrl(), 
                cmd.getHttpMethod(), 
                cmd.getEntity(), String.class, cmd.getUrlVariables());
        
        if(HttpStatus.OK != resp.getStatusCode()){
            throw new BulbBridgeHwException(
                    resp.getStatusCode().value(), 
                    resp.getStatusCode().getReasonPhrase(), 
                    resp.getBody());
        }
        InvocationResponse invocationResp;
        if( (invocationResp = cmdTranslator.checkResponseForError(resp.getBody())) != null){
            throw new BulbBridgeHwException(invocationResp.getMessage(), null);
        }
        return resp;
    }catch(HttpStatusCodeException bbex){
        throw new BulbBridgeHwException(
                bbex.getStatusCode().value(), bbex.getStatusText(), bbex.getResponseBodyAsString());
    }catch(RestClientException rcex){
        throw new BulbBridgeHwException(rcex.getMessage(), rcex);
    }
}
 
開發者ID:datenstrudel,項目名稱:bulbs-core,代碼行數:31,代碼來源:BulbBridgeHardwareAdapter_REST.java

示例9: buildDataRetrievalException

import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
protected DataRetrievalException buildDataRetrievalException(
    HttpStatusCodeException ex) {
  return new DataRetrievalException(
      getResultClass().getSimpleName(), ex.getStatusCode(), ex.getResponseBodyAsString()
  );
}
 
開發者ID:OpenLMIS,項目名稱:openlmis-stockmanagement,代碼行數:7,代碼來源:BaseCommunicationService.java

示例10: CredHubException

import org.springframework.web.client.HttpStatusCodeException; //導入方法依賴的package包/類
/**
 * Create a new exception with the provided root cause.
 *
 * @param e an {@link HttpStatusCodeException} caught while attempting to communicate
 * with CredHub
 */
public CredHubException(HttpStatusCodeException e) {
	super("Error calling CredHub: " + e.getStatusCode() + ": "
			+ e.getResponseBodyAsString());
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:11,代碼來源:CredHubException.java


注:本文中的org.springframework.web.client.HttpStatusCodeException.getResponseBodyAsString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。