Search in sources :

Example 36 with PortletPreferences

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";
}
Also used : PortletPreferences(javax.portlet.PortletPreferences) JsonNode(com.fasterxml.jackson.databind.JsonNode) ResourceMapping(org.springframework.web.portlet.bind.annotation.ResourceMapping)

Example 37 with PortletPreferences

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;
}
Also used : HashMap(java.util.HashMap) List(java.util.List) PortletPreferences(javax.portlet.PortletPreferences)

Example 38 with PortletPreferences

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);
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Header(org.apache.http.Header) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) PortletPreferences(javax.portlet.PortletPreferences) IOException(java.io.IOException) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Aggregations

PortletPreferences (javax.portlet.PortletPreferences)38 HashMap (java.util.HashMap)10 RenderMapping (org.springframework.web.portlet.bind.annotation.RenderMapping)9 ModelAndView (org.springframework.web.portlet.ModelAndView)6 List (java.util.List)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 IPerson (org.apereo.portal.security.IPerson)5 PortletRequest (javax.portlet.PortletRequest)4 ResourceMapping (org.springframework.web.portlet.bind.annotation.ResourceMapping)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Principal (java.security.Principal)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Header (org.apache.http.Header)2 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)2 MarketplaceEntry (org.apereo.portal.rest.layout.MarketplaceEntry)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2