Java Code Examples for javax.portlet.PortletRequest#removeAttribute()

The following examples show how to use javax.portlet.PortletRequest#removeAttribute() . 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 vote down vote up
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: DispatcherRenderParameterTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkParameters(PortletContext context,
                                     PortletRequest request,
                                     PortletResponse response)
throws IOException, PortletException {

	// Dispatch to the companion servlet: call checkParameters().
	StringBuffer buffer = new StringBuffer();
	buffer.append(SERVLET_PATH).append("?")
			.append(KEY_TARGET).append("=").append(TARGET_PARAMS)
			.append("&").append(KEY_A).append("=").append(VALUE_A)
			.append("&").append(KEY_B).append("=").append(VALUE_B);

	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);
    return result;
}
 
Example 3
Source File: DispatcherRenderParameterTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkSameNameParameter(PortletContext context,
                                            PortletRequest request,
                                            PortletResponse response)
throws IOException, PortletException {

	// Dispatch to the companion servlet: call checkSameNameParameter().
	StringBuffer buffer = new StringBuffer();
	buffer.append(SERVLET_PATH).append("?")
			.append(KEY_TARGET).append("=").append(TARGET_SAME_NAME_PARAM)
			.append("&").append(KEY_C).append("=").append(VALUE_C1)
			.append("&").append(KEY_C).append("=").append(VALUE_C2)
			.append("&").append(KEY_C).append("=").append(VALUE_C3);

	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);
	return result;
}
 
Example 4
Source File: DispatcherRenderParameterTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkAddedSameNameParameter(PortletContext context,
                                                 PortletRequest request,
                                                 PortletResponse response)
throws IOException, PortletException {
	// Dispatch to the companion servlet: call checkAddedSameNameParameter().
	StringBuffer buffer = new StringBuffer();
	buffer.append(SERVLET_PATH).append("?")
			.append(KEY_TARGET).append("=").append(TARGET_ADDED_SAME_NAME_PARAM)
			.append("&").append(KEY_RENDER).append("=").append(VALUE_ADDED1)
			.append("&").append(KEY_RENDER).append("=").append(VALUE_ADDED2);

	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);
	return result;
}
 
Example 5
Source File: DispatcherRenderParameterTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkInvalidParameters(PortletContext context,
                                            PortletRequest request,
                                            PortletResponse response)
throws IOException, PortletException {

	// Dispatch to the companion servlet: call checkInvalidParameters().
	StringBuffer buffer = new StringBuffer();
	buffer.append(SERVLET_PATH).append("?")
			.append(KEY_TARGET).append("=").append(TARGET_INVALID_PARAMS)
			.append("&").append(KEY_A)
			.append("&").append(KEY_B).append("=").append(VALUE_B)
			.append("&").append(KEY_C).append("=");
	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);
	return result;
}
 
Example 6
Source File: SimpleAttributeTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
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 7
Source File: DispatcherRequestTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
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 8
Source File: PortletRequestDispatcherImpl.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
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();
   }
}