List of usage examples for com.liferay.portal.kernel.util TransientValue TransientValue
public TransientValue(V value)
From source file:com.liferay.document.library.repository.cmis.internal.CMISSessionCache.java
License:Open Source License
public void put(String key, Session session) { HttpSession httpSession = PortalSessionThreadLocal.getHttpSession(); if (httpSession == null) { if (_log.isWarnEnabled()) { _log.warn("Unable to get HTTP session"); }//from w ww . j ava2 s . c om return; } httpSession.setAttribute(key, new TransientValue<>(session)); _sessions.putIfAbsent(httpSession.getId(), httpSession); }
From source file:com.liferay.document.library.repository.external.cache.ConnectionCache.java
License:Open Source License
public T getConnection() throws RepositoryException { T connection = null;//from w w w. j a v a 2 s. c o m HttpSession httpSession = PortalSessionThreadLocal.getHttpSession(); if (httpSession != null) { TransientValue<T> transientValue = (TransientValue<T>) httpSession.getAttribute(_sessionKey); if (transientValue != null) { connection = transientValue.getValue(); } } else { connection = _connectionThreadLocal.get(); } if (connection != null) { return connection; } connection = _connectionBuilder.buildConnection(); if (httpSession != null) { TransientValue<T> transientValue = new TransientValue<>(connection); httpSession.setAttribute(_sessionKey, transientValue); } _connectionThreadLocal.set(connection); return connection; }
From source file:com.liferay.google.drive.repository.GoogleDriveRepository.java
License:Open Source License
protected GoogleDriveSession getGoogleDriveSession() throws PortalException { GoogleDriveSession googleDriveSession = null; HttpSession httpSession = PortalSessionThreadLocal.getHttpSession(); if (httpSession != null) { TransientValue<GoogleDriveSession> transientValue = (TransientValue<GoogleDriveSession>) httpSession .getAttribute(GoogleDriveSession.class.getName()); if (transientValue != null) { googleDriveSession = transientValue.getValue(); }/*from ww w.j a v a 2 s . c om*/ } else { googleDriveSession = _googleDriveSessionThreadLocal.get(); } if (googleDriveSession != null) { return googleDriveSession; } try { googleDriveSession = buildGoogleDriveSession(); } catch (Exception e) { throw new PrincipalException(e); } if (httpSession != null) { httpSession.setAttribute(GoogleDriveSession.class.getName(), new TransientValue<GoogleDriveSession>(googleDriveSession)); } else { _googleDriveSessionThreadLocal.set(googleDriveSession); } return googleDriveSession; }
From source file:com.liferay.mobile.device.rules.internal.events.MDRServicePreAction.java
License:Open Source License
@Override public void run(HttpServletRequest request, HttpServletResponse response) { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Device device = null;/*from www . j ava2 s. c om*/ if (PropsValues.MOBILE_DEVICE_SESSION_CACHE_ENABLED) { HttpSession session = request.getSession(); TransientValue<Device> transientValue = (TransientValue<Device>) session.getAttribute(WebKeys.DEVICE); if (transientValue != null) { device = transientValue.getValue(); } if (device == null) { device = DeviceDetectionUtil.detectDevice(request); session.setAttribute(WebKeys.DEVICE, new TransientValue<>(device)); } } else { device = DeviceDetectionUtil.detectDevice(request); } themeDisplay.setDevice(device); UnknownDevice unknownDevice = UnknownDevice.getInstance(); if (device.equals(unknownDevice)) { return; } MDRRuleGroupInstance mdrRuleGroupInstance = null; try { mdrRuleGroupInstance = RuleGroupProcessorUtil.evaluateRuleGroups(themeDisplay); if (_log.isDebugEnabled()) { String logMessage = "Rule group evaluation returned rule group instance "; if (mdrRuleGroupInstance != null) { logMessage += mdrRuleGroupInstance.getRuleGroupInstanceId(); } else { logMessage += "null"; } _log.debug(logMessage); } } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to retrieve rule group", e); } return; } if (mdrRuleGroupInstance == null) { return; } themeDisplay.setMDRRuleGroupInstance(new MDRRuleGroupInstanceImpl(mdrRuleGroupInstance)); try { List<MDRAction> mdrActions = _mdrActionLocalService .getActions(mdrRuleGroupInstance.getRuleGroupInstanceId()); ActionHandlerManagerUtil.applyActions(mdrActions, request, response); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to apply device profile", e); } } }
From source file:com.liferay.repository.external.cache.ConnectionCache.java
License:Open Source License
public T getConnection() throws RepositoryException { T connection = null;// w w w .ja va 2s .c om HttpSession httpSession = PortalSessionThreadLocal.getHttpSession(); if (httpSession != null) { TransientValue<T> transientValue = (TransientValue<T>) httpSession.getAttribute(_sessionKey); if (transientValue != null) { connection = transientValue.getValue(); } } else { connection = _connectionThreadLocal.get(); } if (connection != null) { return connection; } connection = _connectionBuilder.buildConnection(); if (httpSession != null) { TransientValue<T> transientValue = new TransientValue<T>(connection); httpSession.setAttribute(_sessionKey, transientValue); } _connectionThreadLocal.set(connection); return connection; }
From source file:com.liferay.wsrp.consumer.portlet.ConsumerPortlet.java
License:Open Source License
protected ServiceHolder getServiceHolder(PortletRequest portletRequest, WSRPConsumerManager wsrpConsumerManager, WSRPConsumer wsrpConsumer) throws Exception { PortletSession portletSession = portletRequest.getPortletSession(); String markupServiceKey = getSessionKey(WebKeys.MARKUP_SERVICE, portletRequest, wsrpConsumer); TransientValue<ServiceHolder> serviceHolderTransientValue = (TransientValue<ServiceHolder>) portletSession .getAttribute(markupServiceKey, PortletSession.APPLICATION_SCOPE); if ((serviceHolderTransientValue == null) || serviceHolderTransientValue.isNull()) { ServiceHolder serviceHolder = new ServiceHolder(); WSRP_v2_Markup_PortType markupService = wsrpConsumerManager.getMarkupService(); serviceHolder.setMarkupService(markupService); RegistrationContext registrationContext = wsrpConsumer.getRegistrationContext(); serviceHolder.setRegistrationContext(registrationContext); serviceHolderTransientValue = new TransientValue<ServiceHolder>(serviceHolder); portletSession.setAttribute(markupServiceKey, serviceHolderTransientValue, PortletSession.APPLICATION_SCOPE); ServiceDescription serviceDescription = wsrpConsumerManager.getServiceDescription(); String cookieKey = getSessionKey(WebKeys.COOKIE, portletRequest, wsrpConsumer); String cookie = (String) portletSession.getAttribute(cookieKey, PortletSession.APPLICATION_SCOPE); CookieProtocol cookieProtocol = serviceDescription.getRequiresInitCookie(); if ((cookie == null) && (cookieProtocol != null)) { String cookieProtocolValue = cookieProtocol.getValue(); if (cookieProtocolValue.equals(CookieProtocol._perGroup) || cookieProtocolValue.equals(CookieProtocol._perUser)) { InitCookie initCookie = new InitCookie(); initCookie.setRegistrationContext(registrationContext); markupService.initCookie(initCookie); cookie = WSRPHTTPSender.getCurrentCookie(); portletSession.setAttribute(cookieKey, cookie, PortletSession.APPLICATION_SCOPE); }// www. j a v a 2 s . co m } } return serviceHolderTransientValue.getValue(); }
From source file:com.liferay.wsrp.portlet.ConsumerPortlet.java
License:Open Source License
protected WSRP_v2_Markup_PortType getMarkupService(PortletRequest portletRequest, WSRPConsumerManager wsrpConsumerManager, WSRPConsumer wsrpConsumer) throws Exception { PortletSession portletSession = portletRequest.getPortletSession(); String markupServiceKey = getSessionKey(WebKeys.MARKUP_SERVICE, portletRequest, wsrpConsumer); TransientValue<WSRP_v2_Markup_PortType> markupServiceTransientValue = (TransientValue<WSRP_v2_Markup_PortType>) portletSession .getAttribute(markupServiceKey, PortletSession.APPLICATION_SCOPE); if ((markupServiceTransientValue == null) || (markupServiceTransientValue.isNull())) { String userToken = WSRPConsumerManager.getUserToken(portletRequest); WSRP_v2_Markup_PortType markupService = wsrpConsumerManager.getMarkupService(userToken); markupServiceTransientValue = new TransientValue<WSRP_v2_Markup_PortType>(markupService); ServiceDescription serviceDescription = wsrpConsumerManager.getServiceDescription(); String cookieKey = getSessionKey(WebKeys.COOKIE, portletRequest, wsrpConsumer); String cookie = (String) portletSession.getAttribute(cookieKey, PortletSession.APPLICATION_SCOPE); CookieProtocol cookieProtocol = serviceDescription.getRequiresInitCookie(); if ((cookie == null) && (cookieProtocol != null)) { String cookieProtocolValue = cookieProtocol.getValue(); if (cookieProtocolValue.equals(CookieProtocol._perGroup) || cookieProtocolValue.equals(CookieProtocol._perUser)) { InitCookie initCookie = new InitCookie(); initCookie.setRegistrationContext(wsrpConsumer.getRegistrationContext()); markupService.initCookie(initCookie); cookie = SimpleHTTPSender.getCurrentCookie(); portletSession.setAttribute(cookieKey, cookie, PortletSession.APPLICATION_SCOPE); }/*from w w w .j av a2 s.c o m*/ } portletSession.setAttribute(markupServiceKey, markupServiceTransientValue, PortletSession.APPLICATION_SCOPE); } return markupServiceTransientValue.getValue(); }
From source file:com.liferay.wsrp.util.WSRPConsumerManagerFactory.java
License:Open Source License
private static WSRPConsumerManager _getWSRPConsumerManager(String url, RegistrationContext registrationContext, String forwardCookies, String forwardHeaders) throws Exception { HttpSession session = getSession();/* w ww.j a va2 s . c om*/ Map<String, WSRPConsumerManager> wsrpConsumerManagers = null; if (session != null) { TransientValue<Map<String, WSRPConsumerManager>> transientValue = (TransientValue<Map<String, WSRPConsumerManager>>) session .getAttribute(WebKeys.WSRP_CONSUMER_MANAGERS); if (transientValue == null) { transientValue = new TransientValue<Map<String, WSRPConsumerManager>>( new ConcurrentHashMap<String, WSRPConsumerManager>()); session.setAttribute(WebKeys.WSRP_CONSUMER_MANAGERS, transientValue); } wsrpConsumerManagers = transientValue.getValue(); } if (wsrpConsumerManagers == null) { wsrpConsumerManagers = _wsrpConsumerManagers; } WSRPConsumerManager wsrpConsumerManager = wsrpConsumerManagers.get(url); if (wsrpConsumerManager == null) { String userToken = _getUserToken(); wsrpConsumerManager = new WSRPConsumerManager(url, registrationContext, forwardCookies, forwardHeaders, userToken); wsrpConsumerManagers.put(url, wsrpConsumerManager); } return wsrpConsumerManager; }