/* (non-Javadoc)
@see org.apereo.portal.portlet.rendering.IPortletExecutionManager#getPortletTitle(org.apereo.portal.portlet.om.IPortletWindowId, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
435503
@Override
    public String getPortletTitle(
            IPortletWindowId portletWindowId,
            HttpServletRequest request,
            HttpServletResponse response) {
        final IPortletDefinition portletDefinition = getPortletDefinition(portletWindowId, request);
        final IPortletDefinitionParameter disableDynamicTitle =
                portletDefinition.getParameter("disableDynamicTitle");

        if (disableDynamicTitle == null || !Boolean.parseBoolean(disableDynamicTitle.getValue())) {
            try {
                final PortletRenderResult portletRenderResult =
                        getPortletRenderResult(portletWindowId, request, response);
                if (portletRenderResult != null) {
                    final String title = portletRenderResult.getTitle();
                    if (title != null) {
                        return title;
                    }
                }
            } catch (Exception e) {
                logger.warn(
                        "unable to get portlet title, falling back to title defined in channel definition for portletWindowId "
                                + portletWindowId);
            }
        }

        // we assume that response locale has been set to correct value
        String locale = response.getLocale().toString();

        // return portlet title from channel definition
        return portletDefinition.getTitle(locale);
    }
1028988
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
        try {
            if (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface.class.isAssignableFrom(serviceEndpointInterface)) {
                com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceSoapBindingStub _stub = new com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceSoapBindingStub(new java.net.URL(AdGroupCriterionServiceInterfacePort_address), this);
                _stub.setPortName(getAdGroupCriterionServiceInterfacePortWSDDServiceName());
                return _stub;
            }
        }
        catch (java.lang.Throwable t) {
            throw new javax.xml.rpc.ServiceException(t);
        }
        throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }
505781
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
        try {
            if (com.google.api.ads.admanager.axis.v201808.NativeStyleServiceInterface.class.isAssignableFrom(serviceEndpointInterface)) {
                com.google.api.ads.admanager.axis.v201808.NativeStyleServiceSoapBindingStub _stub = new com.google.api.ads.admanager.axis.v201808.NativeStyleServiceSoapBindingStub(new java.net.URL(NativeStyleServiceInterfacePort_address), this);
                _stub.setPortName(getNativeStyleServiceInterfacePortWSDDServiceName());
                return _stub;
            }
        }
        catch (java.lang.Throwable t) {
            throw new javax.xml.rpc.ServiceException(t);
        }
        throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }
1301581
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
        try {
            if (com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingServiceInterface.class.isAssignableFrom(serviceEndpointInterface)) {
                com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingServiceSoapBindingStub _stub = new com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingServiceSoapBindingStub(new java.net.URL(CampaignExtensionSettingServiceInterfacePort_address), this);
                _stub.setPortName(getCampaignExtensionSettingServiceInterfacePortWSDDServiceName());
                return _stub;
            }
        }
        catch (java.lang.Throwable t) {
            throw new javax.xml.rpc.ServiceException(t);
        }
        throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }
788084
@Override
    public IPortletWindow convertPortletWindow(
            HttpServletRequest request, PortletWindow plutoPortletWindow) {
        Validate.notNull(request, "request can not be null");
        Validate.notNull(plutoPortletWindow, "portletWindow can not be null");

        // Conver the pluto portlet window ID into a uPortal portlet window ID
        final PortletWindowID plutoWindowId = plutoPortletWindow.getId();
        final IPortletWindowId portletWindowId;
        if (plutoWindowId instanceof IPortletWindowId) {
            portletWindowId = (IPortletWindowId) plutoWindowId;
        } else {
            portletWindowId = this.getPortletWindowId(request, plutoWindowId.getStringId());
        }

        // Do a new get to make sure the referenced data gets updated correctly
        return this.getPortletWindow(request, portletWindowId);
    }
729425
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
        try {
            if (com.google.api.ads.adwords.axis.v201809.cm.FeedServiceInterface.class.isAssignableFrom(serviceEndpointInterface)) {
                com.google.api.ads.adwords.axis.v201809.cm.FeedServiceSoapBindingStub _stub = new com.google.api.ads.adwords.axis.v201809.cm.FeedServiceSoapBindingStub(new java.net.URL(FeedServiceInterfacePort_address), this);
                _stub.setPortName(getFeedServiceInterfacePortWSDDServiceName());
                return _stub;
            }
        }
        catch (java.lang.Throwable t) {
            throw new javax.xml.rpc.ServiceException(t);
        }
        throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }
1292493
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
        try {
            if (com.google.api.ads.admanager.axis.v201808.ReportServiceInterface.class.isAssignableFrom(serviceEndpointInterface)) {
                com.google.api.ads.admanager.axis.v201808.ReportServiceSoapBindingStub _stub = new com.google.api.ads.admanager.axis.v201808.ReportServiceSoapBindingStub(new java.net.URL(ReportServiceInterfacePort_address), this);
                _stub.setPortName(getReportServiceInterfacePortWSDDServiceName());
                return _stub;
            }
        }
        catch (java.lang.Throwable t) {
            throw new javax.xml.rpc.ServiceException(t);
        }
        throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }
780541
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
        try {
            if (com.google.api.ads.adwords.axis.v201809.cm.DraftAsyncErrorServiceInterface.class.isAssignableFrom(serviceEndpointInterface)) {
                com.google.api.ads.adwords.axis.v201809.cm.DraftAsyncErrorServiceSoapBindingStub _stub = new com.google.api.ads.adwords.axis.v201809.cm.DraftAsyncErrorServiceSoapBindingStub(new java.net.URL(DraftAsyncErrorServiceInterfacePort_address), this);
                _stub.setPortName(getDraftAsyncErrorServiceInterfacePortWSDDServiceName());
                return _stub;
            }
        }
        catch (java.lang.Throwable t) {
            throw new javax.xml.rpc.ServiceException(t);
        }
        throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }
242437
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
        try {
            if (com.google.api.ads.admanager.axis.v201808.LineItemTemplateServiceInterface.class.isAssignableFrom(serviceEndpointInterface)) {
                com.google.api.ads.admanager.axis.v201808.LineItemTemplateServiceSoapBindingStub _stub = new com.google.api.ads.admanager.axis.v201808.LineItemTemplateServiceSoapBindingStub(new java.net.URL(LineItemTemplateServiceInterfacePort_address), this);
                _stub.setPortName(getLineItemTemplateServiceInterfacePortWSDDServiceName());
                return _stub;
            }
        }
        catch (java.lang.Throwable t) {
            throw new javax.xml.rpc.ServiceException(t);
        }
        throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }
47236
@Override
    public String getPortletHeadOutput(
            IPortletWindowId portletWindowId,
            HttpServletRequest request,
            HttpServletResponse response) {
        if (doesPortletNeedHeaderWorker(portletWindowId, request)) {
            final IPortletRenderExecutionWorker tracker =
                    getRenderedPortletHeaderWorker(portletWindowId, request, response);
            final long timeout = getPortletRenderTimeout(portletWindowId, request);
            try {
                final String output = tracker.getOutput(timeout);
                return output == null ? "" : output;
            } catch (Exception e) {
                logger.error("failed to render header output for " + portletWindowId, e);
                return "";
            }
        }

        logger.debug(portletWindowId + " does not produce output for header");
        return "";
    }
881880
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
        try {
            if (com.google.api.ads.adwords.axis.v201809.cm.OfflineCallConversionFeedServiceInterface.class.isAssignableFrom(serviceEndpointInterface)) {
                com.google.api.ads.adwords.axis.v201809.cm.OfflineCallConversionFeedServiceSoapBindingStub _stub = new com.google.api.ads.adwords.axis.v201809.cm.OfflineCallConversionFeedServiceSoapBindingStub(new java.net.URL(OfflineCallConversionFeedServiceInterfacePort_address), this);
                _stub.setPortName(getOfflineCallConversionFeedServiceInterfacePortWSDDServiceName());
                return _stub;
            }
        }
        catch (java.lang.Throwable t) {
            throw new javax.xml.rpc.ServiceException(t);
        }
        throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }
378628
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
        try {
            if (com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedServiceInterface.class.isAssignableFrom(serviceEndpointInterface)) {
                com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedServiceSoapBindingStub _stub = new com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedServiceSoapBindingStub(new java.net.URL(OfflineConversionAdjustmentFeedServiceInterfacePort_address), this);
                _stub.setPortName(getOfflineConversionAdjustmentFeedServiceInterfacePortWSDDServiceName());
                return _stub;
            }
        }
        catch (java.lang.Throwable t) {
            throw new javax.xml.rpc.ServiceException(t);
        }
        throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }
731549
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
        try {
            if (com.google.api.ads.adwords.axis.v201809.cm.CampaignBidModifierServiceInterface.class.isAssignableFrom(serviceEndpointInterface)) {
                com.google.api.ads.adwords.axis.v201809.cm.CampaignBidModifierServiceSoapBindingStub _stub = new com.google.api.ads.adwords.axis.v201809.cm.CampaignBidModifierServiceSoapBindingStub(new java.net.URL(CampaignBidModifierServiceInterfacePort_address), this);
                _stub.setPortName(getCampaignBidModifierServiceInterfacePortWSDDServiceName());
                return _stub;
            }
        }
        catch (java.lang.Throwable t) {
            throw new javax.xml.rpc.ServiceException(t);
        }
        throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }
321406
@Override
    public PortletWindowIdImpl getPortletWindowId(
            HttpServletRequest request, String portletWindowId) {
        Validate.notNull(portletWindowId, "portletWindowId can not be null");

        final String entityIdStr = PortletWindowIdStringUtils.parsePortletEntityId(portletWindowId);
        final String instanceId;
        if (!PortletEntityIdStringUtils.hasCorrectNumberOfParts(entityIdStr)
                || !PortletWindowIdStringUtils.hasCorrectNumberOfParts(portletWindowId)) {
            throw new IllegalArgumentException(
                    "Provided portlet window ID '" + portletWindowId + "' is not valid");
        }

        if (PortletWindowIdStringUtils.hasPortletWindowInstanceId(portletWindowId)) {
            instanceId = PortletWindowIdStringUtils.parsePortletWindowInstanceId(portletWindowId);
        } else {
            instanceId = null;
        }

        final IPortletEntity portletEntity =
                this.portletEntityRegistry.getPortletEntity(request, entityIdStr);
        if (portletEntity == null) {
            throw new IllegalArgumentException(
                    "No parent IPortletEntity found for id '"
                            + entityIdStr
                            + "' from portlet window id: "
                            + portletWindowId);
        }

        return createPortletWindowId(instanceId, portletEntity.getPortletEntityId());
    }
716834
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
        try {
            if (com.google.api.ads.admanager.axis.v201811.ReconciliationOrderReportServiceInterface.class.isAssignableFrom(serviceEndpointInterface)) {
                com.google.api.ads.admanager.axis.v201811.ReconciliationOrderReportServiceSoapBindingStub _stub = new com.google.api.ads.admanager.axis.v201811.ReconciliationOrderReportServiceSoapBindingStub(new java.net.URL(ReconciliationOrderReportServiceInterfacePort_address), this);
                _stub.setPortName(getReconciliationOrderReportServiceInterfacePortWSDDServiceName());
                return _stub;
            }
        }
        catch (java.lang.Throwable t) {
            throw new javax.xml.rpc.ServiceException(t);
        }
        throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }
150538
@RequestMapping(value = "/v4-3/portlet/{fname}.html", method = RequestMethod.GET)
    public @ResponseBody String getRenderedPortlet(
            HttpServletRequest req, HttpServletResponse res, @PathVariable String fname) {

        // Does the portlet exist in the registry?
        final IPortletDefinition portletDef =
                portletDefinitionRegistry.getPortletDefinitionByFname(fname);
        if (portletDef == null) {
            res.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return "Portlet not found";
        }

        // Is the user permitted to access it?
        final IAuthorizationPrincipal ap = getAuthorizationPrincipal(req);
        if (!ap.canRender(portletDef.getPortletDefinitionId().getStringId())) {
            res.setStatus(HttpServletResponse.SC_FORBIDDEN);
            return "Access denied";
        }

        // Proceed...
        try {

            final PortalHttpServletFactoryService.RequestAndResponseWrapper wrapper =
                    servletFactoryService.createRequestAndResponseWrapper(req, res);

            final IPortletWindow portletWindow =
                    portletWindowRegistry.getOrCreateDefaultPortletWindow(
                            wrapper.getRequest(), portletDef.getPortletDefinitionId());
            final String rslt =
                    portletExecutionManager.getPortletOutput(
                            portletWindow.getPortletWindowId(),
                            wrapper.getRequest(),
                            wrapper.getResponse());
            return rslt;
        } catch (Exception e) {
            logger.error("Failed to render the requested portlet '{}'", fname, e);
            res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return "Internal error";
        }
    }
1302004
protected IPortletEntity getPortletEntity(
            HttpServletRequest request,
            PortletEntityCache<IPortletEntity> portletEntityCache,
            IPortletEntityId portletEntityId,
            String layoutNodeId,
            int userId) {

        IPortletEntity portletEntity;

        // First look in the request map
        if (portletEntityId != null) {
            portletEntity = portletEntityCache.getEntity(portletEntityId);
        } else {
            portletEntity = portletEntityCache.getEntity(layoutNodeId, userId);
        }

        if (portletEntity != null) {
            logger.trace(
                    "Found IPortletEntity {} in request cache", portletEntity.getPortletEntityId());
            return portletEntity;
        }

        // Didn't find it, next look in the session map
        final PortletEntityCache<PortletEntityData> portletEntityDataMap =
                this.getPortletEntityDataMap(request);
        final PortletEntityData portletEntityData;
        if (portletEntityId != null) {
            portletEntityData = portletEntityDataMap.getEntity(portletEntityId);
        } else {
            portletEntityData = portletEntityDataMap.getEntity(layoutNodeId, userId);
        }

        if (portletEntityData != null) {

            // Stick the entity wrapper in the request map (if it wasn't already added by another
            // thread)
            portletEntity =
                    portletEntityCache.storeIfAbsentEntity(
                            portletEntityData.getPortletEntityId(),
                            new Function<IPortletEntityId, IPortletEntity>() {
                                @Override
                                public IPortletEntity apply(IPortletEntityId input) {
                                    // Found a session stored entity, wrap it to make it a real
                                    // IPortletEntity
                                    logger.trace(
                                            "Found PortletEntityData {} in session cache, caching wrapper in the request",
                                            portletEntityData.getPortletEntityId());

                                    return wrapPortletEntityData(portletEntityData);
                                }
                            });

            return portletEntity;
        }

        // Still didn't find it, look in the persistent store
        if (portletEntityId != null) {
            if (portletEntityId instanceof PortletEntityIdImpl) {
                final PortletEntityIdImpl consistentPortletEntityId =
                        (PortletEntityIdImpl) portletEntityId;
                final String localLayoutNodeId = consistentPortletEntityId.getLayoutNodeId();
                final int localUserId = consistentPortletEntityId.getUserId();

                portletEntity =
                        this.portletEntityDao.getPortletEntity(localLayoutNodeId, localUserId);
            } else {
                portletEntity = this.portletEntityDao.getPortletEntity(portletEntityId);
            }
        } else {
            portletEntity = this.portletEntityDao.getPortletEntity(layoutNodeId, userId);
        }

        // Found a persistent entity, wrap it to make the id consistent between the persistent and
        // session stored entities
        if (portletEntity != null) {
            final IPortletEntityId consistentPortletEntityId =
                    this.createConsistentPortletEntityId(portletEntity);

            final IPortletEntity anonPortletEntity = portletEntity;

            // Stick the entity wrapper in the request map (if it wasn't already added by another
            // thread)
            portletEntity =
                    portletEntityCache.storeIfAbsentEntity(
                            consistentPortletEntityId,
                            new Function<IPortletEntityId, IPortletEntity>() {
                                @Override
                                public IPortletEntity apply(IPortletEntityId input) {
                                    logger.trace(
                                            "Found persistent IPortletEntity {}, mapped id to {}, caching the wrapper in the request",
                                            anonPortletEntity.getPortletEntityId(),
                                            consistentPortletEntityId);
                                    return new PersistentPortletEntityWrapper(
                                            anonPortletEntity, consistentPortletEntityId);
                                }
                            });

            return portletEntity;
        }

        // Didn't find an entity, just return null
        return null;
    }