Java Code Examples for javax.portlet.PortletSession#getAttribute()

The following examples show how to use javax.portlet.PortletSession#getAttribute() . 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: PortletHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static String getErrorOutput(PortletRequest request)
{   
	PortletSession pSession = request.getPortletSession(true);
	try {
		return (String) pSession.getAttribute("error.output");
	} catch (Throwable t) {
		return null;
	}
}
 
Example 2
Source File: DispatcherTests4_SPEC2_19_ForwardJSPAction.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp) throws PortletException, IOException {

   long tid = Thread.currentThread().getId();
   portletReq.setAttribute(THREADID_ATTR, tid);

   PrintWriter writer = portletResp.getWriter();

   PortletSession ps = portletReq.getPortletSession();
   String msg = (String) ps.getAttribute(RESULT_ATTR_PREFIX + "DispatcherTests4_SPEC2_19_ForwardJSPAction",
         APPLICATION_SCOPE);
   if (msg != null) {
      writer.write("<p>" + msg + "</p><br/>\n");
      ps.removeAttribute(RESULT_ATTR_PREFIX + "DispatcherTests4_SPEC2_19_ForwardJSPAction", APPLICATION_SCOPE);
   }

   /* TestCase: V2DispatcherTests4_SPEC2_19_ForwardJSPAction_invoke3 */
   /* Details: "Parameters to the forward method for a target servlet */
   /* can be wrapped request and response classes from the portlet */
   /* lifecyle method initiating the include" */
   {
      PortletURL aurl = portletResp.createActionURL();
      aurl.setParameters(portletReq.getPrivateParameterMap());
      TestButton tb = new TestButton(V2DISPATCHERTESTS4_SPEC2_19_FORWARDJSPACTION_INVOKE3, aurl);
      tb.writeTo(writer);
   }

}
 
Example 3
Source File: AnnotationTests_ProcessAction_ApiAction.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp)
    throws PortletException, IOException {

  long tid = Thread.currentThread().getId();
  portletReq.setAttribute(THREADID_ATTR, tid);

  PrintWriter writer = portletResp.getWriter();

  PortletSession ps = portletReq.getPortletSession();
  String msg =
      (String) ps.getAttribute(RESULT_ATTR_PREFIX + "AnnotationTests_ProcessAction_ApiAction",
          APPLICATION_SCOPE);
  if (msg != null) {
    writer.write("<p>" + msg + "</p><br/>\n");
    ps.removeAttribute(RESULT_ATTR_PREFIX + "AnnotationTests_ProcessAction_ApiAction",
        APPLICATION_SCOPE);
  }

  /* TestCase: V2AnnotationTests_ProcessAction_ApiAction_name */
  /* Details: "Method name(): On an action request, the method is */
  /* executed if the parameter \"javax.portlet.action\" matches the */
  /* name field" */
  {
    PortletURL aurl = portletResp.createActionURL();
    aurl.setParameter(ActionRequest.ACTION_NAME, V2ANNOTATIONTESTS_PROCESSACTION_APIACTION_NAME);
    TestButton tb = new TestButton(V2ANNOTATIONTESTS_PROCESSACTION_APIACTION_NAME, aurl);
    tb.writeTo(writer);
  }

}
 
Example 4
Source File: SimpleAttributeTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected TestResult checkGetNullAttribute(PortletSession session) {
    TestResult res = new TestResult();
    res.setName("Retrieve Missing Session Attribute Test");
    res.setDescription("Retrieves an attribute bound to an invalid key set are retrieved as null");

    Object val = session.getAttribute(KEY);
    if(val != null) {
        res.setReturnCode(TestResult.FAILED);
        res.setResultMessage("Retrieved value: '"+val+"' for attribute '"+KEY+"'");
    }
    else {
        res.setReturnCode(TestResult.PASSED);
    }
    return res;
}
 
