本文整理了Java中com.google.api.client.http.HttpResponse.parseAs()
方法的一些代码示例,展示了HttpResponse.parseAs()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.parseAs()
方法的具体详情如下:
包路径:com.google.api.client.http.HttpResponse
类名称:HttpResponse
方法名:parseAs
暂无
代码示例来源:origin: googleapis/google-cloud-java
return last && response != null ? response.parseAs(Job.class) : null;
} catch (IOException ex) {
throw translate(ex);
代码示例来源:origin: googleapis/google-cloud-java
@Override
public List<List<DetectionsResourceItems>> detect(List<String> texts) {
try {
Map<String, ?> content = ImmutableMap.of("q", texts);
HttpRequest httpRequest =
translate
.getRequestFactory()
.buildPostRequest(
buildTargetUrl("detect"),
new JsonHttpContent(translate.getJsonFactory(), content))
.setParser(translate.getObjectParser());
List<List<DetectionsResourceItems>> detections =
httpRequest.execute().parseAs(DetectionsListResponse.class).getDetections();
// TODO use REST apiary as soon as it supports POST
// List<List<DetectionsResourceItems>> detections =
//
// translate.detections().list(texts).setKey(options.getApiKey()).execute().getDetections();
return detections != null ? detections : ImmutableList.<List<DetectionsResourceItems>>of();
} catch (IOException ex) {
throw translate(ex);
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Override
public List<LanguagesResource> listSupportedLanguages(Map<Option, ?> optionMap) {
try {
Map<String, ?> content =
ImmutableMap.of(
"target",
firstNonNull(
Option.TARGET_LANGUAGE.getString(optionMap), options.getTargetLanguage()));
HttpRequest httpRequest =
translate
.getRequestFactory()
.buildPostRequest(
buildTargetUrl("languages"),
new JsonHttpContent(translate.getJsonFactory(), content))
.setParser(translate.getObjectParser());
List<LanguagesResource> languages =
httpRequest.execute().parseAs(LanguagesListResponse.class).getLanguages();
// TODO use REST apiary as soon as it supports POST
// List<LanguagesResource> languages = translate.languages()
// .list()
// .setKey(options.getApiKey())
// .setTarget(
// firstNonNull(TARGET_LANGUAGE.getString(optionMap), options.getTargetLanguage()))
// .execute().getLanguages();
return languages != null ? languages : ImmutableList.<LanguagesResource>of();
} catch (IOException ex) {
throw translate(ex);
}
}
代码示例来源:origin: google/google-api-java-client-samples
HttpResponse response = prediction.trainedmodels().get(PROJECT_ID, MODEL_ID).executeUnparsed();
if (response.getStatusCode() == 200) {
trainingModel = response.parseAs(Insert2.class);
String trainingStatus = trainingModel.getTrainingStatus();
if (trainingStatus.equals("DONE")) {
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
Dataset responseDataset = response.parseAs(Dataset.class);
System.out.printf(
"Updated label \"%s\" with value \"%s\"\n",
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
Table responseTable = response.parseAs(Table.class);
System.out.printf(
"Updated label \"%s\" with value \"%s\"\n",
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
private static String getGoogleIdToken(String jwt) throws Exception {
final GenericData tokenRequest =
new GenericData().set("grant_type", JWT_BEARER_TOKEN_GRANT_TYPE).set("assertion", jwt);
final UrlEncodedContent content = new UrlEncodedContent(tokenRequest);
final HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
final HttpRequest request =
requestFactory
.buildPostRequest(new GenericUrl(OAUTH_TOKEN_URI), content)
.setParser(new JsonObjectParser(JacksonFactory.getDefaultInstance()));
HttpResponse response;
String idToken = null;
response = request.execute();
GenericData responseData = response.parseAs(GenericData.class);
idToken = (String) responseData.get("id_token");
return idToken;
}
代码示例来源:origin: com.google.api-client/google-api-client
/**
* Sends the metadata request to the server and returns the parsed metadata response.
*
* <p>
* Subclasses may override by calling the super implementation.
* </p>
*
* @return parsed HTTP response
*/
public T execute() throws IOException {
return executeUnparsed().parseAs(responseClass);
}
代码示例来源:origin: com.google.api-client/google-api-client
@Override
public GoogleTokenResponse execute() throws IOException {
return executeUnparsed().parseAs(GoogleTokenResponse.class);
}
代码示例来源:origin: com.google.api-client/google-api-client
@Override
public GoogleTokenResponse execute() throws IOException {
return executeUnparsed().parseAs(GoogleTokenResponse.class);
}
代码示例来源:origin: org.nuxeo.ecm.liveconnect/nuxeo-liveconnect-onedrive-core
@Override
public TokenResponse execute() throws IOException {
return executeUnparsed().parseAs(OneDriveTokenResponse.class).toTokenResponse();
}
代码示例来源:origin: UglyTroLL/Douban-Java-SDK-OAuth2
public <T extends IDoubanObject> T getResponse(String url, List<NameValuePair> params, Class<T> responseType, boolean needAccessToken) throws DoubanException, IOException {
if (params != null && params.size() > 0) {
String encodedParams = encodeParameters(params);
url = url + "?" + encodedParams;
}
HttpRequest method = requestFactory.buildGetRequest(new GenericUrl(url));
return httpRequest(method, needAccessToken).parseAs(responseType);
}
代码示例来源:origin: UglyTroLL/Douban-Java-SDK-OAuth2
public <T, W extends IDoubanObject> W putResponse(String url, T requestObj, Class<W> responseType, boolean needAccessToken) throws DoubanException, IOException {
AtomContent content = AtomContent.forEntry(DefaultConfigs.DOUBAN_XML_NAMESPACE, requestObj);
HttpRequest method = requestFactory.buildPutRequest(new GenericUrl(url), content);
return httpRequest(method, needAccessToken).parseAs(responseType);
}
代码示例来源:origin: UglyTroLL/Douban-Java-SDK-OAuth2
public <T, W extends IDoubanObject> W postResponse(String url, T requestObj, Class<W> responseType, boolean needAccessToken) throws DoubanException, IOException {
AtomContent content = AtomContent.forEntry(DefaultConfigs.DOUBAN_XML_NAMESPACE, requestObj);
HttpRequest method = requestFactory.buildPostRequest(new GenericUrl(url), content);
return httpRequest(method, needAccessToken).parseAs(responseType);
}
代码示例来源:origin: UglyTroLL/Douban-Java-SDK-OAuth2
public <T> T getResponseInJsonArray(String url, List<NameValuePair> params, Class<T> responseType, boolean needAccessToken) throws DoubanException, IOException {
if (params != null && params.size() > 0) {
String encodedParams = encodeParameters(params);
url = url + "?" + encodedParams;
}
HttpRequest method = requestFactory.buildGetRequest(new GenericUrl(url));
method.setParser(new JsonObjectParser(new JacksonFactory()));
return httpRequest(method, needAccessToken).parseAs(responseType);
}
代码示例来源:origin: UglyTroLL/Douban-Java-SDK-OAuth2
public <T extends IDoubanObject> T getResponseInJson(String url, List<NameValuePair> params, Class<T> responseType, boolean needAccessToken) throws DoubanException, IOException {
if (params != null && params.size() > 0) {
String encodedParams = encodeParameters(params);
url = url + "?" + encodedParams;
}
HttpRequest method = requestFactory.buildGetRequest(new GenericUrl(url));
method.setParser(new JsonObjectParser(new JacksonFactory()));
return httpRequest(method, needAccessToken).parseAs(responseType);
}
代码示例来源:origin: UglyTroLL/Douban-Java-SDK-OAuth2
public <T, W extends IDoubanObject> W postResponseInJson(String url, T requestObj, Class<W> responseType, boolean needAccessToken) throws DoubanException, IOException {
AtomContent content = AtomContent.forEntry(DefaultConfigs.DOUBAN_XML_NAMESPACE, requestObj);
HttpRequest method = requestFactory.buildPostRequest(new GenericUrl(url), content);
method.setParser(new JsonObjectParser(new JacksonFactory()));
return httpRequest(method, needAccessToken).parseAs(responseType);
}
代码示例来源:origin: com.google.api-client/google-api-client
@Override
protected TokenResponse executeRefreshToken() throws IOException {
GenericUrl tokenUrl = new GenericUrl(getTokenServerEncodedUrl());
HttpRequest request = getTransport().createRequestFactory().buildGetRequest(tokenUrl);
request.setParser(new JsonObjectParser(getJsonFactory()));
request.getHeaders().set("Metadata-Flavor", "Google");
return request.execute().parseAs(TokenResponse.class);
}
代码示例来源:origin: GoogleCloudPlatform/bigdata-interop
@Override
protected TokenResponse executeRefreshToken() throws IOException {
HttpRequest request =
getTransport()
.createRequestFactory(getRequestInitializer())
.buildGetRequest(new GenericUrl(getTokenServerEncodedUrl()))
.setParser(new JsonObjectParser(getJsonFactory()));
request.getHeaders().set("Metadata-Flavor", "Google");
return request.execute().parseAs(TokenResponse.class);
}
}
代码示例来源:origin: com.google.cloud.bigdataoss/util
@Override
protected TokenResponse executeRefreshToken() throws IOException {
HttpRequest request =
getTransport()
.createRequestFactory(getRequestInitializer())
.buildGetRequest(new GenericUrl(getTokenServerEncodedUrl()))
.setParser(new JsonObjectParser(getJsonFactory()));
request.getHeaders().set("Metadata-Flavor", "Google");
return request.execute().parseAs(TokenResponse.class);
}
}
内容来源于网络,如有侵权,请联系作者删除!