本文整理匯總了Java中com.google.api.client.http.HttpResponseException.computeMessageBuffer方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponseException.computeMessageBuffer方法的具體用法?Java HttpResponseException.computeMessageBuffer怎麽用?Java HttpResponseException.computeMessageBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.client.http.HttpResponseException
的用法示例。
在下文中一共展示了HttpResponseException.computeMessageBuffer方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: from
import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
/**
* Returns a new instance of {@link LenientTokenResponseException}.
* <p>
* If there is a JSON error response, it is parsed using
* {@link TokenErrorResponse}, which can be inspected using
* {@link #getDetails()}. Otherwise, the full response content is read and
* included in the exception message.
* </p>
*
* @param jsonFactory JSON factory
* @param readResponse an HTTP response that has already been read
* @param responseContent the content String of the HTTP response
* @return new instance of {@link TokenErrorResponse}
*/
public static LenientTokenResponseException from(JsonFactory jsonFactory,
HttpResponse readResponse, String responseContent) {
HttpResponseException.Builder builder = new HttpResponseException.Builder(
readResponse.getStatusCode(), readResponse.getStatusMessage(),
readResponse.getHeaders());
// details
Preconditions.checkNotNull(jsonFactory);
TokenErrorResponse details = null;
String detailString = null;
String contentType = readResponse.getContentType();
try {
if (/* !response.isSuccessStatusCode() && */true
&& contentType != null
&& HttpMediaType.equalsIgnoreParameters(Json.MEDIA_TYPE, contentType)) {
details = readResponse
.getRequest()
.getParser()
.parseAndClose(new StringReader(responseContent), TokenErrorResponse.class);
detailString = details.toPrettyString();
} else {
detailString = responseContent;
}
} catch (IOException exception) {
// it would be bad to throw an exception while throwing an exception
exception.printStackTrace();
}
// message
StringBuilder message = HttpResponseException.computeMessageBuffer(readResponse);
if (!com.google.api.client.util.Strings.isNullOrEmpty(detailString)) {
message.append(StringUtils.LINE_SEPARATOR).append(detailString);
builder.setContent(detailString);
}
builder.setMessage(message.toString());
return new LenientTokenResponseException(builder, details);
}