Example 5
Source File: RenderStateTests_SPEC2_12_MutableRenderState2.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp)
      throws PortletException, IOException {

   portletResp.setContentType("text/html");
   PrintWriter writer = portletResp.getWriter();

   PortletSession ps = portletReq.getPortletSession();
   String msg = (String) ps.getAttribute(Constants.RESULT_ATTR_PREFIX + "RenderStateTests_SPEC2_12_MutableRenderState2");
   ps.removeAttribute(Constants.RESULT_ATTR_PREFIX + "RenderStateTests_SPEC2_12_MutableRenderState2");

   if (msg != null && msg.length() > 0) {
      writer.write("<p>" + msg + "</p>\n");
   }
   
   /*
    * TestCase:
    * V3RenderStateTests_SPEC2_12_MutableRenderState_getRenderParameters3
    */
   /*
    * Details:
    * "If no render parameters are available, the object will be empty."
    */
   {
      ActionURL actionURL = portletResp.createActionURL();
      MutableActionParameters mutableActionParams = actionURL
            .getActionParameters();
      mutableActionParams.clear();
      TestButton tb = new TestButton(
            V3RENDERSTATETESTS_SPEC2_12_MUTABLERENDERSTATE_GETRENDERPARAMETERS3,
            actionURL);
      tb.writeTo(writer);
   }

}
 
Example 6
Source File: IMSBLTIPortlet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {

	log.debug("==== processAction called ====");

	String action = request.getParameter("sakai.action");
	log.debug("sakai.action = {}", action);

	PortletSession pSession = request.getPortletSession(true);

	// Clear before Action
	clearErrorMessage(request);

	String view = (String) pSession.getAttribute("sakai.view");
	log.debug("sakai.view={}", view);

	if ( action == null ) {
		// Do nothing
	} else if ( action.equals("main") ) {
		response.setPortletMode(PortletMode.VIEW);
	} else if ( action.equals("edit") ) {
		pSession.setAttribute("sakai.view", "edit");
	} else if ( action.equals("edit.reset") ) {
		pSession.setAttribute("sakai.view","edit.reset");
	} else if (action.equals("edit.setup")){
		pSession.setAttribute("sakai.view","edit.setup");
	} else if ( action.equals("edit.clear") ) {
		clearSession(request);
		response.setPortletMode(PortletMode.VIEW);
		pSession.setAttribute("sakai.view", "main");
	} else if ( action.equals("edit.do.reset") ) {
		processActionReset(action,request, response);
	} else if ( action.equals("edit.save") ) {
		processActionSave(action,request, response);
	}
	log.debug("==== End of ProcessAction ====");
}
 
Example 7
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static Map getErrorMap(PortletRequest request)
{   
	PortletSession pSession = request.getPortletSession(true);
	try {
		return (Map) pSession.getAttribute("error.map");
	} catch (Throwable t) {
		return null;
	}
}
 
Example 8
Source File: AppScopedSessionAttributeTest.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected TestResult checkGetEmptyAppScopedAttribute(PortletSession session) {
    TestResult result = new TestResult();
    result.setDescription("Retrieve an attribute that has not been set "
    		+ "in the session's application scope "
    		+ "and ensure it's value is null.");
    result.setSpecPLT("15.3");

    Object value = session.getAttribute(BOGUS_KEY, PortletSession.APPLICATION_SCOPE);
    if (value == null) {
    	result.setReturnCode(TestResult.PASSED);
    } else {
    	TestUtils.failOnAssertion("session attribute", value, null, result);
    }
    return result;
}
 
Example 9
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static String getErrorOutput(PortletRequest request)
{   
	PortletSession pSession = request.getPortletSession(true);
	try {
		return (String) pSession.getAttribute("error.output");
	} catch (Throwable t) {
		return null;
	}
}
 
Example 10
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static Map getErrorMap(PortletRequest request)
{   
	PortletSession pSession = request.getPortletSession(true);
	try {
		return (Map) pSession.getAttribute("error.map");
	} catch (Throwable t) {
		return null;
	}
}
 
Example 11
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static String getDebugOutput(PortletRequest request)
{   
	PortletSession pSession = request.getPortletSession(true);
	try {
		return (String) pSession.getAttribute("debug.print");
	} catch (Throwable t) {
		return null;
	}
}
 
