Here the sample code to get LogOut url from Portlet/Servlet.
Import the following classes
import com.ibm.portal.state.Constants;
import com.ibm.portal.state.StateManager;
import com.ibm.portal.state.accessors.StateAccessor;
import com.ibm.portal.state.accessors.StateAccessorFactory;
import com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorController;
import com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorFactory;
import com.ibm.portal.state.accessors.exceptions.StateNotInRequestException;
import com.ibm.portal.state.accessors.url.URLContext;
import com.ibm.wps.state.accessors.url.EngineUrlEx;
import com.ibm.wps.state.accessors.url.URLAccessorFactoryEx;
import com.ibm.wps.state.accessors.url.URLContextConstants;
import com.ibm.wps.state.utils.StateHelper;
Called below method from Portlet
private void getLogOuturl( HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse){
try{
EngineUrlEx engineurlex;
StateManager statemanager = StateHelper.getStateManager();
StateAccessorFactory stateaccessorfactory = (StateAccessorFactory)statemanager.getAccessorFactory(com.ibm.portal.state.accessors.StateAccessorFactory.class);
StateAccessor stateaccessor = stateaccessorfactory.getStateAccessor();
Object obj = null;
try
{
obj = stateaccessor.getStateHolder(httpservletrequest);
}
catch(StateNotInRequestException statenotinrequestexception)
{
obj = statemanager.newState();
}
stateaccessor.dispose();
URLAccessorFactoryEx urlaccessorfactoryex = (URLAccessorFactoryEx)statemanager.getAccessorFactory(com.ibm.wps.state.accessors.url.URLAccessorFactoryEx.class);
engineurlex = urlaccessorfactoryex.newURL(httpservletrequest, httpservletresponse, ((com.ibm.portal.state.StateHolder) (obj)), getURLContext(null), Constants.EMPTY_COPY);
LogoutActionAccessorFactory logoutactionaccessorfactory = (LogoutActionAccessorFactory)statemanager.getAccessorFactory(com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorFactory.class);
LogoutActionAccessorController logoutactionaccessorcontroller = logoutactionaccessorfactory.newLogoutActionController(httpservletrequest, engineurlex.getState());
logoutactionaccessorcontroller.dispose();
System.out.println(engineurlex.toString());
String LogOuturl = engineurlex.toString();
}catch (Exception e) {
e.printStackTrace();
}
}
private URLContext getURLContext(URLContext urlcontext)
{
return URLContextConstants.FORCE_ABSOLUTE_URLS;
}
Tuesday, November 3, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment