List of usage examples for com.liferay.portal.kernel.util TransientValue getValue
public V getValue()
From source file:com.liferay.document.library.repository.cmis.internal.CMISSessionCache.java
License:Open Source License
public Session get(String key) { HttpSession httpSession = PortalSessionThreadLocal.getHttpSession(); if (httpSession == null) { return null; }// w w w . j a v a 2 s. co m TransientValue<Session> transientValue = (TransientValue<Session>) httpSession.getAttribute(key); if (transientValue == null) { return null; } Object value = transientValue.getValue(); if (value instanceof Session) { return (Session) value; } httpSession.removeAttribute(key); return null; }
From source file:com.liferay.document.library.repository.external.cache.ConnectionCache.java
License:Open Source License
public T getConnection() throws RepositoryException { T connection = null;/* w w w .jav a 2 s . com*/ 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.exportimport.lifecycle.DefaultEventAwareExportImportLifecycleListener.java
License:Open Source License
protected StagedModel getStagedModelAttribute(List<Serializable> attributes) { TransientValue<Object> transientValue = getAttributeByType(attributes, TransientValue.class); Object value = transientValue.getValue(); if (value instanceof StagedModel) { return (StagedModel) value; }//ww w . ja v a 2s. c om return null; }
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(); }// ww w .j a v a 2s . co m } 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 ww w .java 2 s. co m*/ 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;//from w w w .j av a2 s. co 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<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); }/*from w w w . ja v a 2s .c o 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); }// ww w . j av a 2 s .c om } portletSession.setAttribute(markupServiceKey, markupServiceTransientValue, PortletSession.APPLICATION_SCOPE); } return markupServiceTransientValue.getValue(); }
From source file:com.liferay.wsrp.servlet.WSRPSessionListener.java
License:Open Source License
@Override public void sessionDestroyed(HttpSessionEvent httpSessionEvent) { HttpSession session = httpSessionEvent.getSession(); Enumeration<String> enu = session.getAttributeNames(); while (enu.hasMoreElements()) { String name = enu.nextElement(); Object value = session.getAttribute(name); if (value instanceof TransientValue) { TransientValue<?> transientValue = ((TransientValue<?>) value); releaseSessions(transientValue.getValue()); }//from w w w. java 2 s . c o m } }
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();/*from w ww. j a v a 2 s .co m*/ 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; }