本文整理匯總了Java中com.google.api.client.http.HttpResponse.parseAsString方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponse.parseAsString方法的具體用法?Java HttpResponse.parseAsString怎麽用?Java HttpResponse.parseAsString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.client.http.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.parseAsString方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPublicKeysJson
import com.google.api.client.http.HttpResponse; //導入方法依賴的package包/類
/**
*
* @return
* @throws IOException
*/
private JsonObject getPublicKeysJson() throws IOException {
// get public keys
URI uri = URI.create(pubKeyUrl);
GenericUrl url = new GenericUrl(uri);
HttpTransport http = new NetHttpTransport();
HttpResponse response = http.createRequestFactory().buildGetRequest(url).execute();
// store json from request
String json = response.parseAsString();
// disconnect
response.disconnect();
// parse json to object
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
return jsonObject;
}
示例2: get
import com.google.api.client.http.HttpResponse; //導入方法依賴的package包/類
protected Response get(String endPoint, Date modifiedAfter, Map<String, String> params) throws IOException {
HttpResponse resp = null;
OAuthRequestResource req = new OAuthRequestResource(config, signerFactory, endPoint, "GET", null, params);
req.setToken(token);
req.setTokenSecret(tokenSecret);
if (modifiedAfter != null) {
req.setIfModifiedSince(modifiedAfter);
}
try {
resp = req.execute();
String r = resp.parseAsString();
return unmarshallResponse(r, Response.class);
} catch (IOException ioe) {
throw xeroExceptionHandler.convertException(ioe);
}
}
示例3: handleResponse
import com.google.api.client.http.HttpResponse; //導入方法依賴的package包/類
/**
* Handler that will be invoked when an error response is received.
*
* @param request Instance of {@link HttpRequest}
* @param response Instance of {@link HttpResponse}
* @param supportsRetry Flag that indicates whether there will be a retry if this handler
* returns true.
*/
@Override
public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry)
throws IOException {
IOException exception;
try {
String responseString = response.parseAsString();
ErrorMessage msg = jsonFactory.fromString(responseString, ErrorMessage.class);
exception = new ApiException(msg);
} catch (IOException e) {
String errorMessage = "Couldn't parse JSON error message: " + e.getMessage();
logger.severe(errorMessage);
exception = new ApiException(errorMessage);
}
throw exception;
}
示例4: retrieveRemoteJwksUri
import com.google.api.client.http.HttpResponse; //導入方法依賴的package包/類
private GenericUrl retrieveRemoteJwksUri(String openIdUrl) {
try {
GenericUrl genericUrl = new GenericUrl(openIdUrl);
HttpResponse httpResponse = this.httpRequestFactory.buildGetRequest(genericUrl).execute();
String json = httpResponse.parseAsString();
ProviderMetadata metadata = OBJECT_MAPPER.readValue(json, ProviderMetadata.class);
return new GenericUrl(metadata.getJwksUri());
} catch (IOException exception) {
throw new UnauthenticatedException("Cannot retrieve or parse OpenId Provider Metadata",
exception);
}
}
示例5: retrieveJwksJson
import com.google.api.client.http.HttpResponse; //導入方法依賴的package包/類
private String retrieveJwksJson(GenericUrl jwksUri) {
try {
HttpResponse response = this.httpRequestFactory.buildGetRequest(jwksUri).execute();
return response.parseAsString();
} catch (IOException exception) {
String message = String.format("Cannot retrive the JWKS json from %s", jwksUri.build());
throw new UnauthenticatedException(message, exception);
}
}
示例6: getCardFromResponse
import com.google.api.client.http.HttpResponse; //導入方法依賴的package包/類
protected static Card getCardFromResponse(HttpResponse response)
{
String responseString = "";
try {
responseString = response.parseAsString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Card[] returnedCardArr = gson.fromJson(responseString, Card[].class);
return returnedCardArr[0];
}
示例7: getStationsList
import com.google.api.client.http.HttpResponse; //導入方法依賴的package包/類
public List<Station> getStationsList(Location location, String nextPageToken) {
double latitude = location.getLat();
double longitude = location.getLng();
this._latitude = latitude;
this._longitude = longitude;
String types="gas_station";
try {
HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
HttpRequest request = httpRequestFactory
.buildGetRequest(new GenericUrl(PLACES_SEARCH_URL));
request.getUrl().put("types", types);
request.getUrl().put("rankby", "distance");
request.getUrl().put("location", _latitude + "," + _longitude);
request.getUrl().put("sensor", "false");
request.getUrl().put("key", API_KEY);
if(nextPageToken!=null && !nextPageToken.isEmpty())
request.getUrl().put("pagetoken",nextPageToken);
HttpResponse response = request.execute();
String str = response.parseAsString();
return parser.listFromJson(str);
} catch (java.io.IOException e) {
Log.e("Error:", e.getMessage());
return null;
}
}