Example 12
Source File: DispatcherTests3S_SPEC2_19_IncludeJSPAction.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp) throws PortletException, IOException {

   long tid = Thread.currentThread().getId();
   portletReq.setAttribute(THREADID_ATTR, tid);

   PrintWriter writer = portletResp.getWriter();

   PortletSession ps = portletReq.getPortletSession();
   String msg = (String) ps.getAttribute(RESULT_ATTR_PREFIX + V2DISPATCHERTESTS3S_SPEC2_19_INCLUDEJSPACTION_DISPATCH4,
         APPLICATION_SCOPE);
   if (msg != null) {
      writer.write("<p>" + msg + "</p><br/>\n");
      ps.removeAttribute(RESULT_ATTR_PREFIX + V2DISPATCHERTESTS3S_SPEC2_19_INCLUDEJSPACTION_DISPATCH4, APPLICATION_SCOPE);
   }

   /* TestCase: V2DispatcherTests3S_SPEC2_19_IncludeJSPAction_dispatch4 */
   /* Details: "The parameters associated with a request dispatcher are */
   /* scoped only for the duration of the include or forward call" */
   {
      PortletURL aurl = portletResp.createActionURL();
      aurl.setParameters(portletReq.getPrivateParameterMap());
      TestButton tb = new TestButton(V2DISPATCHERTESTS3S_SPEC2_19_INCLUDEJSPACTION_DISPATCH4, aurl);
      tb.writeTo(writer);
   }

}
 
Example 13
Source File: IMSBLTIPortlet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void doEdit(RenderRequest request, RenderResponse response)
throws PortletException, IOException {

	response.setContentType("text/html");
	log.debug("==== doEdit called ====");

	PortletSession pSession = request.getPortletSession(true);

	String title = getTitleString(request);
	if ( title != null ) response.setTitle(title);

	// Debug
	String inputData = (String) pSession.getAttribute("sakai.descriptor");
	if ( inputData != null ) log.debug("descriptor.length()={}", inputData.length());
	String url = (String) pSession.getAttribute("sakai.url");
	log.debug("sakai.url={}", url);

	String view = (String) pSession.getAttribute("sakai.view");
	log.debug("sakai.view={}", view);
	if ( "edit.reset".equals(view) ) {
		sendToJSP(request, response, "/editreset.jsp");
	} else {
		prepareEdit(request);
		sendToJSP(request, response, "/edit.jsp");
	}

	clearErrorMessage(request);
	log.debug("==== doEdit called ====");
}
 
Example 14
Source File: DispatcherReqRespTests5S_SPEC2_19_ForwardJSPActionResponse.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp)
      throws PortletException, IOException {

   long tid = Thread.currentThread().getId();
   portletReq.setAttribute(THREADID_ATTR, tid);

   PrintWriter writer = portletResp.getWriter();

   PortletSession ps = portletReq.getPortletSession();
   String msg = (String) ps.getAttribute(RESULT_ATTR_PREFIX + "DispatcherReqRespTests5S_SPEC2_19_ForwardJSPActionResponse", APPLICATION_SCOPE);
   if (msg != null) {
      writer.write("<p>" + msg + "</p><br/>\n");
      ps.removeAttribute(RESULT_ATTR_PREFIX + "DispatcherReqRespTests5S_SPEC2_19_ForwardJSPActionResponse", APPLICATION_SCOPE);
   }

   /* TestCase: V2DispatcherReqRespTests5S_SPEC2_19_ForwardJSPActionResponse_sendRedirect */
   /* Details: "In a target jsp of a forward in the Action phase, the      */
   /* method HttpServletResponse.sendRedirect must provide the same        */
   /* functionality as ActionResponse.sendRedirect"                        */
   {
      PortletURL aurl = portletResp.createActionURL();
      aurl.setParameters(portletReq.getPrivateParameterMap());
      TestButton tb = new TestButton(V2DISPATCHERREQRESPTESTS5S_SPEC2_19_FORWARDJSPACTIONRESPONSE_SENDREDIRECT, aurl);
      tb.writeTo(writer);
   }

}
 
