public GadgetsHandlerApi.ProxyResponse getProxy(GadgetsHandlerApi.ProxyRequest request)
throws ProcessingException {
verifyBaseParams(request, true);
Set<String> fields = beanFilter.processBeanFields(request.getFields());
ProxyUri proxyUri = createProxyUri(request);
List<Uri> uris = proxyUriManager.make(ImmutableList.of(proxyUri), null);
HttpResponse httpResponse = null;
try {
if (isFieldIncluded(fields, "proxyContent")) {
httpResponse = proxyHandler.fetch(proxyUri);
}
} catch (IOException e) {
LOG.log(Level.INFO, "Failed to fetch resource " + proxyUri.getResource().toString(), e);
throw new ProcessingException("Error getting response content", HttpResponse.SC_BAD_GATEWAY);
} catch (GadgetException e) {
LOG.log(Level.INFO, "Failed to fetch resource " + proxyUri.getResource().toString(), e);
throw new ProcessingException("Error getting response content", HttpResponse.SC_BAD_GATEWAY);
}
try {
return createProxyResponse(uris.get(0), httpResponse, fields,
getProxyExpireMs(proxyUri, httpResponse));
} catch (IOException e) {
LOG.log(Level.WARNING, "Error creating proxy response", e);
throw new ProcessingException("Error getting response content",
HttpResponse.SC_INTERNAL_SERVER_ERROR);
}
}