Example usage for com.liferay.portal.kernel.util TransientValue isNull

List of usage examples for com.liferay.portal.kernel.util TransientValue isNull

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util TransientValue isNull.

Prototype

public boolean isNull() 

Source Link

Usage

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. j a va 2  s  . com
        }
    }

    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  ww.j  a  v a  2s.co m*/
        }

        portletSession.setAttribute(markupServiceKey, markupServiceTransientValue,
                PortletSession.APPLICATION_SCOPE);
    }

    return markupServiceTransientValue.getValue();
}