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

The following examples show how to use javax.portlet.PortletRequest#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: DispatcherTests3S_SPEC2_19_ForwardServletResource_servlet.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected void processTCKReq(HttpServletRequest request, HttpServletResponse response) throws ServletException,
      IOException {

   PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request");
   PortletResponse portletResp = (PortletResponse) request.getAttribute("javax.portlet.response");
   request.getAttribute("javax.portlet.config");
   Thread.currentThread().getId();
   portletReq.getAttribute(THREADID_ATTR);

   PrintWriter writer = ((MimeResponse) portletResp).getWriter();

   // Create result objects for the tests

   PortletURL purl = ((MimeResponse) portletResp).createRenderURL();
   TestLink tl = new TestLink(V2DISPATCHERTESTS3S_SPEC2_19_FORWARDSERVLETRESOURCE_DISPATCH4, purl);
   tl.writeTo(writer);

}
 
Example 2
Source File: PortalUser.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String getFirstName(PortletRequest request) {
	fixPortalType(request);
	String firstName = null;
	Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);

	switch (portalType) {
		case GRIDSPHERE:
			String fullName = getGridsphereFullName(request);
			firstName = fullName.trim().substring(0, fullName.indexOf(" "));
			break;
		case PLUTO:
		case UPORTAL:
			if (userInfo != null) {
				firstName = (String) userInfo.get("user.name.given");
			}
			break;
	}
	log.debug("First Name={}", firstName);
	return firstName;
}
 
Example 3
Source File: PortalUser.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String getLastName(PortletRequest request) {
	fixPortalType(request);
	String lastName = null;
	Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);

	switch (portalType) {
		case GRIDSPHERE:
			String fullName = getGridsphereFullName(request);
			lastName = fullName.substring(fullName.trim().lastIndexOf(" ") + 1);
			break;
		case PLUTO:
		case UPORTAL:
			if (userInfo != null) { 
				lastName =  (String) userInfo.get("user.name.family");
			}
			break;
	}
	log.debug("Last Name={}", lastName);
	return lastName;
}
 
Example 4
Source File: PortalUser.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String getEmail(PortletRequest request) {
	fixPortalType(request);
	String email = null;
	Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);

	switch (portalType) {
		case GRIDSPHERE:
			if (userInfo != null) {
				email = (String) userInfo.get("user.email");
			}
			break;
		case PLUTO:
		case UPORTAL:
			if (userInfo != null) {
				email = (String) userInfo.get("user.home-info.online.email");
			}
	}

	log.debug("EMail={}", email);
	return email;
}
 
Example 5
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static String getEmail(PortletRequest request) {
	String email = null;
	Map<String,String> userInfo = (Map<String,String>) request.getAttribute(PortletRequest.USER_INFO);

	switch (lookupPortalType(request)) {
		case GRIDSPHERE:
			if (userInfo != null) {
				email = userInfo.get("user.email");
			}
			break;
		case PLUTO:
		case UPORTAL:
			if (userInfo != null) {
				email = userInfo.get("user.home-info.online.email");
			}
	}

	debugPrint(request,"EMail="+email);
	return email;
}
 
Example 6
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 7
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public static String getFirstName(PortletRequest request) {
	String firstName = null;
	Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);

	switch (lookupPortalType(request)) {
		case GRIDSPHERE:
			String fullName = getGridsphereFullName(request);
			firstName = fullName.trim().substring(0, fullName.indexOf(" "));
			break;
		case PLUTO:
		case UPORTAL:
			if (userInfo != null) {
				firstName = (String) userInfo.get("user.name.given");
			}
			break;
	}
	debugPrint(request,"First Name="+firstName);
	return firstName;
}
 
Example 8
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static String getEmail(PortletRequest request) {
	String email = null;
	Map<String,String> userInfo = (Map<String,String>) request.getAttribute(PortletRequest.USER_INFO);

	switch (lookupPortalType(request)) {
		case GRIDSPHERE:
			if (userInfo != null) {
				email = userInfo.get("user.email");
			}
			break;
		case PLUTO:
		case UPORTAL:
			if (userInfo != null) {
				email = userInfo.get("user.home-info.online.email");
			}
	}

	debugPrint(request,"EMail="+email);
	return email;
}
 
Example 9
Source File: DispatcherTests3S_SPEC2_19_IncludeServletRender_servlet.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected void processTCKReq(HttpServletRequest request, HttpServletResponse response) throws ServletException,
      IOException {

   PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request");
   request.getAttribute("javax.portlet.response");
   request.getAttribute("javax.portlet.config");
   Thread.currentThread().getId();
   portletReq.getAttribute(THREADID_ATTR);

   new JSR286DispatcherTestCaseDetails();

   // Create result objects for the tests

}
 
Example 10
Source File: DefineObjectsTag286.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method.
 * <p>
 * Sets the portlet render and request attribute with 
 * the names described in the JSR 286 - PLT 26.1 (defineObjects Tag).
 * 
 * @param request PortletRequest
 * @param response PortletResponse
 */
