Sample code for geting different url in liferay.

Liferay developers often need to find different from render/servlet request.

Here below i share some code to get different url in liferay

Sample code:

        HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(request);
        String currentCompleteUrl = PortalUtil.getCurrentCompleteURL(servletRequest);

        try {
           
            String renderCurrentURL =    PortalUtil.getCurrentURL(request);
            String servletRequestCurrentURL = PortalUtil.getCurrentURL(servletRequest);
            String canonicalURL    = PortalUtil.getCanonicalURL(currentCompleteUrl, themeDisplay, themeDisplay.getLayout());
            String homeURL = PortalUtil.getHomeURL(servletRequest);
            String currentPageURL = PortalUtil.getPortalURL(themeDisplay)+themeDisplay.getLayout().getFriendlyURL();
            String portalUrl =    PortalUtil.getPortalURL(request);
            String servletRequestPortalUrl = PortalUtil.getPortalURL(servletRequest);
            String themedisplayPortalUrl  = PortalUtil.getPortalURL(themeDisplay);
            String themedisplaylayoutPortalUrl = PortalUtil.getPortalURL(themeDisplay.getLayout(), themeDisplay);
            String portalWebDir =    PortalUtil.getPortalWebDir();
            String portalLibDir = PortalUtil.getPortalLibDir();
           
            log.info("currentCompleteUrl: "+currentCompleteUrl);
            log.info("renderCurrentURL: "+renderCurrentURL);
            log.info("servletRequestCurrentURL: "+servletRequestCurrentURL);
            log.info("canonicalURL: "+canonicalURL);
            log.info("homeURL: "+homeURL);
            log.info("currentPageURL: "+currentPageURL);
            log.info("portalUrl: "+portalUrl);
            log.info("servletRequestPortalUrl: "+servletRequestPortalUrl);
            log.info("themedisplayPortalUrl: "+themedisplayPortalUrl);
            log.info("themedisplaylayoutPortalUrl: "+themedisplaylayoutPortalUrl);
            log.info("portalWebDir: "+portalWebDir);
            log.info("portalLibDir: "+portalLibDir);
           
        } catch (Exception e) {
            e.printStackTrace();
        }




Sample output:

 currentCompleteUrl: http://localhost:7070/organization?selectedCard=Organization&cardViewState=Listview
 renderCurrentURL: /organization?selectedCard=Organization&cardViewState=Listview
 servletRequestCurrentURL: /organization?selectedCard=Organization&cardViewState=Listview
 canonicalURL: http://localhost:7070/organization?selectedCard=Organization&cardViewState=Listview
 homeURL: http://localhost:7070/web/guest
 currentPageURL: http://localhost:7070/organization
 portalUrl: http://localhost:7070
 servletRequestPortalUrl: http://localhost:7070
 themedisplayPortalUrl: http://localhost:7070
 themedisplaylayoutPortalUrl: http://localhost:7070
 portalWebDir: /home/tariq/projects/projects/coorg/bundles/tomcat-7.0.42/webapps/ROOT/
 portalLibDir: /home/tariq/projects/projects/coorg/bundles/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/

Enjoy..

Comments

Popular posts from this blog

How to find the companyId in Liferay.

How to add portlet in liferay theme.

How to create soap client for ofbiz service or ofbiz service invocation from another application.