WebSphere Portal URL types, setting base URL, Generating Relative and Friendly URL's


Different URL Formats In General
  1. Absolute URL
A complete URL containing the protocol, hostname, port, and path. For example: http://hostname.example.com:10039/wps/portal

  1. Server-relative URL
A URL that does not contain the protocol, hostname, and port, but does contain the full path part of the URL, starting with a slash. For example: "/wps/portal" .

  1. Relative URL
A URL that must be combined with a base URL in order to create a full URL. Relative to current request url.
For example browser url is http://host:port/wps/portal/firstpage generated markup that contains  <a href="testpage"/>testpage</a> then click "testpage" will try to open" http://host:port/wps/portal/testpage ".


Generating Relative and Friendly Portal URL's
Instead of encoding the complete navigational state into every URL on a page, WebSphere Portal provides ways for you to encode only the difference (delta) of the state that is represented by the URL with respect to the state of the request that generated the markup. The state of the current request is represented (in the HTML case) by the HTML <base/> tag in the head area of the HTML response. Overall, relative URLs are preferable because they are smaller and require less server resources to generate, giving better performance.

There are two ways to control the generation of relative URLs as opposed to server-relative URLs. 

1. Global (affects all URLs generated by WebSphere Portal)
2. AllowRelativeURL attribute on the <portal-navigation:urlGeneration/> tag, which overrides the global setting.

Approach 1 (Global):
1. Add/Update the following in statemanager service , "com.ibm.portal.state.accessors.url.URLContext.enableRelative"  with true/false for relative urls .

Approach 2 (Per URL based):
  1. Setting Base URL at theme level :

Execute the following using xmlaccess

<?xml version="1.0" encoding="UTF-8"?>
<request build="wpnext_372_01" type="update" version="7.0.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PortalConfig_7.0.0.xsd">
     <portal action="locate">
          <theme action="update" uniquename="siva.custom.theme">
               <parameter name="com.ibm.portal.theme.hasBaseURL" type="string" update="set">true</parameter>
          </theme>
     </portal>
</request>

After successfull execution, it adds additional parameter to theme as below
<parameter name="com.ibm.portal.theme.hasBaseURL" type="string" update="set"><![CDATA[true]]></parameter>

  1. Add StatBase tag to theme
Add the following in the theme <head> markup
<portal-core:stateBase/>

Stores a base URL which will be used while resolving relative URL's, i.e it will generate the <base href=""> tag on the page like below. This enables shorter URLs and can improve the page serving performance


  1. When allowRelativeURL is true
While Generating the URL if you set the  allowrelativeURL to true , then generated url will be like 

<portal-navigation:urlGeneration allowRelativeURL="true" contentNode="com.sivavaka.test.pages.page1">
         <a href="<%wpsURL.write(escapeXmlWriter);%>">testlink</a>
</portal-navigation:urlGeneration>

output markup will be like below

  1. When allowRelativeURL is false
While Generating the URL if you set the allowRelativeURL to false , then generated url will be like below
<portal-navigation:urlGeneration allowRelativeURL="false" contentNode="com.sivavaka.test.pages.page1">
         <a href="<%wpsURL.write(escapeXmlWriter);%>">testlink</a>
</portal-navigation:urlGeneration>

output markup will be like below

<a href="/wps/myportal/Home/SivaTestPages/Page1/!ut/p/b1/pZDbCsIwDIafxRdYsqVdu8uidqvnI2pvZIqM4jZvRF_f6pWITsHw3yR8XyABC5uQSZ74kIQ12Dq_uCI_u1Odl_fextsIxz5DsTSYaTRaJj3D5n7EPbB5BlTaRzRhe06LDpHqxn_67D_fhL_57VRlTAwQ5SDlaFS2nCVTIlT0ze-BdbsquO6rAAMuSCIJRmHEUUQEK7CNC5C_Am8e2AywL8D9BQ-g6cYHgB9KIYyyU3WAypZaa3l0xk0K1WrdAEvr7Kw!/dl4/d5/L2dJQSEvUUt3QS80SmtFL1o2XzIwTzIwT003VUE3OTkwQU9NNFFVMDEwUzk2/">testlink</a>

  1. When KeepNavigationState is set
Regard less of the allowRelativeURL="true/false" , if you set the KeepNavigationState="false" , it will remove all navigation state and generate url like below
<portal-navigation:urlGeneration keepNavigationalState="false" contentNode="test.pages.page1">
         <a href="<%wpsURL.write(escapeXmlWriter);%>">testlink</a>
</portal-navigation:urlGeneration>

output markup will be like below
<a href="/wps/myportal/Home/TestPages/Page1">Testlink</a>

NOTE: 
1. If you don't enable the "hasBaseURL" at theme level, <portal-core:stateBase/> doesn't generate the <base href=""> tag causing the url looks like below even if you set the keepRelativeURL="true" i.e. it is equivalent to "allowRelativeURL=false" 

<a href="/wps/myportal/Home/TestPages/page1/!ut/p/b1/pZDbCsIwDIafxRdYsqVdu8uidqvnI2pvZIqM4jZvRF_f6pWITsHw3yR8XyABC5uQSZ74kIQ12Dq_uCI_u1Odl_fextsIxz5DsTSYaTRaJj3D5n7EPbB5BlTaRzRhe06LDpHqxn_67D_fhL_57VRlTAwQ5SDlaFS2nCVTIlT0ze-BdbsquO6rAAMuSCIJRmHEUUQEK7CNC5C_Am8e2AywL8D9BQ-g6cYHgB9KIYyyU3WAypZaa3l0xk0K1WrdAEvr7Kw!/dl4/d5/L2dJQSEvUUt3QS80SmtFL1o2XzIwTzIwT003VUE3OTkwQU9NNFFVMDEwUzk2/" >testlink</a>

References

No comments:

Post a Comment