protected void setPortletRequestResponseAttribute(PortletRequest request, 
		PortletResponse response ){
	
	String phase = (String)request.getAttribute(PortletRequest.LIFECYCLE_PHASE);
	
  setAttribute(request, "portletRequest");
  setAttribute(response, "portletResponse");
	
	//check where request and response where included from
	if(PortletRequest.ACTION_PHASE.equals(phase)){
		setAttribute(request, "actionRequest");
		setAttribute(response, "actionResponse");
	}    	
	else if(PortletRequest.EVENT_PHASE.equals(phase)){
		setAttribute(request, "eventRequest");
		setAttribute(response, "eventResponse");
	}
	else if(PortletRequest.RENDER_PHASE.equals(phase)){
		setAttribute(request, "renderRequest");
		setAttribute(response, "renderResponse");
	}    	
	else if(PortletRequest.RESOURCE_PHASE.equals(phase)){
		setAttribute(request, "resourceRequest");
		setAttribute(response, "resourceResponse");
	}
}
 
Example 11
Source File: DispatcherTests3S_SPEC2_19_IncludeServletEvent_servlet.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected void processTCKReq(HttpServletRequest request, HttpServletResponse response) throws ServletException,
      IOException {

   PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request");
   request.getAttribute("javax.portlet.response");
   request.getAttribute("javax.portlet.config");
   Thread.currentThread().getId();
   portletReq.getAttribute(THREADID_ATTR);

   // Create result objects for the tests

}
 
Example 12
Source File: DispatcherTests3S_SPEC2_19_IncludeServletResource_servlet.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected void processTCKReq(HttpServletRequest request, HttpServletResponse response) throws ServletException,
      IOException {

   PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request");
   request.getAttribute("javax.portlet.response");
   request.getAttribute("javax.portlet.config");
   Thread.currentThread().getId();
   portletReq.getAttribute(THREADID_ATTR);

   // Create result objects for the tests

}
 
Example 13
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static String getGridsphereFullName(PortletRequest request) {
	String fullName = null;
	Map<String,String> userInfo = (Map<String,String>) request.getAttribute(PortletRequest.USER_INFO);
	if (userInfo != null) {
		fullName = userInfo.get("user.name.full");
	}
	return fullName;
}
 
Example 14
Source File: DispatcherTests4_SPEC2_19_ForwardServletAction_servlet.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
protected void processTCKReq(HttpServletRequest request, HttpServletResponse response) throws ServletException,
      IOException {

   PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request");
   request.getAttribute("javax.portlet.response");
   request.getAttribute("javax.portlet.config");
   Thread.currentThread().getId();
   portletReq.getAttribute(THREADID_ATTR);

   StringWriter writer = new StringWriter();

   JSR286DispatcherTestCaseDetails tcd = new JSR286DispatcherTestCaseDetails();

   // Create result objects for the tests

   /* TestCase: V2DispatcherTests4_SPEC2_19_ForwardServletAction_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" */
   TestResult tr0 = tcd.getTestResultFailed(V2DISPATCHERTESTS4_SPEC2_19_FORWARDSERVLETACTION_INVOKE3);
   try {
      // If this gets executed, include worked.
      tr0.setTcSuccess(true);
   } catch (Exception e) {
      tr0.appendTcDetail(e.toString());
   }
   tr0.writeTo(writer);

   request.getSession().setAttribute(
         Constants.RESULT_ATTR_PREFIX + "DispatcherTests4_SPEC2_19_ForwardServletAction", writer.toString());

}
 
Example 15
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static String getUsername(PortletRequest request) {
	String username = null;
	Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);

	switch (lookupPortalType(request)) {
		case GRIDSPHERE:
			if (userInfo != null) {
				username = (String) userInfo.get("user.name");
			}
			break;
		case ORACLEPORTAL:
			log.debug("userInfo {}", userInfo); // Changes by Venkatesh for Oracle Portal
			log.debug("Remote User={}", username); // Oracle portal is populating user name with [1] at the end
			// the following code will get rid of the unnecessary characters
			username = request.getRemoteUser();
			if(username != null && username.indexOf("[") != -1)
			{
				debugPrint(request,"Modifying user name for Oracle Portal=" + username);
				int corruptIndex = username.indexOf('[');
				username = username.substring(0,corruptIndex);
			}
			break;
		case PLUTO:  
		case UPORTAL:
			username = request.getRemoteUser();
			break;
	}
	debugPrint(request,"Remote User=" + username);
	return username;
}
 
Example 16
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static String getUsername(PortletRequest request) {
	String username = null;
	Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);

	switch (lookupPortalType(request)) {
		case GRIDSPHERE:
			if (userInfo != null) {
				username = (String) userInfo.get("user.name");
			}
			break;
		case ORACLEPORTAL:
			log.debug("userInfo {}", userInfo); // Changes by Venkatesh for Oracle Portal
			log.debug("Remote User={}", username); // Oracle portal is populating user name with [1] at the end
			// the following code will get rid of the unnecessary characters
			username = request.getRemoteUser();
			if(username != null && username.indexOf("[") != -1)
			{
				debugPrint(request,"Modifying user name for Oracle Portal=" + username);
				int corruptIndex = username.indexOf('[');
				username = username.substring(0,corruptIndex);
			}
			break;
		case PLUTO:  
		case UPORTAL:
			username = request.getRemoteUser();
			break;
	}
	debugPrint(request,"Remote User=" + username);
	return username;
}
 
