use of javax.portlet.PortletPreferences in project uPortal by Jasig.
the class GoogleAnalyticsConfigController method getData.
@ResourceMapping("getData")
public String getData(PortletRequest portletRequest, ModelMap model) throws IOException {
final PortletPreferences preferences = portletRequest.getPreferences();
final JsonNode config = this.portletPreferencesJsonDao.getJsonNode(preferences, CONFIG_PREF_NAME);
model.put("data", config);
return "jsonView";
}
use of javax.portlet.PortletPreferences in project uPortal by Jasig.
the class JspInvokerPortletController method getPreferences.
private Map<String, List<String>> getPreferences(PortletRequest req) {
// default
Map<String, List<String>> rslt = new HashMap<String, List<String>>();
PortletPreferences prefs = req.getPreferences();
List<String> names = Collections.list(prefs.getNames());
for (String name : names) {
if (!name.startsWith(CONTROLLER_PREFERENCE_PREFIX)) {
// Pass it along in the model
List<String> values = Arrays.asList(prefs.getValues(name, new String[] {}));
rslt.put(name, values);
}
}
logger.debug("Invoking with preferences={}", rslt);
return rslt;
}
use of javax.portlet.PortletPreferences in project uPortal by Jasig.
the class SoffitConnectorController method invokeService.
@RenderMapping
public void invokeService(final RenderRequest req, final RenderResponse res) {
final PortletPreferences prefs = req.getPreferences();
final String serviceUrl = prefs.getValue(SERVICE_URL_PREFERENCE, null);
if (serviceUrl == null) {
throw new IllegalStateException("Missing portlet prefernce value for " + SERVICE_URL_PREFERENCE);
}
// First look in cache for an existing response that applies to this request
ResponseWrapper responseValue = fetchContentFromCacheIfAvailable(req, serviceUrl);
if (responseValue != null) {
logger.debug("Response value obtained from cache for serviceUrl '{}'", serviceUrl);
} else {
logger.debug("No applicable response in cache; invoking serviceUrl '{}'", serviceUrl);
final HttpGet getMethod = new HttpGet(serviceUrl);
try (final CloseableHttpClient httpClient = httpClientBuilder.build()) {
// Send the data model as encrypted JWT HTTP headers
for (IHeaderProvider headerProvider : headerProviders) {
final Header header = headerProvider.createHeader(req, res);
getMethod.addHeader(header);
}
// Send the request
final HttpResponse httpResponse = httpClient.execute(getMethod);
try {
final int statusCode = httpResponse.getStatusLine().getStatusCode();
logger.debug("HTTP response code for url '{}' was '{}'", serviceUrl, statusCode);
if (statusCode == HttpStatus.SC_OK) {
responseValue = extractResponseAndCacheIfAppropriate(httpResponse, req, serviceUrl);
} else {
logger.error("Failed to get content from remote service '{}'; HttpStatus={}", serviceUrl, statusCode);
res.getWriter().write(// TODO: Better message
"FAILED! statusCode=" + statusCode);
}
} finally {
if (null != httpResponse) {
// Ensures that the entity content is fully consumed and the content stream, if exists, is closed.
EntityUtils.consumeQuietly(httpResponse.getEntity());
}
}
} catch (IOException e) {
logger.error("Failed to invoke serviceUrl '{}'", serviceUrl, e);
}
}
if (responseValue != null) {
// Whether by cache or by fresh HTTP request, we have a response we can show...
try {
res.getPortletOutputStream().write(responseValue.getBytes());
} catch (IOException e) {
logger.error("Failed to write the response for serviceUrl '{}'", serviceUrl, e);
}
}
}
Aggregations