本文整理汇总了Java中com.google.api.client.http.HttpResponse.parseAs方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse.parseAs方法的具体用法?Java HttpResponse.parseAs怎么用?Java HttpResponse.parseAs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.http.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.parseAs方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signInWithCustomToken
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
private String signInWithCustomToken(String customToken) throws IOException {
GenericUrl url = new GenericUrl(ID_TOOLKIT_URL + "?key="
+ IntegrationTestUtils.getApiKey());
Map<String, Object> content = ImmutableMap.<String, Object>of(
"token", customToken, "returnSecureToken", true);
HttpRequest request = transport.createRequestFactory().buildPostRequest(url,
new JsonHttpContent(jsonFactory, content));
request.setParser(new JsonObjectParser(jsonFactory));
HttpResponse response = request.execute();
try {
GenericJson json = response.parseAs(GenericJson.class);
return json.get("idToken").toString();
} finally {
response.disconnect();
}
}
示例2: createThumbnail
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
/**
* Richiede ad Alfresco la creazione di una <i>thumbnail</i>.
* <p>
* Si tenga presente che in caso di creazione asincrona la <i>thumbnail</i> potrebbe non essere
* subito disponibile anche se il metodo ha restituito informazioni valide.
*
* @param pContentId
* L'id del contenuto.
* @param pThumbDefinition
* Il nome della <i>thumbnail</i> di cui si richiede la crezione.
* @param pAsync
* Se la crazione deve essere sincrona ({@code true} o asincrona ({@false}).
*
* @return La <i>thumbnail</i> richiesta o {@code null} se il tipo di <i>thumbnail</i> di cui si
* è richiesta la creazione non è valido per il contenuto specificato.
*
* @throws IOException
*/
public Thumbnail createThumbnail(String pContentId, String pThumbDefinition, boolean pAsync) throws IOException {
/*
* POST <base>/content{property}/thumbnails?as={async?}
*
* {
* "thumbnailName": <name>
* }
*/
GenericUrl lUrl = getContentUrl(pContentId);
lUrl.appendRawPath(URL_RELATIVE_THUMBNAILS);
lUrl.set("as", pAsync);
// Recupero delle definizioni valide
// Purtroppo Alfresco restituisce successo anche se viene richiesta la generazione di una
// thumbnail non possibile. Controllando preventivamente si può restituire null.
List<String> lThumbDefinitions = getThumbnailDefinitions(pContentId);
if (!lThumbDefinitions.contains(pThumbDefinition)) {
return null;
}
JsonHttpContent lContent = new JsonHttpContent(JSON_FACTORY, new Thumbnail(pThumbDefinition));
HttpHeaders lRequestHeaders = new HttpHeaders().setContentType("application/json");
HttpRequest lRequest =
mHttpRequestFactory.buildPostRequest(lUrl, lContent).setHeaders(lRequestHeaders);
HttpResponse lResponse = lRequest.execute();
Thumbnail lThumbnail = lResponse.parseAs(Thumbnail.class);
return lThumbnail;
}
示例3: post
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T post(String path, Object request, Type responseType)
throws RepoException, ValidationException {
HttpRequestFactory requestFactory = getHttpRequestFactory(getCredentials());
GenericUrl url = new GenericUrl(URI.create(API_URL + "/" + path));
try {
HttpRequest httpRequest = requestFactory.buildPostRequest(url,
new JsonHttpContent(JSON_FACTORY, request));
HttpResponse response = httpRequest.execute();
return (T) response.parseAs(responseType);
} catch (IOException e) {
throw new RepoException("Error running GitHub API operation " + path, e);
}
}
示例4: get
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T get(String path, Type responseType) throws RepoException, ValidationException {
HttpRequestFactory requestFactory = getHttpRequestFactory(getCredentialsIfPresent());
GenericUrl url = new GenericUrl(URI.create(API_URL + "/" + path));
try {
HttpRequest httpRequest = requestFactory.buildGetRequest(url);
HttpResponse response = httpRequest.execute();
return (T) response.parseAs(responseType);
} catch (IOException e) {
throw new RepoException("Error running GitHub API operation " + path, e);
}
}
示例5: execute
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T execute(Type responseType, HttpRequest httpRequest)
throws IOException, GerritApiException {
HttpResponse response;
try {
response = httpRequest.execute();
} catch (HttpResponseException e) {
throw new GerritApiException(e.getStatusCode(), e.getContent());
}
return (T) response.parseAs(responseType);
}
示例6: executeAndParse
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
<T> T executeAndParse(HttpRequest request, Class<T> cls) throws IOException {
if (log.isDebugEnabled()) {
log.debug("Calling {} on {}", request.getRequestMethod(), request.getUrl());
}
HttpResponse response = request.execute();
if (response.isSuccessStatusCode()) {
return response.parseAs(cls);
} else {
SalesforceException exception = response.parseAs(SalesforceException.class);
throw exception;
}
}
示例7: execute
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public ExecuteResults execute() throws IOException {
HttpResponse response = this.httpRequest.execute();
return response.parseAs(ExecuteResults.class);
}
示例8: execute
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
public QueryResults execute() throws IOException {
HttpResponse response = this.httpRequest.execute();
return response.parseAs(QueryResults.class);
}
示例9: put
import com.google.api.client.http.HttpResponse; //导入方法依赖的package包/类
@Override
public void put(Collection<SinkRecord> collection) {
if (collection.isEmpty()) {
log.trace("No records in collection.");
return;
}
try {
log.trace("Posting {} message(s) to {}", collection.size(), this.eventCollectorUrl);
SinkRecordContent sinkRecordContent = new SinkRecordContent(collection);
if (log.isTraceEnabled()) {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
sinkRecordContent.writeTo(outputStream);
outputStream.flush();
byte[] buffer = outputStream.toByteArray();
log.trace("Posting\n{}", new String(buffer, "UTF-8"));
} catch (IOException ex) {
if (log.isTraceEnabled()) {
log.trace("exception thrown while previewing post", ex);
}
}
}
HttpRequest httpRequest = this.httpRequestFactory.buildPostRequest(this.eventCollectorUrl, sinkRecordContent);
HttpResponse httpResponse = httpRequest.execute();
if (httpResponse.getStatusCode() == 403) {
throw new ConnectException("Authentication was not successful. Please check the token with Splunk.");
}
if (httpResponse.getStatusCode() == 417) {
log.warn("This exception happens when too much content is pushed to splunk per call. Look at this blog post " +
"http://blogs.splunk.com/2016/08/12/handling-http-event-collector-hec-content-length-too-large-errors-without-pulling-your-hair-out/" +
" Setting consumer.max.poll.records to a lower value will decrease the number of message posted to Splunk " +
"at once.");
throw new ConnectException("Status 417: Content-Length of XXXXX too large (maximum is 1000000). Verify Splunk config or " +
" lower the value in consumer.max.poll.records.");
}
if (JSON_MEDIA_TYPE.equalsIgnoreParameters(httpResponse.getMediaType())) {
SplunkStatusMessage statusMessage = httpResponse.parseAs(SplunkStatusMessage.class);
if (!statusMessage.isSuccessful()) {
throw new RetriableException(statusMessage.toString());
}
} else {
throw new RetriableException("Media type of " + Json.MEDIA_TYPE + " was not returned.");
}
} catch (IOException e) {
throw new RetriableException(
String.format("Exception while posting data to %s.", this.eventCollectorUrl),
e
);
}
}