Skip to content

Commit

Permalink
SAK-42496 JSF STATE_SAVING_METHOD logic added to ToolListener (sakaip…
Browse files Browse the repository at this point in the history
  • Loading branch information
ern authored and Miguel Pellicer committed Sep 16, 2019
1 parent 01ae8ff commit 13fc654
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1420,9 +1420,9 @@
# By default Sakai is using "client" as SAVING_STATE_METHOD in JSF tools
# You can change this value to "server" in all jsf tools with default or in selected ones
# jsf.state_saving_method=server
# jsf.state_saving_method.{servlet-name}=server
# Example: jsf.state_saving_method.sakai.samigo=server
# Example: jsf.state_saving_method.sakai.summary.calendar=server
# jsf.state_saving_method.{servlet-context-name}=server
# Example: jsf.state_saving_method.SAM=server
# Example: jsf.state_saving_method.sakai-chat-tool=server


# ########################################################################
Expand Down
12 changes: 1 addition & 11 deletions jsf/jsf-tool/src/java/org/sakaiproject/jsf/util/JsfTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,6 @@ public String getServletInfo()
public void init(ServletConfig config) throws ServletException
{
super.init(config);
ServerConfigurationService scs = ComponentManager.get(ServerConfigurationService.class);
ServletContext context = config.getServletContext();
String customJsfState = scs.getString("jsf.state_saving_method."+config.getServletName(), null);
String defaultJsfState = scs.getString("jsf.state_saving_method", "client");
if (customJsfState != null) {
context.setInitParameter("javax.faces.STATE_SAVING_METHOD", customJsfState);
} else if (defaultJsfState != null) {
context.setInitParameter("javax.faces.STATE_SAVING_METHOD", defaultJsfState);
}
m_default = config.getInitParameter("default");
m_path = config.getInitParameter("path");
m_defaultToLastView = "true".equals(config.getInitParameter("default.last.view"));
Expand All @@ -296,8 +287,7 @@ public void init(ServletConfig config) throws ServletException
{
m_path = m_path.substring(0, m_path.length() - 1);
}

log.info("init: "+config.getServletName()+"["+context.getInitParameter("javax.faces.STATE_SAVING_METHOD")+"]"+" default: " + m_default + " path: " + m_path);
log.info("Servlet {} configured with default: {} path: {}", config.getServletName(), m_default, m_path);
}

/**
Expand Down
12 changes: 1 addition & 11 deletions jsf2/jsf2-tool/src/java/org/sakaiproject/jsf2/util/JsfTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,6 @@ public String getServletInfo()
public void init(ServletConfig config) throws ServletException
{
super.init(config);
ServerConfigurationService scs = ComponentManager.get(ServerConfigurationService.class);
ServletContext context = config.getServletContext();
String customJsfState = scs.getString("jsf.state_saving_method."+config.getServletName(), null);
String defaultJsfState = scs.getString("jsf.state_saving_method", "client");
if (customJsfState != null) {
context.setInitParameter("javax.faces.STATE_SAVING_METHOD", customJsfState);
} else if (defaultJsfState != null) {
context.setInitParameter("javax.faces.STATE_SAVING_METHOD", defaultJsfState);
}
m_default = config.getInitParameter("default");
m_path = config.getInitParameter("path");
m_defaultToLastView = "true".equals(config.getInitParameter("default.last.view"));
Expand All @@ -288,8 +279,7 @@ public void init(ServletConfig config) throws ServletException
{
m_path = m_path.substring(0, m_path.length() - 1);
}

log.info("init: "+config.getServletName()+"["+context.getInitParameter("javax.faces.STATE_SAVING_METHOD")+"]"+" default: " + m_default + " path: " + m_path);
log.info("Servlet {} configured with default: {} path: {}", config.getServletName(), m_default, m_path);
}

/**
Expand Down
19 changes: 17 additions & 2 deletions kernel/api/src/main/java/org/sakaiproject/util/ToolListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.tool.api.ActiveToolManager;
Expand Down Expand Up @@ -85,8 +86,7 @@ public class ToolListener implements ServletContextListener

public ToolListener()
{
activeToolManager = ComponentManager.get(ActiveToolManager.class);
serverConfigurationService = ComponentManager.get(ServerConfigurationService.class);
this(ComponentManager.get(ActiveToolManager.class), ComponentManager.get(ServerConfigurationService.class));
}

public ToolListener(ActiveToolManager activeToolManager, ServerConfigurationService serverConfigurationService)
Expand All @@ -103,6 +103,7 @@ public void contextInitialized(ServletContextEvent event)
final String sakaiHomePath = serverConfigurationService.getSakaiHomePath();
// The the location of resource and registration files.
ServletContext context = event.getServletContext();
String contextName = context.getServletContextName();
Set<String> paths = getToolsPaths(context);
if (paths == null) return;
int registered = 0;
Expand Down Expand Up @@ -154,6 +155,20 @@ public void contextInitialized(ServletContextEvent event)
log.info("Added localization " + tn + "resources for " + tid);
}
}

// only set context param javax.faces.STATE_SAVING_METHOD if it's not already configured in the web.xml,
// always respecting when its declared in the web.xml
if (StringUtils.isBlank(context.getInitParameter("javax.faces.STATE_SAVING_METHOD"))) {
String defaultStateSavingMethod = serverConfigurationService.getString("jsf.state_saving_method", "client");
String stateSavingMethod = serverConfigurationService.getString("jsf.state_saving_method." + contextName, defaultStateSavingMethod);
try {
context.setInitParameter("javax.faces.STATE_SAVING_METHOD", stateSavingMethod);
log.debug("Adding context param [javax.faces.STATE_SAVING_METHOD => {}] for context {}", stateSavingMethod, contextName);
} catch (UnsupportedOperationException uoe) {
// Tomcat does not permit this if you don't declare the listener, aka spring web apps as they use ServletContextInitializer
log.debug("Could not add context param [javax.faces.STATE_SAVING_METHOD] for context {}, {}", context, uoe.getMessage());
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,25 +284,18 @@ realm.allowed..auth=annc.all.groups,annc.read,asn.read,asn.receive.notifications
[email protected]=sakai.gradebook.tool

# These tools need to use server saving method as they are on older JSF versions. If upgraded to JSf 1.2+ please remove from this list

# Chat Tool
jsf.state_saving_method.sakai.chat=server
jsf.state_saving_method.sakai.synoptic.chat=server
jsf.state_saving_method.sakai.chat.deleteMessage=server
jsf.state_saving_method.sakai-chat-tool=server
# Podcasts Tool
jsf.state_saving_method.sakai.podcasts=server
jsf.state_saving_method.sakai-podcasts=server
# User Preferences
jsf.state_saving_method.sakai.preferences=server
jsf.state_saving_method.sakai.privacy=server
jsf.state_saving_method.sakai-user-tool-prefs=server
# Help Tool
jsf.state_saving_method.sakai.help=server
jsf.state_saving_method.sakai-help=server
# Forums
jsf.state_saving_method.sakai.forums=server
jsf.state_saving_method.sakai.messageforums.helper=server
jsf.state_saving_method.sakai.messages=server
jsf.state_saving_method.sakai.synoptic.messagecenter=server
jsf.state_saving_method.messageforums=server
# Scheduler
jsf.state_saving_method.sakai.scheduler=server
jsf.state_saving_method.sakai-scheduler=server

# browser default features
browser.feature.allow.count=5
Expand Down

0 comments on commit 13fc654

Please sign in to comment.