Example 15
Source File: RequestTests_ActionRequest_ApiAction.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp)
      throws PortletException, IOException {
   LOGGER.trace("main portlet render entry");

   long tid = Thread.currentThread().getId();
   portletReq.setAttribute(THREADID_ATTR, tid);

   PrintWriter writer = portletResp.getWriter();

   PortletSession ps = portletReq.getPortletSession();
   String msg = (String) ps.getAttribute(RESULT_ATTR_PREFIX + "RequestTests_ActionRequest_ApiAction", APPLICATION_SCOPE);
   if (msg != null) {
      writer.write("<p>" + msg + "</p><br/>\n");
      ps.removeAttribute(RESULT_ATTR_PREFIX + "RequestTests_ActionRequest_ApiAction", APPLICATION_SCOPE);
   }

   /* TestCase: V2RequestTests_ActionRequest_ApiAction_fieldACTION_NAME    */
   /* Details: "Has String field ACTION_NAME with value of                 */
   /* \"javax.portlet.action\" "                                           */
   {
      PortletURL aurl = portletResp.createActionURL();
      aurl.setParameters(portletReq.getPrivateParameterMap());
      TestButton tb = new TestButton(V2REQUESTTESTS_ACTIONREQUEST_APIACTION_FIELDACTION_NAME, aurl);
      tb.writeTo(writer);
   }

}
 
Example 16
Source File: EnvironmentTests_PortletRequestDispatcher_ApiRender.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public void render(RenderRequest renderReq, RenderResponse renderResp)
    throws PortletException, IOException {

  long tid = Thread.currentThread().getId();
  renderReq.setAttribute(THREADID_ATTR, tid);

  PrintWriter writer = renderResp.getWriter();

  PortletSession ps = renderReq.getPortletSession();
  String msg = (String) ps.getAttribute(
      RESULT_ATTR_PREFIX + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_forward1",
      APPLICATION_SCOPE);
  if (msg != null) {
    writer.write("<p>" + msg + "</p><br/>\n");
    ps.removeAttribute(
        RESULT_ATTR_PREFIX + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_forward1",
        APPLICATION_SCOPE);
  }

  // Create result objects for the tests

  PortletRequest portletReq = renderReq;
  PortletResponse portletResp = renderResp;

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeA1 */
  /* Details: "Method include(PortletRequest, PortletResponse): */
  /* Includes the content of a JSP page in the response" */
  String target_tr0 =
      JSP_PREFIX + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeA1" + JSP_SUFFIX
          + "?" + QUERY_STRING;
  PortletRequestDispatcher rd_tr0 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr0);
  rd_tr0.include(portletReq, portletResp);

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeA2 */
  /* Details: "Method include(PortletRequest, PortletResponse): */
  /* Includes the content of a HTML Page in the response" */
  String target_tr1 = HTML_PREFIX
      + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeA2" + HTML_SUFFIX;
  PortletRequestDispatcher rd_tr1 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr1);
  rd_tr1.include(portletReq, portletResp);

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeA3 */
  /* Details: "Method include(PortletRequest, PortletResponse): The */
  /* included servlet cannot change the status code. The attempt is */
  /* ignored" */
  String target_tr2 = SERVLET_PREFIX
      + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_PortletRequest_Include"
      + SERVLET_SUFFIX;
  PortletRequestDispatcher rd_tr2 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr2);
  rd_tr2.include(portletReq, portletResp);

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeB1 */
  /* Details: "Method include(RenderRequest, RenderResponse): Includes */
  /* the content of a JSP page in the response" */
  String target_tr3 =
      JSP_PREFIX + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeB1" + JSP_SUFFIX
          + "?" + QUERY_STRING;
  PortletRequestDispatcher rd_tr3 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr3);
  rd_tr3.include(portletReq, portletResp);

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeB2 */
  /* Details: "Method include(RenderRequest, RenderResponse): Includes */
  /* the content of a HTML Page in the response" */
  String target_tr4 = HTML_PREFIX
      + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeB2" + HTML_SUFFIX;
  PortletRequestDispatcher rd_tr4 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr4);
  rd_tr4.include(portletReq, portletResp);

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeB3 */
  /* Details: "Method include(RenderRequest, RenderResponse): The */
  /* included servlet cannot change the status code. The attempt is */
  /* ignored" */
  String target_tr5 = SERVLET_PREFIX
      + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_RenderRequest_Include"
      + SERVLET_SUFFIX;
  PortletRequestDispatcher rd_tr5 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr5);
  rd_tr5.include(portletReq, portletResp);



}
 
