Java Code Examples for javax.portlet.PortletRequest#setAttribute()
The following examples show how to use
javax.portlet.PortletRequest#setAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleAttributeTest.java From portals-pluto with Apache License 2.0 | 6 votes |
protected TestResult checkSetAttribute(PortletRequest req) { TestResult result = new TestResult(); result.setDescription("Ensure that attributes can be set to " + "portlet request."); req.setAttribute(KEY, VAL); Object val = req.getAttribute(KEY); if (VAL.equals(val)) { result.setReturnCode(TestResult.PASSED); } else { TestUtils.failOnAssertion("attribute", val, VAL, result); } req.removeAttribute(KEY); return result; }
Example 2
Source File: SimpleAttributeTest.java From portals-pluto with Apache License 2.0 | 6 votes |
protected TestResult checkEnumerateAttributes(PortletRequest req) { TestResult result = new TestResult(); result.setDescription("Ensure that all attribute names appear in the " + "attribute name enumeration returned by portlet request."); int count = 5; for (int i = 0; i < count; i++) { req.setAttribute(KEY + "." + i, VAL); } int found = 0; for (Enumeration<String> en = req.getAttributeNames(); en.hasMoreElements(); ) { if (en.nextElement().toString().startsWith(KEY)) { found++; } } if (count == found) { result.setReturnCode(TestResult.PASSED); } else { TestUtils.failOnAssertion("count of attribute names", String.valueOf(found), String.valueOf(count), result); } return result; }
Example 3
Source File: DispatcherPortlet.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Actually render the given view. * <p>The default implementation delegates to * {@link org.springframework.web.servlet.ViewRendererServlet}. * @param view the View to render * @param model the associated model * @param request current portlet render/resource request * @param response current portlet render/resource response * @throws Exception if there's a problem rendering the view */ protected void doRender(View view, Map<String, ?> model, PortletRequest request, MimeResponse response) throws Exception { // Expose Portlet ApplicationContext to view objects. request.setAttribute(ViewRendererServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, getPortletApplicationContext()); // These attributes are required by the ViewRendererServlet. request.setAttribute(ViewRendererServlet.VIEW_ATTRIBUTE, view); request.setAttribute(ViewRendererServlet.MODEL_ATTRIBUTE, model); // Include the content of the view in the render/resource response. doDispatch(getPortletContext().getRequestDispatcher(this.viewRendererUrl), request, response); }
Example 4
Source File: PortletUtils.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Expose the given Map as request attributes, using the keys as attribute names * and the values as corresponding attribute values. Keys must be Strings. * @param request current portlet request * @param attributes the attributes Map */ public static void exposeRequestAttributes(PortletRequest request, Map<String, ?> attributes) { Assert.notNull(request, "Request must not be null"); Assert.notNull(attributes, "Attributes Map must not be null"); for (Map.Entry<String, ?> entry : attributes.entrySet()) { request.setAttribute(entry.getKey(), entry.getValue()); } }
Example 5
Source File: SimpleAttributeTest.java From portals-pluto with Apache License 2.0 | 5 votes |
protected TestResult checkRemoveAttribute(PortletRequest req) { TestResult result = new TestResult(); result.setDescription("Ensure that attributes can be removed from " + "portlet request."); req.setAttribute(KEY, VAL); req.removeAttribute(KEY); Object val = req.getAttribute(KEY); if (val == null) { result.setReturnCode(TestResult.PASSED); } else { TestUtils.failOnAssertion("removed attribute", val, null, result); } return result; }
Example 6
Source File: DispatcherRequestTest.java From portals-pluto with Apache License 2.0 | 5 votes |
private TestResult doCheckIncludedAttribute(PortletContext context, PortletRequest request, PortletResponse response, String pathInfo) throws IOException, PortletException { // Save expected values as request attributes. String contextPath = request.getContextPath(); String requestUri = contextPath + SERVLET_PATH + pathInfo; request.setAttribute(EXPECTED_REQUEST_URI, requestUri); request.setAttribute(EXPECTED_CONTEXT_PATH, contextPath); // Dispatch to the companion servlet: call checkParameters(). StringBuffer buffer = new StringBuffer(); buffer.append(SERVLET_PATH).append(pathInfo).append("?") .append(QUERY_STRING); if (LOG.isDebugEnabled()) { LOG.debug("Dispatching to: " + buffer.toString()); } PortletRequestDispatcher dispatcher = context.getRequestDispatcher( buffer.toString()); dispatcher.include((RenderRequest) request, (RenderResponse) response); // Retrieve test result returned by the companion servlet. TestResult result = (TestResult) request.getAttribute(RESULT_KEY); request.removeAttribute(RESULT_KEY); request.removeAttribute(EXPECTED_REQUEST_URI); request.removeAttribute(EXPECTED_CONTEXT_PATH); return result; }
Example 7
Source File: TestFilter.java From portals-pluto with Apache License 2.0 | 5 votes |
private void processRequest(PortletRequest request) { String phase = (String) request.getAttribute(PortletRequest.LIFECYCLE_PHASE); request.setAttribute( WildcardMappedFilter.ATTR_TO_BE_OVERWRITTEN, phase); request.setAttribute(TEST_FILTER_ATTR, Boolean.TRUE); }
Example 8
Source File: WildcardMappedFilter.java From portals-pluto with Apache License 2.0 | 4 votes |
private void processRequest(PortletRequest request) { request.setAttribute(ATTR_SET_IN_FILTER, Boolean.TRUE); request.setAttribute(ATTR_TO_BE_OVERWRITTEN, ATTR_TO_BE_OVERWRITTEN); }
Example 9
Source File: PortletRequestDispatcherImpl.java From portals-pluto with Apache License 2.0 | 4 votes |
private void doDispatch(PortletRequest request, PortletResponse response, boolean included) throws PortletException, IOException { boolean needsFlushAfterForward = false; if (!included) { String lifecyclePhase = (String) request.getAttribute(PortletRequest.LIFECYCLE_PHASE); if (PortletRequest.RENDER_PHASE.equals(lifecyclePhase) || PortletRequest.RESOURCE_PHASE.equals(lifecyclePhase)) { needsFlushAfterForward = true; ((MimeResponse) response).resetBuffer(); } } PortletRequestContext requestContext = (PortletRequestContext) request .getAttribute(PortletInvokerService.REQUEST_CONTEXT); HttpSession session = null; // PLT.10.4.3. Proxied session is created and passed if javax.portlet.servletDefaultSessionScope == PORTLET_SCOPE if (isPortletScopeSessionConfigured(requestContext)) { String portletWindowId = requestContext.getPortletWindow().getId().getStringId(); session = ServletPortletSessionProxy.createProxy(requestContext.getServletRequest(), portletWindowId); } // The servlet request and response wrappers are applied only a single time HttpServletPortletRequestWrapper req = getWrappedRequest(requestContext.getServletRequest()); HttpServletPortletResponseWrapper res = getWrappedResponse(requestContext.getServletResponse()); if (req == null) { req = new HttpServletPortletRequestWrapper(requestContext.getServletRequest(),session, request); } if (res == null) { res = new HttpServletPortletResponseWrapper(requestContext.getServletResponse(), request, response, included); } // to control the DispatcherType available in the body of the portlet boolean executingReqBody = requestContext.isExecutingRequestBody(); requestContext.setExecutingRequestBody(false); try { request.setAttribute(PortletInvokerService.PORTLET_CONFIG, requestContext.getPortletConfig()); request.setAttribute(PortletInvokerService.PORTLET_REQUEST, request); request.setAttribute(PortletInvokerService.PORTLET_RESPONSE, response); if (!included) { if (namedDispatch) { req.startNamed(path); } else { req.startForward(path); } if (req.isForwardingPossible()) { requestDispatcher.forward(req, res); } else { // need to "fake" the forward using an include requestDispatcher.include(req, res); } } else { if (namedDispatch) { req.startNamed(path); } else { req.startInclude(path); } requestDispatcher.include(req, res); } if (needsFlushAfterForward) { ((MimeResponse) response).flushBuffer(); } } catch (ServletException sex) { if (sex.getRootCause() != null) { throw new PortletException(sex.getRootCause()); } throw new PortletException(sex); } finally { request.removeAttribute(PortletInvokerService.PORTLET_CONFIG); request.removeAttribute(PortletInvokerService.PORTLET_REQUEST); request.removeAttribute(PortletInvokerService.PORTLET_RESPONSE); requestContext.setExecutingRequestBody(executingReqBody); req.endDispatch(); } }
Example 10
Source File: ViewRendererMvcImpl.java From portals-pluto with Apache License 2.0 | 4 votes |
@Override public void render(PortletRequest portletRequest, MimeResponse mimeResponse, PortletConfig portletConfig) throws PortletException { Map<String, Object> modelMap = models.asMap(); for (Map.Entry<String, Object> entry : modelMap.entrySet()) { portletRequest.setAttribute(entry.getKey(), entry.getValue()); } String viewName = (String) portletRequest.getAttribute(VIEW_NAME); if (viewName != null) { if (!viewName.contains(".")) { String defaultViewExtension = (String) configuration.getProperty( ConfigurationImpl.DEFAULT_VIEW_EXTENSION); viewName = viewName.concat(".").concat(defaultViewExtension); } ViewEngine supportingViewEngine = null; for (ViewEngine viewEngine : viewEngines) { if (viewEngine.supports(viewName)) { supportingViewEngine = viewEngine; break; } } if (supportingViewEngine == null) { throw new PortletException(new ViewEngineException("No ViewEngine found that supports " + viewName)); } try { beanManager.fireEvent(new BeforeProcessViewEventImpl(viewName, supportingViewEngine.getClass())); supportingViewEngine.processView(new ViewEngineContextImpl(configuration, portletRequest, mimeResponse, models, portletRequest.getLocale())); beanManager.fireEvent(new AfterProcessViewEventImpl(viewName, supportingViewEngine.getClass())); } catch (ViewEngineException vee) { throw new PortletException(vee); } } if ((mutableBindingResult != null) && !mutableBindingResult.isConsulted()) { Set<ParamError> allErrors = mutableBindingResult.getAllErrors(); for (ParamError paramError : allErrors) { if (LOG.isWarnEnabled()) { LOG.warn("BindingResult error not processed for " + paramError.getParamName() + ": " + paramError.getMessage()); } } } }