Example 17
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static String getGridsphereFullName(PortletRequest request) {
	String fullName = null;
	Map<String,String> userInfo = (Map<String,String>) request.getAttribute(PortletRequest.USER_INFO);
	if (userInfo != null) {
		fullName = userInfo.get("user.name.full");
	}
	return fullName;
}
 
Example 18
Source File: SakaiOptionalPortletContainerServices.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void setupThread(PortletRequest request, boolean doLog)
{

	String placementId = (String) request
			.getAttribute("org.sakaiproject.portal.api.PortalService_placementid");
	log.debug("place from getAttribute = {}", placementId);
	if (placementId == null)
	{
		if (doLog) log.info("No Placement found");
		return; // We have nothing to work with
	}

	Session session = SessionManager.getCurrentSession();
	log.debug("Session = {}", session);
	if (session == null)
	{
		if (doLog) log.info("No Session found placementId=" + placementId);
		return; // We have nothing to work with
	}

	log.debug("UserId={} UserEID={}", session.getUserId(), session.getUserEid());

	// Check to see if there is already a placement in place
	Placement ppp = (Placement) ThreadLocalManager.get(CURRENT_PLACEMENT);
	log.debug("ThreadLocal CURRENT_PLACEMENT={}", ppp);
	if (ppp != null)
	{
		log.debug("ThreadLocal CURRENT_PLACEMENT ID={}", ppp.getId());
		if (placementId.equals(ppp.getId()))
		{
			log.debug("Thread already setup");
			return; // Placement in place
		}
	}

	// find the tool from some site (ToolConfiguration extends Placement)
	ToolConfiguration siteTool = SiteService.findTool(placementId);
	log.debug("siteTool={}", siteTool);
	if (siteTool == null)
	{
		if (doLog)
			log.info("No ToolConfiguration found, placementId=" + placementId
					+ " session=" + session);
		return;
	}

	// Actually store the placement in Thread Local
	ThreadLocalManager.set(CURRENT_PLACEMENT, siteTool);

	if (log.isDebugEnabled()) {
		// *** Testing Printout to see how well we have the APIs Configured ****
		ToolSession ts = SessionManager.getCurrentToolSession();
		log.debug("*** TEST *** \nTool Session = {}", ts);
		if ( ts != null ) {
			log.debug("ToolSession.getId={}", ts.getId());
		}

		Placement placement = ToolManager.getCurrentPlacement();
		log.debug("Placement = {}", placement);

		if ( placement != null ) {
			log.debug("Context = {}", placement.getContext());
		}
	}
}
 
Example 19
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();
   }
}
 
Example 20
Source File: SakaiOptionalPortletContainerServices.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void setupThread(PortletRequest request, boolean doLog)
{

	String placementId = (String) request
			.getAttribute("org.sakaiproject.portal.api.PortalService_placementid");
	log.debug("place from getAttribute = {}", placementId);
	if (placementId == null)
	{
		if (doLog) log.info("No Placement found");
		return; // We have nothing to work with
	}

	Session session = SessionManager.getCurrentSession();
	log.debug("Session = {}", session);
	if (session == null)
	{
		if (doLog) log.info("No Session found placementId=" + placementId);
		return; // We have nothing to work with
	}

	log.debug("UserId={} UserEID={}", session.getUserId(), session.getUserEid());

	// Check to see if there is already a placement in place
	Placement ppp = (Placement) ThreadLocalManager.get(CURRENT_PLACEMENT);
	log.debug("ThreadLocal CURRENT_PLACEMENT={}", ppp);
	if (ppp != null)
	{
		log.debug("ThreadLocal CURRENT_PLACEMENT ID={}", ppp.getId());
		if (placementId.equals(ppp.getId()))
		{
			log.debug("Thread already setup");
			return; // Placement in place
		}
	}

	// find the tool from some site (ToolConfiguration extends Placement)
	ToolConfiguration siteTool = SiteService.findTool(placementId);
	log.debug("siteTool={}", siteTool);
	if (siteTool == null)
	{
		if (doLog)
			log.info("No ToolConfiguration found, placementId=" + placementId
					+ " session=" + session);
		return;
	}

	// Actually store the placement in Thread Local
	ThreadLocalManager.set(CURRENT_PLACEMENT, siteTool);

	if (log.isDebugEnabled()) {
		// *** Testing Printout to see how well we have the APIs Configured ****
		ToolSession ts = SessionManager.getCurrentToolSession();
		log.debug("*** TEST *** \nTool Session = {}", ts);
		if ( ts != null ) {
			log.debug("ToolSession.getId={}", ts.getId());
		}

		Placement placement = ToolManager.getCurrentPlacement();
		log.debug("Placement = {}", placement);

		if ( placement != null ) {
			log.debug("Context = {}", placement.getContext());
		}
	}
}