本文整理汇总了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;
}
}