Search in sources :

Example 11 with HTTPRequestInfo

use of com.google.appengine.tools.cloudstorage.oauth.URLFetchUtils.HTTPRequestInfo in project appengine-gcs-client by GoogleCloudPlatform.

the class OauthRawGcsService method getObjectMetadata.

@Override
public GcsFileMetadata getObjectMetadata(GcsFilename filename, long timeoutMillis) throws IOException {
    HTTPRequest req = makeRequest(filename, null, HEAD, timeoutMillis);
    HTTPResponse resp;
    try {
        resp = urlfetch.fetch(req);
    } catch (IOException e) {
        throw createIOException(new HTTPRequestInfo(req), e);
    }
    int responseCode = resp.getResponseCode();
    if (responseCode == 404) {
        return null;
    }
    if (responseCode != 200) {
        throw HttpErrorHandler.error(new HTTPRequestInfo(req), resp);
    }
    return getMetadataFromResponse(filename, resp, getLengthFromHeader(resp, X_GOOG_CONTENT_LENGTH));
}
Also used : HTTPRequest(com.google.appengine.api.urlfetch.HTTPRequest) HTTPResponse(com.google.appengine.api.urlfetch.HTTPResponse) HTTPRequestInfo(com.google.appengine.tools.cloudstorage.oauth.URLFetchUtils.HTTPRequestInfo) IOException(java.io.IOException)

Example 12 with HTTPRequestInfo

use of com.google.appengine.tools.cloudstorage.oauth.URLFetchUtils.HTTPRequestInfo in project appengine-gcs-client by GoogleCloudPlatform.

the class OauthRawGcsService method deleteObject.

/**
 * True if deleted, false if not found.
 */
@Override
public boolean deleteObject(GcsFilename filename, long timeoutMillis) throws IOException {
    HTTPRequest req = makeRequest(filename, null, DELETE, timeoutMillis);
    HTTPResponse resp;
    try {
        resp = urlfetch.fetch(req);
    } catch (IOException e) {
        throw createIOException(new HTTPRequestInfo(req), e);
    }
    switch(resp.getResponseCode()) {
        case 204:
            return true;
        case 404:
            return false;
        default:
            throw HttpErrorHandler.error(new HTTPRequestInfo(req), resp);
    }
}
Also used : HTTPRequest(com.google.appengine.api.urlfetch.HTTPRequest) HTTPResponse(com.google.appengine.api.urlfetch.HTTPResponse) HTTPRequestInfo(com.google.appengine.tools.cloudstorage.oauth.URLFetchUtils.HTTPRequestInfo) IOException(java.io.IOException)

Aggregations

HTTPRequestInfo (com.google.appengine.tools.cloudstorage.oauth.URLFetchUtils.HTTPRequestInfo)12 HTTPRequest (com.google.appengine.api.urlfetch.HTTPRequest)11 HTTPResponse (com.google.appengine.api.urlfetch.HTTPResponse)11 IOException (java.io.IOException)8 HTTPHeader (com.google.appengine.api.urlfetch.HTTPHeader)3 FutureWrapper (com.google.appengine.api.utils.FutureWrapper)2 URL (java.net.URL)2 Test (org.junit.Test)2 HttpRequest (com.google.api.client.http.HttpRequest)1 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)1 HttpResponseException (com.google.api.client.http.HttpResponseException)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 Storage (com.google.api.services.storage.Storage)1 BadRangeException (com.google.appengine.tools.cloudstorage.BadRangeException)1 GcsFilename (com.google.appengine.tools.cloudstorage.GcsFilename)1 ListItem (com.google.appengine.tools.cloudstorage.ListItem)1 Escaper (com.google.common.escape.Escaper)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1