com.google.appengine.api.urlfetch.HTTPHeader

Here are the examples of the java api class com.google.appengine.api.urlfetch.HTTPHeader taken from open source projects.

1. GoogleAppEngineRequestor#toRequestorResponse()

Project: dropbox-sdk-java
File: GoogleAppEngineRequestor.java
private static Response toRequestorResponse(HTTPResponse response) {
    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    for (HTTPHeader header : response.getHeadersUncombined()) {
        List<String> existing = headers.get(header.getName());
        if (existing == null) {
            existing = new ArrayList<String>();
            headers.put(header.getName(), existing);
        }
        existing.add(header.getValue());
    }
    return new Response(response.getResponseCode(), new ByteArrayInputStream(response.getContent()), headers);
}

2. GaePendingResult#parseResponse()

Project: google-maps-services-java
File: GaePendingResult.java
@SuppressWarnings("unchecked")
private T parseResponse(GaePendingResult<T, R> request, HTTPResponse response) throws Exception {
    if (RETRY_ERROR_CODES.contains(response.getResponseCode()) && cumulativeSleepTime < errorTimeOut) {
        // call, which is blocking anyway, or we're handling a callback in a separate thread.
        return request.retry();
    }
    byte[] bytes = response.getContent();
    R resp;
    String contentType = null;
    for (HTTPHeader header : response.getHeaders()) {
        if (header.getName().equalsIgnoreCase("Content-Type")) {
            contentType = header.getValue();
        }
    }
    // Places Photo API special case
    if (contentType != null && contentType.startsWith("image") && responseClass == PhotoRequest.Response.class && response.getResponseCode() == 200) {
        // Photo API response is just a raw image byte array.
        PhotoResult result = new PhotoResult();
        result.contentType = contentType;
        result.imageData = bytes;
        return (T) result;
    }
    Gson gson = new GsonBuilder().registerTypeAdapter(DateTime.class, new DateTimeAdapter()).registerTypeAdapter(Distance.class, new DistanceAdapter()).registerTypeAdapter(Duration.class, new DurationAdapter()).registerTypeAdapter(Fare.class, new FareAdapter()).registerTypeAdapter(LatLng.class, new LatLngAdapter()).registerTypeAdapter(AddressComponentType.class, new SafeEnumAdapter<AddressComponentType>(AddressComponentType.UNKNOWN)).registerTypeAdapter(AddressType.class, new SafeEnumAdapter<AddressType>(AddressType.UNKNOWN)).registerTypeAdapter(TravelMode.class, new SafeEnumAdapter<TravelMode>(TravelMode.UNKNOWN)).registerTypeAdapter(LocationType.class, new SafeEnumAdapter<LocationType>(LocationType.UNKNOWN)).registerTypeAdapter(RatingType.class, new SafeEnumAdapter<RatingType>(RatingType.UNKNOWN)).registerTypeAdapter(DayOfWeek.class, new DayOfWeekAdaptor()).registerTypeAdapter(PriceLevel.class, new PriceLevelAdaptor()).registerTypeAdapter(Instant.class, new InstantAdapter()).registerTypeAdapter(LocalTime.class, new LocalTimeAdapter()).setFieldNamingPolicy(fieldNamingPolicy).create();
    // body that we can use to provide a more descriptive exception.
    try {
        resp = gson.fromJson(new String(bytes, "utf8"), responseClass);
    } catch (JsonSyntaxException e) {
        if (response.getResponseCode() > 399) {
            throw new IOException(String.format("Server Error: %d %s", response.getResponseCode(), new String(response.getContent(), Charset.defaultCharset())));
        }
        throw e;
    }
    if (resp.successful()) {
        // Return successful responses
        return resp.getResult();
    } else {
        ApiException e = resp.getError();
        if (e instanceof OverQueryLimitException && cumulativeSleepTime < errorTimeOut) {
            // Retry over_query_limit errors
            return request.retry();
        } else {
            // Throw anything else, including OQLs if we've spent too much time retrying
            throw e;
        }
    }
}