本文整理汇总了Java中com.google.api.client.http.EmptyContent类的典型用法代码示例。如果您正苦于以下问题:Java EmptyContent类的具体用法?Java EmptyContent怎么用?Java EmptyContent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EmptyContent类属于com.google.api.client.http包,在下文中一共展示了EmptyContent类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serverErrorCallback
import com.google.api.client.http.EmptyContent; //导入依赖的package包/类
/**
* {@link Beta} <br/>
* The call back method that will be invoked on a server error or an I/O
* exception during resumable upload inside {@link #upload}.
*
* <p>
* This method changes the current request to query the current status of
* the upload to find how many bytes were successfully uploaded before the
* server error occurred.
* </p>
*/
@Beta
void serverErrorCallback() throws IOException {
Preconditions.checkNotNull(currentRequest,
"The current request should not be null");
// Query the current status of the upload by issuing an empty PUT
// request on the upload URI.
currentRequest.setContent(new EmptyContent());
currentRequest
.getHeaders()
.setContentRange(
"bytes */"
+ (isMediaLengthKnown() ? getMediaContentLength()
: "*"));
}
示例2: addChildToGroup
import com.google.api.client.http.EmptyContent; //导入依赖的package包/类
public static boolean addChildToGroup(HttpRequestFactory pHttpRequestFactory, AlfrescoConfig pConfig,
String pStrGroupId, String pStrChildId) {
mLog.debug("START addChildToGroup(String, String)");
boolean lRet = false;
GroupsUrl lUrl = new GroupsUrl(pConfig.getHost());
lUrl.addChild(pStrGroupId, pStrChildId);
try {
// FIXME (Alessio): bisognerebbe trasferire altrove questo codice ripetitivo
HttpHeaders lRequestHeaders = new HttpHeaders().setContentType("application/json");
HttpRequest lRequest =
pHttpRequestFactory.buildPostRequest(lUrl, new EmptyContent()).setHeaders(lRequestHeaders);
// TODO (Alessio): la risposta è completamente ignorata! Vanno gestiti i diversi casi
// possibili.
// L'implementazione dovrebbe prima controllare se l'utente è già parte del gruppo,
// quindi eventualmente effettuare l'aggiunta.
int lStatusCode = lRequest.execute().getStatusCode();
if (200 <= lStatusCode && lStatusCode < 300) {
lRet = true;
}
} catch (Exception e) {
// TODO (Alessio): gestione decente delle eccezioni
// mLog.error("Unexpected failure", e);
lRet = false;
}
mLog.debug("END addChildToGroup(String, String)");
return lRet;
}
示例3: executeUploadInitiation
import com.google.api.client.http.EmptyContent; //导入依赖的package包/类
/**
* This method sends a POST request with empty content to get the unique
* upload URL.
*
* @param initiationRequestUrl
* The request URL where the initiation request will be sent
*/
private HttpResponse executeUploadInitiation(GenericUrl initiationRequestUrl)
throws IOException {
updateStateAndNotifyListener(UploadState.INITIATION_STARTED);
initiationRequestUrl.put("uploadType", "resumable");
HttpContent content = metadata == null ? new EmptyContent() : metadata;
HttpRequest request = requestFactory.buildRequest(
initiationRequestMethod, initiationRequestUrl, content);
initiationHeaders.set(CONTENT_TYPE_HEADER, mediaContent.getType());
if (isMediaLengthKnown()) {
initiationHeaders.set(CONTENT_LENGTH_HEADER,
getMediaContentLength());
}
request.getHeaders().putAll(initiationHeaders);
HttpResponse response = executeCurrentRequest(request);
boolean notificationCompleted = false;
try {
updateStateAndNotifyListener(UploadState.INITIATION_COMPLETE);
notificationCompleted = true;
} finally {
if (!notificationCompleted) {
response.disconnect();
}
}
return response;
}
示例4: executeCurrentRequest
import com.google.api.client.http.EmptyContent; //导入依赖的package包/类
/**
* Executes the current request with some common code that includes
* exponential backoff and GZip encoding.
*
* @param request
* current request
* @return HTTP response
*/
private HttpResponse executeCurrentRequest(HttpRequest request)
throws IOException {
// enable GZip encoding if necessary
if (!disableGZipContent
&& !(request.getContent() instanceof EmptyContent)) {
request.setEncoding(new GZipEncoding());
}
// execute request
HttpResponse response = executeCurrentRequestWithoutGZip(request);
return response;
}
示例5: buildHttpRequest
import com.google.api.client.http.EmptyContent; //导入依赖的package包/类
private HttpRequest buildHttpRequest() throws IOException {
final HttpRequest httpRequest = getGracenote().getRequestFactory().buildRequest(HttpMethods.POST, buildHttpRequestUrl(), httpContent);
httpRequest.setParser(getGracenote().getObjectParser());
if (httpContent == null) {
httpRequest.setContent(new EmptyContent());
}
return httpRequest;
}
示例6: initiateResumableUpload
import com.google.api.client.http.EmptyContent; //导入依赖的package包/类
/**
* Initiates the resumable upload by sending a request to Google Cloud Storage.
*
* @param batchJobUploadUrl the {@code uploadUrl} of a {@code BatchJob}
* @return the URI for the initiated resumable upload
*/
private URI initiateResumableUpload(URI batchJobUploadUrl) throws BatchJobException {
// This follows the Google Cloud Storage guidelines for initiating resumable uploads:
// https://cloud.google.com/storage/docs/resumable-uploads-xml
HttpRequestFactory requestFactory =
httpTransport.createRequestFactory(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
HttpHeaders headers = createHttpHeaders();
headers.setContentLength(0L);
headers.set("x-goog-resumable", "start");
request.setHeaders(headers);
request.setLoggingEnabled(true);
}
});
try {
HttpRequest httpRequest =
requestFactory.buildPostRequest(new GenericUrl(batchJobUploadUrl), new EmptyContent());
HttpResponse response = httpRequest.execute();
if (response.getHeaders() == null || response.getHeaders().getLocation() == null) {
throw new BatchJobException(
"Initiate upload failed. Resumable upload URI was not in the response.");
}
return URI.create(response.getHeaders().getLocation());
} catch (IOException e) {
throw new BatchJobException("Failed to initiate upload", e);
}
}