Example 17
Source File: FilterTests_EventFilter_ApiEventFilter_event.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public void processEvent(EventRequest portletReq, EventResponse portletResp)
    throws PortletException, IOException {

  JSR286ApiTestCaseDetails tcd = new JSR286ApiTestCaseDetails();

  portletResp.setRenderParameters(portletReq);

  long tid = Thread.currentThread().getId();
  portletReq.setAttribute(THREADID_ATTR, tid);

  StringWriter writer = new StringWriter();

  /* TestCase: V2FilterTests_EventFilter_ApiEventFilter_doFilterIsCalled */
  /* Details: "The doFilter(EventRequest, EventResponse, FilterChain): */
  /* method is called before the processEvent method for the portlet" */
  TestResult tr2 =
      tcd.getTestResultFailed(V2FILTERTESTS_EVENTFILTER_APIEVENTFILTER_DOFILTERISCALLED);
  if (FilterTests_EventFilter_ApiEventFilter_filter2.tr2_success) {
    tr2.setTcSuccess(true);
  }
  tr2.writeTo(writer);

  /* TestCase: V2FilterTests_EventFilter_ApiEventFilter_doFilterProcessEvent1 */
  /* Details: "After the doFilter(EventRequest, EventResponse, */
  /* FilterChain): method has sucessfully completed and invokes the */
  /* next filter, the processEventMethod is called" */
  TestResult tr3 =
      tcd.getTestResultFailed(V2FILTERTESTS_EVENTFILTER_APIEVENTFILTER_DOFILTERPROCESSEVENT1);
  if (FilterTests_EventFilter_ApiEventFilter_filter2.tr3_success) {
    tr3.setTcSuccess(true);
  }
  tr3.writeTo(writer);

  PortletSession ps = portletReq.getPortletSession();
  String msg =
      (String) ps.getAttribute(RESULT_ATTR_PREFIX + "FilterTests_EventFilter_ApiEventFilter",
          APPLICATION_SCOPE);
  portletReq.getPortletSession().setAttribute(
      Constants.RESULT_ATTR_PREFIX + "FilterTests_EventFilter_ApiEventFilter",
      msg + writer.toString(), APPLICATION_SCOPE);

}
 
Example 18
Source File: SakaiIFrame.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void sendAlert(RenderRequest request, Context context) {
	PortletSession pSession = request.getPortletSession(true);
	String str = (String) pSession.getAttribute(ALERT_MESSAGE);
	pSession.removeAttribute(ALERT_MESSAGE);
	if ( str != null && str.length() > 0 ) context.put("alertMessage", formattedText.escapeHtml(str, false));
}
 
Example 19
Source File: SakaiIFrame.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void sendAlert(RenderRequest request, Context context) {
	PortletSession pSession = request.getPortletSession(true);
	String str = (String) pSession.getAttribute(ALERT_MESSAGE);
	pSession.removeAttribute(ALERT_MESSAGE);
	if ( str != null && str.length() > 0 ) context.put("alertMessage", formattedText.escapeHtml(str, false));
}
 
Example 20
Source File: PortletUtils.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Check the given request for a session attribute of the given name in the given scope.
 * Returns {@code null} if there is no session or if the session has no such attribute in that scope.
 * Does not create a new session if none has existed before!
 * @param request current portlet request
 * @param name the name of the session attribute
 * @param scope session scope of this attribute
 * @return the value of the session attribute, or {@code null} if not found
 */
public static Object getSessionAttribute(PortletRequest request, String name, int scope) {
	Assert.notNull(request, "Request must not be null");
	PortletSession session = request.getPortletSession(false);
	return (session != null ? session.getAttribute(name, scope) : null);
}