public String render(Gadget gadget) throws RenderingException, GadgetException {
View view = gadget.getCurrentView();
Uri href = view.getHref();
Preconditions.checkArgument(href != null, "Gadget does not have href for the current view");
GadgetContext context = gadget.getContext();
String path = context.getParameter(PATH_PARAM);
if (path != null) {
try {
Uri relative = Uri.parse(path);
if (!relative.isAbsolute()) {
href = href.resolve(relative);
}
} catch (IllegalArgumentException e) {
// TODO: Spec does not say what to do for an invalid relative path.
// Just ignoring for now.
}
}
UriBuilder uri = new UriBuilder(href);
uri.addQueryParameter("lang", context.getLocale().getLanguage());
uri.addQueryParameter("country", context.getLocale().getCountry());
OAuthArguments oauthArgs = new OAuthArguments(view);
oauthArgs.setProxiedContentRequest(true);
HttpRequest request = new HttpRequest(uri.toUri())
.setIgnoreCache(context.getIgnoreCache())
.setOAuthArguments(oauthArgs)
.setAuthType(view.getAuthType())
.setSecurityToken(context.getToken())
.setContainer(context.getContainer())
.setGadget(gadget.getSpec().getUrl());
HttpResponse response = httpCache.getResponse(request);
if (response == null || response.isStale()) {