diff --git a/applications/ecommerce/webapp/ecommerce/login.ftl b/applications/ecommerce/webapp/ecommerce/login.ftl index dfcc14625e..385c4d049e 100644 --- a/applications/ecommerce/webapp/ecommerce/login.ftl +++ b/applications/ecommerce/webapp/ecommerce/login.ftl @@ -34,7 +34,7 @@ under the License.
${uiLabelMap.CommonRegistered}
-
+
${uiLabelMap.CommonUsername}:  @@ -60,7 +60,7 @@ under the License.
${uiLabelMap.CommonForgotYourPassword}?
- + ${uiLabelMap.CommonUsername}: 
 
@@ -74,7 +74,7 @@ under the License.
${uiLabelMap.CommonNewUser}
-
+
${uiLabelMap.CommonMayCreateNewAccountHere}:
diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java index bcfdcec54a..ea22b85393 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java @@ -465,7 +465,7 @@ public class ShoppingCartEvents { partyId = userLogin.getString("partyId"); } String formAction = "/additemsurvey"; - String nextPage = RequestHandler.getNextPageUri(request.getPathInfo()); + String nextPage = RequestHandler.getOverrideViewUri(request.getPathInfo()); if (nextPage != null) { formAction = formAction + "/" + nextPage; } diff --git a/framework/base/src/org/ofbiz/base/util/UtilHttp.java b/framework/base/src/org/ofbiz/base/util/UtilHttp.java index 60d3fc5b50..7abda2d43f 100644 --- a/framework/base/src/org/ofbiz/base/util/UtilHttp.java +++ b/framework/base/src/org/ofbiz/base/util/UtilHttp.java @@ -37,7 +37,6 @@ import java.util.Currency; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -97,22 +96,29 @@ public class UtilHttp { * @return The resulting Map */ public static Map getParameterMap(HttpServletRequest request) { - return getParameterMap(request, null); + return getParameterMap(request, null, null); + } + + public static Map getParameterMap(HttpServletRequest request, Set nameSet) { + return getParameterMap(request, nameSet, null); } /** * Create a map from a HttpServletRequest (parameters) object + * @param onlyIncludeOrSkip If true only include, if false skip, the named parameters in the nameSet. If this is null and nameSet is not null, default to skip. * @return The resulting Map */ - public static Map getParameterMap(HttpServletRequest request, Set namesToSkip) { + public static Map getParameterMap(HttpServletRequest request, Set nameSet, Boolean onlyIncludeOrSkip) { + boolean onlyIncludeOrSkipPrim = onlyIncludeOrSkip == null ? true : onlyIncludeOrSkip.booleanValue(); Map paramMap = FastMap.newInstance(); // add all the actual HTTP request parameters - Enumeration e = request.getParameterNames(); + Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); - if (namesToSkip != null && namesToSkip.contains(name)) + if (nameSet != null && (onlyIncludeOrSkipPrim ^ nameSet.contains(name))) { continue; + } Object value = null; String[] paramArr = request.getParameterValues(name); @@ -126,7 +132,52 @@ public class UtilHttp { } paramMap.put(name, value); } + + paramMap.putAll(getPathInfoOnlyParameterMap(request, nameSet, onlyIncludeOrSkip)); + if (paramMap.size() == 0) { + // nothing found in the parameters; maybe we read the stream instead + Map multiPartMap = UtilGenerics.checkMap(request.getAttribute("multiPartMap")); + if (UtilValidate.isNotEmpty(multiPartMap)) { + paramMap.putAll(multiPartMap); + } + } + + if (Debug.verboseOn()) { + Debug.logVerbose("Made Request Parameter Map with [" + paramMap.size() + "] Entries", module); + Debug.logVerbose("Request Parameter Map Entries: " + System.getProperty("line.separator") + UtilMisc.printMap(paramMap), module); + } + + return paramMap; + } + + public static Map getQueryStringOnlyParameterMap(HttpServletRequest request) { + Map paramMap = FastMap.newInstance(); + String queryString = request.getQueryString(); + if (UtilValidate.isNotEmpty(queryString)) { + StringTokenizer queryTokens = new StringTokenizer(queryString, "&"); + while (queryTokens.hasMoreTokens()) { + String token = queryTokens.nextToken(); + if (token.startsWith("amp;")) { + // this is most likely a split value that had an & in it, so don't consider this a name; note that some old code just stripped the "amp;" and went with it + //token = token.substring(4); + continue; + } + int equalsIndex = token.indexOf("="); + String name = token; + if (equalsIndex > 0) { + name = token.substring(0, equalsIndex); + paramMap.put(name, request.getParameter(name)); + } + } + } + return paramMap; + } + + public static Map getPathInfoOnlyParameterMap(HttpServletRequest request, Set nameSet, Boolean onlyIncludeOrSkip) { + boolean onlyIncludeOrSkipPrim = onlyIncludeOrSkip == null ? true : onlyIncludeOrSkip.booleanValue(); + Map paramMap = FastMap.newInstance(); + // now add in all path info parameters /~name1=value1/~name2=value2/ // note that if a parameter with a given name already exists it will be put into a list with all values String pathInfoStr = request.getPathInfo(); @@ -142,6 +193,10 @@ public class UtilHttp { last = current; if (element.charAt(0) == '~' && element.indexOf('=') > -1) { String name = element.substring(1, element.indexOf('=')); + if (nameSet != null && (onlyIncludeOrSkipPrim ^ nameSet.contains(name))) { + continue; + } + String value = element.substring(element.indexOf('=') + 1); Object curValue = paramMap.get(name); if (curValue != null) { @@ -162,22 +217,15 @@ public class UtilHttp { } } } - - if (paramMap.size() == 0) { - // nothing found in the parameters; maybe we read the stream instead - Map multiPartMap = UtilGenerics.checkMap(request.getAttribute("multiPartMap")); - if (UtilValidate.isNotEmpty(multiPartMap)) { - paramMap.putAll(multiPartMap); - } - } - - if (Debug.verboseOn()) { - Debug.logVerbose("Made Request Parameter Map with [" + paramMap.size() + "] Entries", module); - Debug.logVerbose("Request Parameter Map Entries: " + System.getProperty("line.separator") + UtilMisc.printMap(paramMap), module); - } return paramMap; } + + public static Map getUrlOnlyParameterMap(HttpServletRequest request) { + Map paramMap = getQueryStringOnlyParameterMap(request); + paramMap.putAll(getPathInfoOnlyParameterMap(request, null, null)); + return paramMap; + } /** * Create a map from a HttpRequest (attributes) object @@ -960,7 +1008,7 @@ public class UtilHttp { } return retStr; } - + /** * Given multi form data with the ${param}_o_N notation, creates a Collection * of Maps for the submitted rows. Each Map contains the key/value pairs diff --git a/framework/common/webcommon/WEB-INF/common-controller.xml b/framework/common/webcommon/WEB-INF/common-controller.xml index a17d4679b7..689fe167cb 100644 --- a/framework/common/webcommon/WEB-INF/common-controller.xml +++ b/framework/common/webcommon/WEB-INF/common-controller.xml @@ -77,7 +77,7 @@ under the License. - + diff --git a/framework/common/webcommon/includes/header.ftl b/framework/common/webcommon/includes/header.ftl index 8097316648..16d64f02d5 100644 --- a/framework/common/webcommon/includes/header.ftl +++ b/framework/common/webcommon/includes/header.ftl @@ -106,10 +106,8 @@ under the License.
  • <#if person?has_content> ${uiLabelMap.CommonWelcome} ${person.firstName?if_exists} ${person.middleName?if_exists} ${person.lastName?if_exists} [${userLogin.userLoginId}] - <#if defaultOrganizationPartyId?exists>${uiLabelMap.CommonDefaultOrganizationPartyId} : ${defaultOrganizationPartyGroupName?if_exists} [${defaultOrganizationPartyId}] <#elseif partyGroup?has_content> ${uiLabelMap.CommonWelcome} ${partyGroup.groupName?if_exists} [${userLogin.userLoginId}] - <#if defaultOrganizationPartyId?exists>${uiLabelMap.CommonDefaultOrganizationPartyId} : ${defaultOrganizationPartyGroupName?if_exists} [${defaultOrganizationPartyId}] <#else> ${uiLabelMap.CommonWelcome}! @@ -134,27 +132,23 @@ under the License.
  • background="${layoutSettings.headerRightBackgroundUrl}"> <#if userLogin?exists>

    + <#if person?has_content> + ${uiLabelMap.CommonWelcome} ${person.firstName?if_exists} ${person.lastName?if_exists} + <#elseif partyGroup?has_content> + ${uiLabelMap.CommonWelcome} ${partyGroup.groupName?if_exists} + + [${userLogin.userLoginId}] ${uiLabelMap.CommonLogout}     

    - -

    - <#if person?has_content> - ${uiLabelMap.CommonWelcome} ${person.firstName?if_exists} ${person.lastName?if_exists} [${userLogin.userLoginId}] -

    <#if defaultOrganizationPartyId?exists>

    ${uiLabelMap.CommonDefaultOrganizationPartyId} : ${defaultOrganizationPartyGroupName?if_exists} [${defaultOrganizationPartyId}]

    - <#elseif partyGroup?has_content> - ${uiLabelMap.CommonWelcome} ${partyGroup.groupName?if_exists} [${userLogin.userLoginId}] -

    - <#if defaultOrganizationPartyId?exists>

    ${uiLabelMap.CommonDefaultOrganizationPartyId} : ${defaultOrganizationPartyGroupName?if_exists} [${defaultOrganizationPartyId}]

    - <#else> + <#else/> +

    ${uiLabelMap.CommonWelcome}! ${uiLabelMap.CommonLogin} -

    +

    -
    +
  • diff --git a/framework/common/webcommon/login.ftl b/framework/common/webcommon/login.ftl index 61db4ecb7b..ef517a4ba1 100644 --- a/framework/common/webcommon/login.ftl +++ b/framework/common/webcommon/login.ftl @@ -19,11 +19,6 @@ under the License. <#if requestAttributes.uiLabelMap?exists><#assign uiLabelMap = requestAttributes.uiLabelMap> -<#assign previousParams = sessionAttributes._PREVIOUS_PARAMS_?if_exists> -<#if previousParams?has_content> - <#assign previousParams = "?" + previousParams> - - <#assign username = requestParameters.USERNAME?default((sessionAttributes.autoUserLogin.userLoginId)?default(""))> <#if username != ""> <#assign focusName = false> @@ -36,7 +31,7 @@ under the License.

    ${uiLabelMap.CommonRegistered}

    -
    + diff --git a/framework/example/webapp/example/WEB-INF/controller.xml b/framework/example/webapp/example/WEB-INF/controller.xml index 1b09cc78e4..b9a4c8ca8d 100644 --- a/framework/example/webapp/example/WEB-INF/controller.xml +++ b/framework/example/webapp/example/WEB-INF/controller.xml @@ -60,20 +60,24 @@ under the License. - + + + - + + + - - + + @@ -86,19 +90,25 @@ under the License. - + + + - + + + - + + + @@ -106,19 +116,25 @@ under the License. - + + + - + + + - + + + @@ -128,13 +144,17 @@ under the License. - + + + - + + + @@ -142,19 +162,25 @@ under the License. - + + + - + + + - + + + diff --git a/framework/webapp/dtd/site-conf.xsd b/framework/webapp/dtd/site-conf.xsd index 17960b763a..af1ab95fe8 100644 --- a/framework/webapp/dtd/site-conf.xsd +++ b/framework/webapp/dtd/site-conf.xsd @@ -231,6 +231,9 @@ under the License. + + + @@ -250,6 +253,18 @@ under the License. + + Adds a parameter with the given name to the redirect. Finds value in a request attribute if exists, or a request parameter if no attribute is found. + + + + + + + + If specified used instead of the value of name for the key to find a request attribute or parameter. + + diff --git a/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java b/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java index 6fef0d2583..0d66c46796 100644 --- a/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java +++ b/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java @@ -22,11 +22,12 @@ import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import javax.servlet.ServletContext; + import javolution.util.FastList; import javolution.util.FastMap; import javolution.util.FastSet; @@ -35,7 +36,6 @@ import org.ofbiz.base.location.FlexibleLocation; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.FileUtil; import org.ofbiz.base.util.GeneralException; -import static org.ofbiz.base.util.UtilGenerics.checkMap; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; @@ -49,9 +49,20 @@ import org.w3c.dom.Element; public class ConfigXMLReader { public static final String module = ConfigXMLReader.class.getName(); + public static final String controllerXmlFileName = "/WEB-INF/controller.xml"; + public static UtilCache controllerCache = new UtilCache("webapp.ControllerConfig"); public static UtilCache> controllerSearchResultsCache = new UtilCache>("webapp.ControllerSearchResults"); + public static URL getControllerConfigURL(ServletContext context) { + try { + return context.getResource(controllerXmlFileName); + } catch(MalformedURLException e) { + Debug.logError(e, "Error Finding XML Config File: " + controllerXmlFileName, module); + return null; + } + } + public static ControllerConfig getControllerConfig(URL url) { ControllerConfig controllerConfig = controllerCache.get(url); if (controllerConfig == null) { // don't want to block here @@ -70,24 +81,193 @@ public class ConfigXMLReader { public static class ControllerConfig { public URL url; - public Map configMap = FastMap.newInstance(); - public Map> handlerMap = FastMap.newInstance(); - public Map> requestMap = FastMap.newInstance(); - public Map> viewMap = FastMap.newInstance(); - public String defaultRequest = null; + public String errorpage; + public String protectView; + public String owner; + public String securityClass; + public String defaultRequest; + + public List firstVisitEventList = FastList.newInstance(); + public List preprocessorEventList = FastList.newInstance(); + public List postprocessorEventList = FastList.newInstance(); + public List afterLoginEventList = FastList.newInstance(); + public List beforeLogoutEventList = FastList.newInstance(); + + public Map eventHandlerMap = FastMap.newInstance(); + public Map viewHandlerMap = FastMap.newInstance(); + + public Map requestMapMap = FastMap.newInstance(); + public Map viewMapMap = FastMap.newInstance(); public ControllerConfig(URL url) { this.url = url; Element rootElement = loadDocument(url); if (rootElement != null) { - this.configMap = loadConfigMap(rootElement, url); - this.handlerMap = loadHandlerMap(rootElement, url); - this.requestMap = loadRequestMap(rootElement, url); - this.viewMap = loadViewMap(rootElement, url); - this.defaultRequest = loadDefaultRequest(rootElement, url); + loadIncludes(rootElement); + + loadGeneralConfig(rootElement); + loadHandlerMap(rootElement); + loadRequestMap(rootElement); + loadViewMap(rootElement); } } + + protected void absorbControllerConfig(ControllerConfig controllerConfig) { + // copy/add all data except the url + + this.errorpage = controllerConfig.errorpage; + this.protectView = controllerConfig.protectView; + this.owner = controllerConfig.owner; + this.securityClass = controllerConfig.securityClass; + this.defaultRequest = controllerConfig.defaultRequest; + + this.firstVisitEventList.addAll(controllerConfig.firstVisitEventList); + this.preprocessorEventList.addAll(controllerConfig.preprocessorEventList); + this.postprocessorEventList.addAll(controllerConfig.postprocessorEventList); + this.afterLoginEventList.addAll(controllerConfig.afterLoginEventList); + this.beforeLogoutEventList.addAll(controllerConfig.beforeLogoutEventList); + + this.eventHandlerMap.putAll(controllerConfig.eventHandlerMap); + this.viewHandlerMap.putAll(controllerConfig.viewHandlerMap); + + this.requestMapMap.putAll(controllerConfig.requestMapMap); + this.viewMapMap.putAll(controllerConfig.viewMapMap); + } + + protected void loadIncludes(Element rootElement) { + for (Element includeElement: UtilXml.childElementList(rootElement, "include")) { + String includeLocation = includeElement.getAttribute("location"); + if (UtilValidate.isNotEmpty(includeLocation)) { + try { + ControllerConfig controllerConfig = getControllerConfig(FlexibleLocation.resolveLocation(includeLocation)); + this.absorbControllerConfig(controllerConfig); + } catch (MalformedURLException mue) { + Debug.logError(mue, "Error processing include at [" + includeLocation + "]:" + mue.toString(), module); + } + } + } + } + + protected void loadGeneralConfig(Element rootElement) { + long startTime = System.currentTimeMillis(); + if (rootElement == null) { + rootElement = loadDocument(this.url); + } + + this.errorpage = UtilXml.childElementValue(rootElement, "errorpage"); + Element protectElement = UtilXml.firstChildElement(rootElement, "protect"); + if (protectElement != null) { + this.protectView = protectElement.getAttribute("view"); + } + this.owner = UtilXml.childElementValue(rootElement, "owner"); + this.securityClass = UtilXml.childElementValue(rootElement, "security-class"); + Element defaultRequestElement = UtilXml.firstChildElement(rootElement, "default-request"); + if (defaultRequestElement != null) { + this.defaultRequest = defaultRequestElement.getAttribute("request-uri"); + } + + // first visit event + Element firstvisitElement = UtilXml.firstChildElement(rootElement, "firstvisit"); + if (firstvisitElement != null) { + for (Element eventElement: UtilXml.childElementList(firstvisitElement, "event")) { + this.firstVisitEventList.add(new Event(eventElement)); + } + } + + // preprocessor events + Element preprocessorElement = UtilXml.firstChildElement(rootElement, "preprocessor"); + if (preprocessorElement != null) { + for (Element eventElement: UtilXml.childElementList(preprocessorElement, "event")) { + this.preprocessorEventList.add(new Event(eventElement)); + } + } + + // postprocessor events + Element postprocessorElement = UtilXml.firstChildElement(rootElement, "postprocessor"); + if (postprocessorElement != null) { + for (Element eventElement: UtilXml.childElementList(postprocessorElement, "event")) { + this.postprocessorEventList.add(new Event(eventElement)); + } + } + + // after-login events + Element afterLoginElement = UtilXml.firstChildElement(rootElement, "after-login"); + if (afterLoginElement != null) { + for (Element eventElement: UtilXml.childElementList(afterLoginElement, "event")) { + this.afterLoginEventList.add(new Event(eventElement)); + } + } + + // before-logout events + Element beforeLogoutElement = UtilXml.firstChildElement(rootElement, "before-logout"); + if (beforeLogoutElement != null) { + for (Element eventElement: UtilXml.childElementList(beforeLogoutElement, "event")) { + this.beforeLogoutEventList.add(new Event(eventElement)); + } + } + + double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; + long totalRecords = this.firstVisitEventList.size() + this.preprocessorEventList.size() + this.postprocessorEventList.size() + this.afterLoginEventList.size() + this.beforeLogoutEventList.size(); + if (Debug.infoOn()) Debug.logInfo("General Configuration Loaded: (" + totalRecords + ") records in " + totalSeconds + "s", module); + } + + public void loadHandlerMap(Element rootElement) { + long startTime = System.currentTimeMillis(); + if (rootElement == null) { + rootElement = loadDocument(this.url); + } + if (rootElement == null) return; + + for (Element handlerElement: UtilXml.childElementList(rootElement, "handler")) { + String name = handlerElement.getAttribute("name"); + String type = handlerElement.getAttribute("type"); + String className = handlerElement.getAttribute("class"); + + if ("view".equals(type)) { + this.viewHandlerMap.put(name, className); + } else { + this.eventHandlerMap.put(name, className); + } + } + + double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; + if (Debug.infoOn()) Debug.logInfo("View and Event Handler Maps Created: (" + this.viewHandlerMap.size() + ") view handlers and (" + this.eventHandlerMap.size() + ") request/event handlers in " + totalSeconds + "s", module); + } + + public void loadRequestMap(Element root) { + long startTime = System.currentTimeMillis(); + if (root == null) { + root = loadDocument(this.url); + } + if (root == null) return; + + for (Element requestMapElement: UtilXml.childElementList(root, "request-map")) { + RequestMap requestMap = new RequestMap(requestMapElement); + this.requestMapMap.put(requestMap.uri, requestMap); + } + + double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; + if (Debug.infoOn()) Debug.logInfo("RequestMap Created: (" + this.requestMapMap.size() + ") records in " + totalSeconds + "s", module); + } + + public void loadViewMap(Element rootElement) { + long startTime = System.currentTimeMillis(); + if (rootElement == null) { + rootElement = loadDocument(this.url); + } + + if (rootElement == null) return; + + for (Element viewMapElement: UtilXml.childElementList(rootElement, "view-map")) { + ViewMap viewMap = new ViewMap(viewMapElement); + this.viewMapMap.put(viewMap.name, viewMap); + } + + double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; + if (Debug.infoOn()) Debug.logInfo("ViewMap Created: (" + this.viewMapMap.size() + ") records in " + totalSeconds + "s", module); + } + } public static Set findControllerFilesWithRequest(String requestUri, String controllerPartialPath) throws GeneralException { @@ -126,7 +306,7 @@ public class ConfigXMLReader { if (controllerConfigs != null) { for (ControllerConfig cc: controllerConfigs) { // make sure it has the named request in it - if (cc.requestMap.get(requestUri) != null) { + if (cc.requestMapMap.get(requestUri) != null) { String requestUniqueId = cc.url.toExternalForm() + "#" + requestUri; allControllerRequestSet.add(requestUniqueId); // Debug.logInfo("========== In findControllerFilesWithRequest found controller with request here [" + requestUniqueId + "]", module); @@ -169,65 +349,6 @@ public class ConfigXMLReader { } } - /** Site Config Variables */ - public static final String DEFAULT_ERROR_PAGE = "errorpage"; - public static final String DEFAULT_PROTECT_VIEW = "protect"; - public static final String SITE_OWNER = "owner"; - public static final String SECURITY_CLASS = "security-class"; - public static final String FIRSTVISIT = "firstvisit"; - public static final String PREPROCESSOR = "preprocessor"; - public static final String POSTPROCESSOR = "postprocessor"; - - /** URI Config Variables */ - public static final String INCLUDE = "include"; - public static final String INCLUDE_LOCATION = "location"; - - public static final String DEFAULT_REQUEST = "default-request"; - public static final String REQUEST_MAPPING = "request-map"; - public static final String REQUEST_URI = "uri"; - public static final String REQUEST_EDIT = "edit"; - public static final String REQUEST_TRACK_STATS = "track-serverhit"; - public static final String REQUEST_TRACK_VISIT = "track-visit"; - - public static final String REQUEST_DESCRIPTION = "description"; - public static final String ERROR_PAGE_DEFAULT = "error"; - public static final String NEXT_PAGE_DEFAULT = "success"; - - public static final String SECURITY = "security"; - public static final String SECURITY_HTTPS = "https"; - public static final String SECURITY_AUTH = "auth"; - public static final String SECURITY_CERT = "cert"; - public static final String SECURITY_EXTVIEW = "external-view"; - public static final String SECURITY_DIRECT = "direct-request"; - - public static final String EVENT = "event"; - public static final String EVENT_PATH = "path"; - public static final String EVENT_TYPE = "type"; - public static final String EVENT_METHOD = "invoke"; - public static final String EVENT_GLOBAL_TRANSACTION = "global-transaction"; - - public static final String RESPONSE = "response"; - public static final String RESPONSE_NAME = "name"; - public static final String RESPONSE_TYPE = "type"; - public static final String RESPONSE_VALUE = "value"; - public static final String RESPONSE_MAP = "response-map"; - - /** View Config Variables */ - public static final String VIEW_MAPPING = "view-map"; - public static final String VIEW_NAME = "name"; - public static final String VIEW_PAGE = "page"; - public static final String VIEW_TYPE = "type"; - public static final String VIEW_INFO = "info"; - public static final String VIEW_CONTENT_TYPE = "content-type"; - public static final String VIEW_ENCODING = "encoding"; - public static final String VIEW_DESCRIPTION = "description"; - - /** Handler Config Variables */ - public static final String HANDLER = "handler"; - public static final String HANDLER_NAME = "name"; - public static final String HANDLER_TYPE = "type"; - public static final String HANDLER_CLASS = "class"; - /** Loads the XML file and returns the root element */ public static Element loadDocument(URL location) { Document document; @@ -242,543 +363,128 @@ public class ConfigXMLReader { } return null; } - - /** Gets a Map of request mappings. */ - public static Map> getRequestMap(URL xml) { - ControllerConfig controllerConfig = getControllerConfig(xml); - return controllerConfig != null ? controllerConfig.requestMap : null; - } - - /** Gets a FastMap of request mappings. */ - public static Map> loadRequestMap(Element root, URL xml) { - long startTime = System.currentTimeMillis(); - Map> map = FastMap.newInstance(); - if (root == null) { - root = loadDocument(xml); - } - - if (root == null) return map; - - for (Element includeElement: UtilXml.childElementList(root, INCLUDE)) { - String includeLocation = includeElement.getAttribute(INCLUDE_LOCATION); - if ((includeLocation != null) && (includeLocation.length() > 0)) { - try { - Map> subMap = loadRequestMap(null, FlexibleLocation.resolveLocation(includeLocation)); - map.putAll(subMap); - } catch (MalformedURLException mue) { - Debug.logError(mue, "Error processing include at [" + includeLocation + "]:" + mue.toString(), module); - } - } - } - - for (Element requestMapElement: UtilXml.childElementList(root, REQUEST_MAPPING)) { - - // Create a URI-MAP for each element found. - Map uriMap = FastMap.newInstance(); - - // Get the URI info. - String uri = requestMapElement.getAttribute(REQUEST_URI); - String edit = requestMapElement.getAttribute(REQUEST_EDIT); - String stats = requestMapElement.getAttribute(REQUEST_TRACK_STATS); - String visit = requestMapElement.getAttribute(REQUEST_TRACK_VISIT); - - if (edit == null || edit.equals("")) - edit = "true"; - if (uri != null) { - uriMap.put(REQUEST_URI, uri); - uriMap.put(REQUEST_EDIT, edit); - uriMap.put(REQUEST_TRACK_STATS, stats); - uriMap.put(REQUEST_TRACK_VISIT, visit); - } - - // Check for security. - Element securityElement = UtilXml.firstChildElement(requestMapElement, SECURITY); - if (securityElement != null) { - String securityHttps = securityElement.getAttribute(SECURITY_HTTPS); - String securityAuth = securityElement.getAttribute(SECURITY_AUTH); - String securityCert = securityElement.getAttribute(SECURITY_CERT); - String securityExtView = securityElement.getAttribute(SECURITY_EXTVIEW); - String securityDirectRequest = securityElement.getAttribute(SECURITY_DIRECT); - - // if x509 is required so is https - if ("true".equalsIgnoreCase(securityCert)) { - securityHttps = "true"; - } - - uriMap.put(SECURITY_HTTPS, securityHttps); - uriMap.put(SECURITY_AUTH, securityAuth); - uriMap.put(SECURITY_CERT, securityCert); - uriMap.put(SECURITY_EXTVIEW, securityExtView); - uriMap.put(SECURITY_DIRECT, securityDirectRequest); - } - - // Check for an event. - Element eventElement = UtilXml.firstChildElement(requestMapElement, EVENT); - if (eventElement != null) { - String type = eventElement.getAttribute(EVENT_TYPE); - String path = eventElement.getAttribute(EVENT_PATH); - String invoke = eventElement.getAttribute(EVENT_METHOD); - - uriMap.put(EVENT_TYPE, type); - uriMap.put(EVENT_PATH, path); - uriMap.put(EVENT_METHOD, invoke); - - // Check for a global-transaction attribute - default to true - uriMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); - } - - // Check for a description. - String description = UtilXml.childElementValue(requestMapElement, REQUEST_DESCRIPTION); - uriMap.put(REQUEST_DESCRIPTION, UtilValidate.isNotEmpty(description) ? description : ""); - - // Get the response(s). - Map responseMap = FastMap.newInstance(); - uriMap.put(RESPONSE_MAP, responseMap); - - for (Element responseElement: UtilXml.childElementList(requestMapElement, RESPONSE)) { - String name = responseElement.getAttribute(RESPONSE_NAME); - String type = responseElement.getAttribute(RESPONSE_TYPE); - String value = responseElement.getAttribute(RESPONSE_VALUE); - - responseMap.put(name, type + ":" + value); - } - - if (uri != null) { - map.put(uri, uriMap); - } - } - - /* Debugging */ - if (Debug.verboseOn()) { - Debug.logVerbose("-------- Request Mappings --------", module); - //FastMap debugMap = map; - Set debugSet = map.keySet(); - Iterator i = debugSet.iterator(); - while (i.hasNext()) { - Object o = i.next(); - String request = (String) o; - Map thisURI = map.get(o); - - StringBuilder verboseMessageBuffer = new StringBuilder(); - - Iterator debugIter = thisURI.keySet().iterator(); - while (debugIter.hasNext()) { - Object lo = debugIter.next(); - String name = (String) lo; - String value = thisURI.get(lo).toString(); - - verboseMessageBuffer.append("[").append(name).append("=>").append(value).append("]"); - } - Debug.logVerbose(request + " :: " + verboseMessageBuffer.toString(), module); - } - Debug.logVerbose("------ End Request Mappings ------", module); - } - /* End Debugging */ - - double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; - if (Debug.infoOn()) Debug.logInfo("RequestMap Created: (" + map.size() + ") records in " + totalSeconds + "s", module); - return map; - } - - /** Gets a FastMap of view mappings. */ - public static Map> getViewMap(URL xml) { - ControllerConfig controllerConfig = getControllerConfig(xml); - return controllerConfig != null ? controllerConfig.viewMap : null; - } - - /** Gets a FastMap of view mappings. */ - public static Map> loadViewMap(Element root, URL xml) { - long startTime = System.currentTimeMillis(); - Map> map = FastMap.newInstance(); - if (root == null) { - root = loadDocument(xml); - } - - if (root == null) { - return map; - } - - for (Element includeElement: UtilXml.childElementList(root, INCLUDE)) { - String includeLocation = includeElement.getAttribute(INCLUDE_LOCATION); - if ((includeLocation != null) && (includeLocation.length() > 0)) { - try { - Map> subMap = loadViewMap(null, FlexibleLocation.resolveLocation(includeLocation)); - map.putAll(subMap); - } catch (MalformedURLException mue) { - Debug.logError(mue, "Error processing include at [" + includeLocation + "]:" + mue.toString(), module); - } - } - } - - for (Element viewMapElement: UtilXml.childElementList(root, VIEW_MAPPING)) { - // Create a URI-MAP for each element found. - Map uriMap = FastMap.newInstance(); - - // Get the view info. - String name = viewMapElement.getAttribute(VIEW_NAME); - String page = viewMapElement.getAttribute(VIEW_PAGE); - if (page == null || page.length() == 0) { - page = name; - } - - uriMap.put(VIEW_NAME, name); - uriMap.put(VIEW_PAGE, page); - uriMap.put(VIEW_TYPE, viewMapElement.getAttribute(VIEW_TYPE)); - uriMap.put(VIEW_INFO, viewMapElement.getAttribute(VIEW_INFO)); - uriMap.put(VIEW_CONTENT_TYPE, viewMapElement.getAttribute(VIEW_CONTENT_TYPE)); - uriMap.put(VIEW_ENCODING, viewMapElement.getAttribute(VIEW_ENCODING)); - - // Check for a description. - String description = UtilXml.childElementValue(viewMapElement, VIEW_DESCRIPTION); - uriMap.put(VIEW_DESCRIPTION, UtilValidate.isNotEmpty(description) ? description : ""); - - if (name != null) map.put(name, uriMap); - } - - /* Debugging */ - if (Debug.verboseOn()) { - Debug.logVerbose("-------- View Mappings --------", module); - //FastMap debugMap = map; - Set debugSet = map.keySet(); - Iterator i = debugSet.iterator(); - while (i.hasNext()) { - Object o = i.next(); - String request = (String) o; - Map thisURI = (Map) map.get(o); - - StringBuilder verboseMessageBuffer = new StringBuilder(); - - Iterator debugIter = thisURI.keySet().iterator(); - while (debugIter.hasNext()) { - Object lo = debugIter.next(); - String name = (String) lo; - String value = (String) thisURI.get(lo); - - verboseMessageBuffer.append("[").append(name).append("=>").append(value).append("]"); - } - Debug.logVerbose(request + " :: " + verboseMessageBuffer.toString(), module); - } - Debug.logVerbose("------ End View Mappings ------", module); - } - /* End Debugging */ - - double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; - if (Debug.infoOn()) Debug.logInfo("ViewMap Created: (" + map.size() + ") records in " + totalSeconds + "s", module); - return map; - } - - /** Gets a FastMap of site configuration variables. */ - public static Map getConfigMap(URL xml) { - ControllerConfig controllerConfig = getControllerConfig(xml); - return controllerConfig != null ? controllerConfig.configMap : null; - } - - /** Gets a FastMap of site configuration variables. */ - public static Map loadConfigMap(Element root, URL xml) { - long startTime = System.currentTimeMillis(); - FastMap map = FastMap.newInstance(); - if (root == null) { - root = loadDocument(xml); - } + public static class RequestMap { + public String uri; + public boolean edit; + public boolean trackVisit; + public boolean trackServerHit; + public String description; - if (root == null) { - return map; - } - - for (Element includeElement: UtilXml.childElementList(root, INCLUDE)) { - String includeLocation = includeElement.getAttribute(INCLUDE_LOCATION); - if ((includeLocation != null) && (includeLocation.length() > 0)) { - try { - Map subMap = loadConfigMap(null, FlexibleLocation.resolveLocation(includeLocation)); - map.putAll(subMap); - } catch (MalformedURLException mue) { - Debug.logError(mue, "Error processing include at [" + includeLocation + "]:" + mue.toString(), module); - } - } - } - - // default error page - String errorpage = UtilXml.childElementValue(root, DEFAULT_ERROR_PAGE); - if (UtilValidate.isNotEmpty(errorpage)) map.put(DEFAULT_ERROR_PAGE, errorpage); - - // default protect view - Element protectElement = UtilXml.firstChildElement(root, DEFAULT_PROTECT_VIEW); - String protectview; - if (protectElement != null) { - protectview = protectElement.getAttribute("view"); - if (protectview != null) map.put(DEFAULT_PROTECT_VIEW, protectview); - } + public Event event; - // site owner - String owner = UtilXml.childElementValue(root, SITE_OWNER); - if (UtilValidate.isNotEmpty(owner)) map.put(SITE_OWNER, owner); + public boolean securityHttps; + public boolean securityAuth; + public boolean securityCert; + public boolean securityExternalView; + public boolean securityDirectRequest; + + public Map requestResponseMap = FastMap.newInstance(); - // security class - String securityClass = UtilXml.childElementValue(root, SECURITY_CLASS); - if (UtilValidate.isNotEmpty(securityClass)) map.put(SECURITY_CLASS, securityClass); - - // first visit event - Element firstvisitElement = UtilXml.firstChildElement(root, FIRSTVISIT); - if (firstvisitElement != null) { - List> eventList = FastList.newInstance(); - for (Element eventElement: UtilXml.childElementList(firstvisitElement, EVENT)) { - Map eventMap = FastMap.newInstance(); - eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); - eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); - eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); - - // Check for a global-transaction attribute - default to true - eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); - eventList.add(eventMap); - } - map.put(FIRSTVISIT, eventList); - } - - // preprocessor events - Element preprocessorElement = UtilXml.firstChildElement(root, PREPROCESSOR); - if (preprocessorElement != null) { - List> eventList = FastList.newInstance(); - for (Element eventElement: UtilXml.childElementList(preprocessorElement, EVENT)) { - Map eventMap = FastMap.newInstance(); - eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); - eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); - eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); - - // Check for a global-transaction attribute - default to true - eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); - eventList.add(eventMap); - } - map.put(PREPROCESSOR, eventList); - } - - // postprocessor events - Element postprocessorElement = UtilXml.firstChildElement(root, POSTPROCESSOR); - if (postprocessorElement != null) { - List> eventList = FastList.newInstance(); - for (Element eventElement: UtilXml.childElementList(postprocessorElement, EVENT)) { - Map eventMap = FastMap.newInstance(); - eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); - eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); - eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); - - // Check for a global-transaction attribute - default to true - eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); - eventList.add(eventMap); - } - map.put(POSTPROCESSOR, eventList); - } - - // after-login events - Element afterLoginElement = UtilXml.firstChildElement(root, "after-login"); - if (afterLoginElement != null) { - List> eventList = FastList.newInstance(); - for (Element eventElement: UtilXml.childElementList(afterLoginElement, EVENT)) { - Map eventMap = FastMap.newInstance(); - eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); - eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); - eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); - - // Check for a global-transaction attribute - default to true - eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); - eventList.add(eventMap); - } - map.put("after-login", eventList); - } - - // before-logout events - Element beforeLogoutElement = UtilXml.firstChildElement(root, "before-logout"); - if (beforeLogoutElement != null) { - List> eventList = FastList.newInstance(); - List eventElementList = UtilXml.childElementList(beforeLogoutElement, EVENT); - for (Element eventElement: UtilXml.childElementList(beforeLogoutElement, EVENT)) { - Map eventMap = FastMap.newInstance(); - eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); - eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); - eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); - - // Check for a global-transaction attribute - default to true - eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); - eventList.add(eventMap); - } - map.put("before-logout", eventList); - } - - /* Debugging */ /* - Debug.logVerbose("-------- Config Mappings --------", module); - FastMap debugMap = map; - Set debugSet = debugMap.keySet(); - Iterator i = debugSet.iterator(); - while (i.hasNext()) { - Object o = i.next(); - String request = (String) o; - FastMap thisURI = (FastMap) debugMap.get(o); - Debug.logVerbose(request, module); - Iterator debugIter = ((Set) thisURI.keySet()).iterator(); - while (debugIter.hasNext()) { - Object lo = debugIter.next(); - String name = (String) lo; - String value = (String) thisURI.get(lo); - if (Debug.verboseOn()) Debug.logVerbose("\t" + name + " -> " + value, module); - } - } - Debug.logVerbose("------ End Config Mappings ------", module); - */ - /* End Debugging */ + public static final String ERROR_PAGE_DEFAULT = "error"; + public static final String NEXT_PAGE_DEFAULT = "success"; + */ + + public RequestMap(Element requestMapElement) { - double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; - if (Debug.infoOn()) Debug.logInfo("ConfigMap Created: (" + map.size() + ") records in " + totalSeconds + "s", module); - return map; + // Get the URI info + this.uri = requestMapElement.getAttribute("uri"); + this.edit = !"false".equals(requestMapElement.getAttribute("edit")); + this.trackServerHit = !"false".equals(requestMapElement.getAttribute("track-serverhit")); + this.trackVisit = !"false".equals(requestMapElement.getAttribute("track-visit")); + + // Check for security + Element securityElement = UtilXml.firstChildElement(requestMapElement, "security"); + if (securityElement != null) { + this.securityHttps = "true".equals(securityElement.getAttribute("https")); + this.securityAuth = "true".equals(securityElement.getAttribute("auth")); + this.securityCert = "true".equals(securityElement.getAttribute("cert")); + this.securityExternalView = !"false".equals(securityElement.getAttribute("external-view")); + this.securityDirectRequest = !"false".equals(securityElement.getAttribute("direct-request")); + } + + // Check for event + Element eventElement = UtilXml.firstChildElement(requestMapElement, "event"); + if (eventElement != null) { + this.event = new Event(eventElement); + } + + // Check for description + this.description = UtilXml.childElementValue(requestMapElement, "description"); + + // Get the response(s) + for (Element responseElement: UtilXml.childElementList(requestMapElement, "response")) { + RequestResponse response = new RequestResponse(responseElement); + requestResponseMap.put(response.name, response); + } + } } + + public static class Event { + public String type; + public String path; + public String invoke; + public boolean globalTransaction; - /** Gets the default-request from the configuration */ - public static String getDefaultRequest(URL xml) { - ControllerConfig controllerConfig = getControllerConfig(xml); - return controllerConfig != null ? controllerConfig.defaultRequest : null; + public Event(Element eventElement) { + this.type = eventElement.getAttribute("type"); + this.path = eventElement.getAttribute("path"); + this.invoke = eventElement.getAttribute("invoke"); + this.globalTransaction = !"false".equals(eventElement.getAttribute("global-transaction")); + } } - - public static String loadDefaultRequest(Element root, URL xml) { - if (root == null) { - root = loadDocument(xml); - } - if (root == null) { - return null; - } - - // holder for the default-request - String defaultRequest = null; - - for (Element includeElement: UtilXml.childElementList(root, INCLUDE)) { - String includeLocation = includeElement.getAttribute(INCLUDE_LOCATION); - if ((includeLocation != null) && (includeLocation.length() > 0)) { - try { - defaultRequest = loadDefaultRequest(null, FlexibleLocation.resolveLocation(includeLocation)); - } catch (MalformedURLException mue) { - Debug.logError(mue, "Error processing include at [" + includeLocation + "]:" + mue.toString(), module); - } + + public static final RequestResponse emptyNoneRequestResponse = RequestResponse.createEmptyNoneRequestResponse(); + public static class RequestResponse { + public String name; + public String type; + public String value; + public Map redirectParameterMap = FastMap.newInstance(); + + public RequestResponse(Element responseElement) { + this.name = responseElement.getAttribute("name"); + this.type = responseElement.getAttribute("type"); + this.value = responseElement.getAttribute("value"); + for (Element redirectParameterElement: UtilXml.childElementList(responseElement, "redirect-parameter")) { + String from = redirectParameterElement.getAttribute("from"); + if (UtilValidate.isEmpty(from)) from = redirectParameterElement.getAttribute("name"); + this.redirectParameterMap.put(redirectParameterElement.getAttribute("name"), from); } } - - Element e = UtilXml.firstChildElement(root, "default-request"); - if (e != null) { - defaultRequest = e.getAttribute("request-uri"); + + public RequestResponse() { } + + public static RequestResponse createEmptyNoneRequestResponse() { + RequestResponse requestResponse = new RequestResponse(); + requestResponse.name = "empty-none"; + requestResponse.type = "none"; + requestResponse.value = null; + return requestResponse; } - return defaultRequest; } + + public static class ViewMap { + public String viewMap; + public String name; + public String page; + public String type; + public String info; + public String contentType; + public String encoding; + public String description; - /** Gets a FastMap of handler mappings. */ - public static Map> getHandlerMap(URL xml) { - ControllerConfig controllerConfig = getControllerConfig(xml); - return controllerConfig != null ? controllerConfig.handlerMap : null; - } - - public static Map> loadHandlerMap(Element root, URL xml) { - long startTime = System.currentTimeMillis(); - Map> map = FastMap.newInstance(); - if (root == null) { - root = loadDocument(xml); - } - if (root == null) { - return map; - } - - for (Element includeElement: UtilXml.childElementList(root, INCLUDE)) { - String includeLocation = includeElement.getAttribute(INCLUDE_LOCATION); - if ((includeLocation != null) && (includeLocation.length() > 0)) { - try { - Map> subMap = loadHandlerMap(null, FlexibleLocation.resolveLocation(includeLocation)); - - Map newViewHandlerMap = checkMap(subMap.get("view"), String.class, String.class); - Map viewHandlerMap = checkMap(map.get("view"), String.class, String.class); - if (viewHandlerMap == null) { - map.put("view", newViewHandlerMap); - } else { - if (newViewHandlerMap != null) { - viewHandlerMap.putAll(newViewHandlerMap); - } - } - - Map newEventHandlerMap = checkMap(subMap.get("event"), String.class, String.class); - Map eventHandlerMap = checkMap(map.get("event"), String.class, String.class); - if (eventHandlerMap == null) { - map.put("event", newEventHandlerMap); - } else { - if (newEventHandlerMap != null) { - eventHandlerMap.putAll(newEventHandlerMap); - } - } - } catch (MalformedURLException mue) { - Debug.logError(mue, "Error processing include at [" + includeLocation + "]:" + mue.toString(), module); - } + public ViewMap(Element viewMapElement) { + this.name = viewMapElement.getAttribute("name"); + this.page = viewMapElement.getAttribute("page"); + this.type = viewMapElement.getAttribute("type"); + this.info = viewMapElement.getAttribute("info"); + this.contentType = viewMapElement.getAttribute("content-type"); + this.encoding = viewMapElement.getAttribute("encoding"); + this.description = UtilXml.childElementValue(viewMapElement, "description"); + if (UtilValidate.isEmpty(this.page)) { + this.page = this.name; } } - - Map eventMap = FastMap.newInstance(); - Map viewMap = FastMap.newInstance(); - - for (Element handlerElement: UtilXml.childElementList(root, HANDLER)) { - String hName = checkEmpty(handlerElement.getAttribute(HANDLER_NAME)); - String hClass = checkEmpty(handlerElement.getAttribute(HANDLER_CLASS)); - String hType = checkEmpty(handlerElement.getAttribute(HANDLER_TYPE)); - if (hType.equals("view")) { - viewMap.put(hName, hClass); - } else { - eventMap.put(hName, hClass); - } - } - - Map viewHandlerMap = checkMap(map.get("view"), String.class, String.class); - if (viewHandlerMap == null) { - map.put("view", viewMap); - } else { - if (viewMap != null) { - viewHandlerMap.putAll(viewMap); - } - } - Map eventHandlerMap = checkMap(map.get("event"), String.class, String.class); - if (eventHandlerMap == null) { - map.put("event", eventMap); - } else { - if (eventMap != null) { - eventHandlerMap.putAll(eventMap); - } - } - - /* Debugging */ - if (Debug.verboseOn()) { - Debug.logVerbose("-------- Handler Mappings --------", module); - Map debugMap = checkMap(map.get("event"), String.class, String.class); - - if (UtilValidate.isNotEmpty(debugMap)) { - Debug.logVerbose("-------------- EVENT -------------", module); - for (Map.Entry entry: debugMap.entrySet()) { - String handlerName = entry.getKey(); - String className = entry.getValue(); - Debug.logVerbose("[EH] : " + handlerName + " => " + className, module); - } - } - debugMap = checkMap(map.get("view"), String.class, String.class); - if (UtilValidate.isNotEmpty(debugMap)) { - Debug.logVerbose("-------------- VIEW --------------", module); - for (Map.Entry entry: debugMap.entrySet()) { - String handlerName = entry.getKey(); - String className = entry.getValue(); - Debug.logVerbose("[VH] : " + handlerName + " => " + className, module); - } - } - Debug.logVerbose("------ End Handler Mappings ------", module); - } - - double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0; - if (Debug.infoOn()) Debug.logInfo("HandlerMap Created: (" + ((Map) map.get("view")).size() + ") view handlers and (" + ((Map) map.get("event")).size() + ") request/event handlers in " + totalSeconds + "s", module); - return map; - } - - private static String checkEmpty(String string) { - if (string != null && string.length() > 0) - return string; - else - return ""; } } diff --git a/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java b/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java index cc1f06dcf7..1969f4e67c 100644 --- a/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java +++ b/framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java @@ -18,12 +18,10 @@ *******************************************************************************/ package org.ofbiz.webapp.control; -import java.io.UnsupportedEncodingException; +import static org.ofbiz.base.util.UtilGenerics.checkMap; + import java.math.BigInteger; -import java.net.URLEncoder; import java.security.cert.X509Certificate; -import java.util.Enumeration; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Matcher; @@ -31,7 +29,6 @@ import java.util.regex.Pattern; import javax.security.auth.x500.X500Principal; import javax.servlet.ServletContext; -import javax.servlet.ServletRequest; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -47,7 +44,6 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.KeyStoreUtil; import org.ofbiz.base.util.UtilFormatOut; -import static org.ofbiz.base.util.UtilGenerics.checkMap; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; @@ -58,7 +54,6 @@ import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityConditionList; -import org.ofbiz.entity.condition.EntityExpr; import org.ofbiz.entity.condition.EntityOperator; import org.ofbiz.entity.model.ModelEntity; import org.ofbiz.entity.transaction.GenericTransactionException; @@ -88,43 +83,28 @@ public class LoginWorker { return makeLoginUrl(pageContext, "checkLogin"); } - public static String makeLoginUrl(ServletRequest request) { + public static String makeLoginUrl(HttpServletRequest request) { return makeLoginUrl(request, "checkLogin"); } public static String makeLoginUrl(PageContext pageContext, String requestName) { - return makeLoginUrl(pageContext.getRequest(), requestName); + return makeLoginUrl((HttpServletRequest) pageContext.getRequest(), requestName); } - public static String makeLoginUrl(ServletRequest request, String requestName) { - String queryString = null; + public static String makeLoginUrl(HttpServletRequest request, String requestName) { + Map urlParams = UtilHttp.getUrlOnlyParameterMap(request); + String queryString = UtilHttp.urlEncodeArgs(urlParams, false); + String currentView = UtilFormatOut.checkNull((String) request.getAttribute("_CURRENT_VIEW_")); - Enumeration parameterNames = request.getParameterNames(); - - while (parameterNames != null && parameterNames.hasMoreElements()) { - String paramName = (String) parameterNames.nextElement(); - - if (paramName != null) { - String sane_paramName, sane_value; - try { - sane_paramName = URLEncoder.encode((String) paramName, "UTF-8"); - sane_value = URLEncoder.encode(request.getParameter(paramName), "UTF-8"); - } catch (UnsupportedEncodingException ex) { - Debug.logError(ex, module); - sane_paramName = paramName; - sane_value = request.getParameter(paramName); - } - - if (queryString == null) { - queryString = sane_paramName + "=" + sane_value; - } else { - queryString = queryString + "&" + sane_paramName + "=" + sane_value; - } - } + String loginUrl = "/" + requestName; + if ("login".equals(currentView)) { + return loginUrl; + } + if (UtilValidate.isNotEmpty(currentView)) { + loginUrl += "/" + currentView; + } + if (UtilValidate.isNotEmpty(queryString)) { + loginUrl += "?" + queryString; } - - String loginUrl = "/" + requestName + "/" + UtilFormatOut.checkNull((String) request.getAttribute("_CURRENT_VIEW_")); - - if (queryString != null) loginUrl = loginUrl + "?" + UtilFormatOut.checkNull(queryString); return loginUrl; } @@ -231,8 +211,8 @@ public class LoginWorker { * @return String */ public static String checkLogin(HttpServletRequest request, HttpServletResponse response) { - GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); HttpSession session = request.getSession(); + GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); // anonymous shoppers are not logged in if (userLogin != null && "anonymous".equals(userLogin.getString("userLoginId"))) { @@ -272,21 +252,25 @@ public class LoginWorker { // in this condition log them in if not already; if not logged in or can't log in, save parameters and return error if ((username == null) || (password == null) || ("error".equals(login(request, response)))) { - Map reqParams = UtilHttp.getParameterMap(request); - String queryString = UtilHttp.urlEncodeArgs(reqParams); - Debug.logInfo("reqParams Map: " + reqParams, module); - Debug.logInfo("queryString: " + queryString, module); // make sure this attribute is not in the request; this avoids infinite recursion when a login by less stringent criteria (like not checkout the hasLoggedOut field) passes; this is not a normal circumstance but can happen with custom code or in funny error situations when the userLogin service gets the userLogin object but runs into another problem and fails to return an error request.removeAttribute("_LOGIN_PASSED_"); - + + // keep the previous request name in the session session.setAttribute("_PREVIOUS_REQUEST_", request.getPathInfo()); - if (queryString != null && queryString.length() > 0) { - session.setAttribute("_PREVIOUS_PARAMS_", queryString); + + // NOTE: not using the old _PREVIOUS_PARAMS_ attribute at all because it was a security hole as it was used to put data in the URL (never encrypted) that was originally in a form field that may have been encrypted + // keep 2 maps: one for URL parameters and one for form parameters + Map urlParams = UtilHttp.getUrlOnlyParameterMap(request); + if (urlParams != null && urlParams.size() > 0) { + session.setAttribute("_PREVIOUS_PARAM_MAP_URL_", urlParams); + } + Map formParams = UtilHttp.getParameterMap(request, urlParams.keySet(), false); + if (formParams != null && formParams.size() > 0) { + session.setAttribute("_PREVIOUS_PARAM_MAP_FORM_", formParams); } - if (Debug.infoOn()) Debug.logInfo("checkLogin: queryString=" + queryString, module); - if (Debug.infoOn()) Debug.logInfo("checkLogin: PathInfo=" + request.getPathInfo(), module); + //if (Debug.infoOn()) Debug.logInfo("checkLogin: PathInfo=" + request.getPathInfo(), module); return "error"; } @@ -305,6 +289,11 @@ public class LoginWorker { */ public static String login(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); + + if (session.getAttribute("userLogin") != null) { + // already logged in, do nothing... + return "success"; + } String username = request.getParameter("USERNAME"); String password = request.getParameter("PASSWORD"); diff --git a/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java b/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java index d9358a3240..ba6f87e971 100644 --- a/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java +++ b/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java @@ -18,19 +18,32 @@ *******************************************************************************/ package org.ofbiz.webapp.control; +import static org.ofbiz.base.util.UtilGenerics.checkMap; + import java.io.IOException; import java.io.Serializable; import java.io.UnsupportedEncodingException; -import java.util.*; import java.security.cert.X509Certificate; +import java.util.List; +import java.util.Locale; +import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import static org.ofbiz.base.util.UtilGenerics.checkMap; -import org.ofbiz.base.util.*; +import javolution.util.FastMap; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.SSLUtil; +import org.ofbiz.base.util.StringUtil; +import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilObject; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; @@ -44,8 +57,6 @@ import org.ofbiz.webapp.view.ViewHandler; import org.ofbiz.webapp.view.ViewHandlerException; import org.ofbiz.webapp.website.WebSiteWorker; -import javolution.util.FastMap; - /** * RequestHandler - Request Processor Object */ @@ -66,17 +77,22 @@ public class RequestHandler implements Serializable { } private ServletContext context = null; - private RequestManager requestManager = null; + private ConfigXMLReader.ControllerConfig controllerConfig = null; private ViewFactory viewFactory = null; private EventFactory eventFactory = null; public void init(ServletContext context) { Debug.logInfo("[RequestHandler Loading...]", module); this.context = context; - this.requestManager = new RequestManager(context); + + this.controllerConfig = ConfigXMLReader.getControllerConfig(ConfigXMLReader.getControllerConfigURL(context)); this.viewFactory = new ViewFactory(this); this.eventFactory = new EventFactory(this); } + + public ConfigXMLReader.ControllerConfig getControllerConfig() { + return this.controllerConfig; + } public void doRequest(HttpServletRequest request, HttpServletResponse response, String requestUri) throws RequestHandlerException { HttpSession session = request.getSession(); @@ -89,48 +105,61 @@ public class RequestHandler implements Serializable { GenericValue userLogin, GenericDelegator delegator) throws RequestHandlerException { HttpSession session = request.getSession(); - String eventType; - String eventPath; - String eventMethod; // workaraound if we are in the root webapp String cname = UtilHttp.getApplicationName(request); // Grab data from request object to process - String requestUri = RequestHandler.getRequestUri(request.getPathInfo()); - String nextView = RequestHandler.getNextPageUri(request.getPathInfo()); + String defaultRequestUri = RequestHandler.getRequestUri(request.getPathInfo()); if (request.getAttribute("targetRequestUri") == null) { if (request.getSession().getAttribute("_PREVIOUS_REQUEST_") != null) { request.setAttribute("targetRequestUri", request.getSession().getAttribute("_PREVIOUS_REQUEST_")); } else { - request.setAttribute("targetRequestUri", "/" + requestUri); + request.setAttribute("targetRequestUri", "/" + defaultRequestUri); } } + + String overrideViewUri = RequestHandler.getOverrideViewUri(request.getPathInfo()); + + String requestMissingErrorMessage = "Unknown request [" + defaultRequestUri + "]; this request does not exist or cannot be called directly."; + + ConfigXMLReader.RequestMap requestMap = controllerConfig.requestMapMap.get(defaultRequestUri); + if (requestMap == null) { + throw new RequestHandlerException(requestMissingErrorMessage); + } - String eventReturnString = null; + String eventReturn = null; + boolean interruptRequest = false; // Check for chained request. if (chain != null) { - requestUri = RequestHandler.getRequestUri(chain); + String chainRequestUri = RequestHandler.getRequestUri(chain); + requestMap = controllerConfig.requestMapMap.get(chainRequestUri); if (request.getAttribute("_POST_CHAIN_VIEW_") != null) { - nextView = (String) request.getAttribute("_POST_CHAIN_VIEW_"); + overrideViewUri = (String) request.getAttribute("_POST_CHAIN_VIEW_"); } else { - nextView = RequestHandler.getNextPageUri(chain); + overrideViewUri = RequestHandler.getOverrideViewUri(chain); } - if (Debug.infoOn()) Debug.logInfo("[RequestHandler]: Chain in place: requestUri=" + requestUri + " nextView=" + nextView + " sessionId=" + UtilHttp.getSessionId(request), module); + if (Debug.infoOn()) Debug.logInfo("[RequestHandler]: Chain in place: requestUri=" + chainRequestUri + " overrideViewUri=" + overrideViewUri + " sessionId=" + UtilHttp.getSessionId(request), module); } else { + // Check if X509 is required and we are not secure; throw exception + if (!request.isSecure() && requestMap.securityCert) { + throw new RequestHandlerException(requestMissingErrorMessage); + } + // Check to make sure we are allowed to access this request directly. (Also checks if this request is defined.) // If the request cannot be called, or is not defined, check and see if there is a default-request we an process - if (!requestManager.allowDirectRequest(requestUri)) { - if (!requestManager.allowDirectRequest(requestManager.getDefaultRequest())) { - throw new RequestHandlerException("Unknown request [" + requestUri + "]; this request does not exist or cannot be called directly."); + if (!requestMap.securityDirectRequest) { + if (!controllerConfig.requestMapMap.get(controllerConfig.defaultRequest).securityDirectRequest) { + // use the same message as if it was missing for security reasons, ie so can't tell if it is missing or direct request is not allowed + throw new RequestHandlerException(requestMissingErrorMessage); } else { - requestUri = requestManager.getDefaultRequest(); + requestMap = controllerConfig.requestMapMap.get(controllerConfig.defaultRequest); } } // Check if we SHOULD be secure and are not. If we are posting let it pass to not lose data. (too late now anyway) - if (!request.isSecure() && requestManager.requiresHttps(requestUri) && !request.getMethod().equalsIgnoreCase("POST")) { + if (!request.isSecure() && requestMap.securityHttps && !request.getMethod().equalsIgnoreCase("POST")) { StringBuilder urlBuf = new StringBuilder(); urlBuf.append(request.getPathInfo()); if (request.getQueryString() != null) { @@ -143,13 +172,8 @@ public class RequestHandler implements Serializable { } } - // Check if X509 is required and we are not secure; throw exception - if (!request.isSecure() && requestManager.requiresHttpsClientCert(requestUri)) { - throw new RequestHandlerException("Unknown request [" + requestUri + "]; this request does not exist or cannot be called directly."); - } - // Check for HTTPS client (x.509) security - if (request.isSecure() && requestManager.requiresHttpsClientCert(requestUri)) { + if (request.isSecure() && requestMap.securityCert) { X509Certificate[] clientCerts = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate"); // 2.2 spec if (clientCerts == null) { clientCerts = (X509Certificate[]) request.getAttribute("javax.net.ssl.peer_certificates"); // 2.1 spec @@ -162,7 +186,7 @@ public class RequestHandler implements Serializable { boolean foundTrustedCert = false; if (clientCerts == null) { - throw new RequestHandlerException("Unknown request [" + requestUri + "]; this request does not exist or cannot be called directly."); + throw new RequestHandlerException(requestMissingErrorMessage); } else { if (Debug.infoOn()) { for (int i = 0; i < clientCerts.length; i++) { @@ -177,8 +201,8 @@ public class RequestHandler implements Serializable { } if (!foundTrustedCert) { - Debug.logWarning("No trusted certificate found for request [" + requestUri + "]", module); - throw new RequestHandlerException("Unknown request [" + requestUri + "]; this request does not exist or cannot be called directly."); + Debug.logWarning(requestMissingErrorMessage, module); + throw new RequestHandlerException(requestMissingErrorMessage); } } @@ -188,20 +212,14 @@ public class RequestHandler implements Serializable { Debug.logInfo("This is the first request in this visit." + " sessionId=" + UtilHttp.getSessionId(request), module); // This isn't an event because it is required to run. We do not want to make it optional. GenericValue visit = VisitHandler.getVisit(session); - Collection> events = requestManager.getFirstVisitEvents(); - - if (visit != null && events != null) { - for (Map eventMap: events) { - String eType = eventMap.get(ConfigXMLReader.EVENT_TYPE); - String ePath = eventMap.get(ConfigXMLReader.EVENT_PATH); - String eMeth = eventMap.get(ConfigXMLReader.EVENT_METHOD); - + if (visit != null) { + for (ConfigXMLReader.Event event: controllerConfig.firstVisitEventList) { try { - String returnString = this.runEvent(request, response, eType, ePath, eMeth); + String returnString = this.runEvent(request, response, event.type, event.path, event.invoke); if (returnString != null && !returnString.equalsIgnoreCase("success")) { throw new EventHandlerException("First-Visit event did not return 'success'."); } else if (returnString == null) { - nextView = "none:"; + interruptRequest = true; } } catch (EventHandlerException e) { Debug.logError(e, module); @@ -211,103 +229,105 @@ public class RequestHandler implements Serializable { } // Invoke the pre-processor (but NOT in a chain) - Collection> preProcEvents = requestManager.getPreProcessor(); - if (preProcEvents != null) { - for (Map eventMap: preProcEvents) { - String eType = eventMap.get(ConfigXMLReader.EVENT_TYPE); - String ePath = eventMap.get(ConfigXMLReader.EVENT_PATH); - String eMeth = eventMap.get(ConfigXMLReader.EVENT_METHOD); - try { - String returnString = this.runEvent(request, response, eType, ePath, eMeth); - if (returnString != null && !returnString.equalsIgnoreCase("success")) { - if (!returnString.contains(":_protect_:")) { - throw new EventHandlerException("Pre-Processor event did not return 'success'."); - } else { // protect the view normally rendered and redirect to error response view - returnString = returnString.replace(":_protect_:", ""); - if (returnString.length() > 0) { - request.setAttribute("_ERROR_MESSAGE_", returnString); - } - eventReturnString = "protect"; - // check to see if there is an "protect" response, if so it's ok else show the default_error_response_view - if (null == requestManager.getRequestAttribute(requestUri, "protect")) { - nextView = requestManager.getDefaultProtectView(); - if (nextView == null) { - nextView = UtilProperties.getPropertyValue("security.properties", "default.error.response.view"); - } - } + for (ConfigXMLReader.Event event: controllerConfig.preprocessorEventList) { + try { + String returnString = this.runEvent(request, response, event.type, event.path, event.invoke); + if (returnString != null && !returnString.equalsIgnoreCase("success")) { + if (!returnString.contains(":_protect_:")) { + throw new EventHandlerException("Pre-Processor event did not return 'success'."); + } else { // protect the view normally rendered and redirect to error response view + returnString = returnString.replace(":_protect_:", ""); + if (returnString.length() > 0) { + request.setAttribute("_ERROR_MESSAGE_", returnString); } - } else if (returnString == null) { - nextView = "none:"; + eventReturn = "protect"; + // check to see if there is an "protect" response, if so it's ok else show the default_error_response_view + if (!requestMap.requestResponseMap.containsKey("protect")) { + if (controllerConfig.protectView != null) { + overrideViewUri = controllerConfig.protectView; + } else { + overrideViewUri = UtilProperties.getPropertyValue("security.properties", "default.error.response.view"); + } + } } - } catch (EventHandlerException e) { - Debug.logError(e, module); + } else if (returnString == null) { + interruptRequest = true; } + } catch (EventHandlerException e) { + Debug.logError(e, module); } } } // Pre-Processor/First-Visit event(s) can interrupt the flow by returning null. // Warning: this could cause problems if more then one event attempts to return a response. - if ("none:".equals(nextView)) { - if (Debug.infoOn()) Debug.logInfo("[Pre-Processor Interrupted Request, not running: " + requestUri + " sessionId=" + UtilHttp.getSessionId(request), module); + if (interruptRequest) { + if (Debug.infoOn()) Debug.logInfo("[Pre-Processor Interrupted Request, not running: " + requestMap.uri + " sessionId=" + UtilHttp.getSessionId(request), module); return; } - if (Debug.infoOn()) Debug.logInfo("[Processing Request]: " + requestUri + " sessionId=" + UtilHttp.getSessionId(request), module); - request.setAttribute("thisRequestUri", requestUri); // store the actual request URI + if (Debug.infoOn()) Debug.logInfo("[Processing Request]: " + requestMap.uri + " sessionId=" + UtilHttp.getSessionId(request), module); + request.setAttribute("thisRequestUri", requestMap.uri); // store the actual request URI // Perform security check. - if (requestManager.requiresAuth(requestUri)) { + if (requestMap.securityAuth) { // Invoke the security handler // catch exceptions and throw RequestHandlerException if failed. Debug.logVerbose("[RequestHandler]: AuthRequired. Running security check." + " sessionId=" + UtilHttp.getSessionId(request), module); - String checkLoginType = requestManager.getEventType("checkLogin"); - String checkLoginPath = requestManager.getEventPath("checkLogin"); - String checkLoginMethod = requestManager.getEventMethod("checkLogin"); - String checkLoginReturnString; + ConfigXMLReader.Event checkLoginEvent = controllerConfig.requestMapMap.get("checkLogin").event; + String checkLoginReturnString = null; try { - checkLoginReturnString = this.runEvent(request, response, checkLoginType, - checkLoginPath, checkLoginMethod); + checkLoginReturnString = this.runEvent(request, response, checkLoginEvent.type, checkLoginEvent.path, checkLoginEvent.invoke); } catch (EventHandlerException e) { throw new RequestHandlerException(e.getMessage(), e); } if (!"success".equalsIgnoreCase(checkLoginReturnString)) { // previous URL already saved by event, so just do as the return says... - eventReturnString = checkLoginReturnString; - requestUri = "checkLogin"; + eventReturn = checkLoginReturnString; + requestMap = controllerConfig.requestMapMap.get("checkLogin"); } } + + // after security check but before running the event, see if a post-login redirect has completed and we have data from the pre-login request form to use now + // we know this is the case if the _PREVIOUS_PARAM_MAP_ attribute is there, but the _PREVIOUS_REQUEST_ attribute has already been removed + if (request.getSession().getAttribute("_PREVIOUS_PARAM_MAP_FORM_") != null && request.getSession().getAttribute("_PREVIOUS_REQUEST_") == null) { + Map previousParamMap = (Map) request.getSession().getAttribute("_PREVIOUS_PARAM_MAP_FORM_"); + for (Map.Entry previousParamEntry: previousParamMap.entrySet()) { + request.setAttribute(previousParamEntry.getKey(), previousParamEntry.getValue()); + } + // to avoid this data being included again, now remove the _PREVIOUS_PARAM_MAP_ attribute + request.getSession().removeAttribute("_PREVIOUS_PARAM_MAP_FORM_"); + } + + // now we can start looking for the next request response to use + ConfigXMLReader.RequestResponse nextRequestResponse = null; + // Invoke the defined event (unless login failed) - if (eventReturnString == null) { - eventType = requestManager.getEventType(requestUri); - eventPath = requestManager.getEventPath(requestUri); - eventMethod = requestManager.getEventMethod(requestUri); - if (eventType != null && eventPath != null && eventMethod != null) { + if (eventReturn == null && requestMap.event != null) { + if (requestMap.event.type != null && requestMap.event.path != null && requestMap.event.invoke != null) { try { long eventStartTime = System.currentTimeMillis(); - // run the event - eventReturnString = this.runEvent(request, response, eventType, eventPath, eventMethod); + // run the request event + eventReturn = this.runEvent(request, response, requestMap.event.type, requestMap.event.path, requestMap.event.invoke); - // save the server hit + // save the server hit for the request event if (this.trackStats(request)) { - ServerHitBin.countEvent(cname + "." + eventMethod, request, eventStartTime, + ServerHitBin.countEvent(cname + "." + requestMap.event.invoke, request, eventStartTime, System.currentTimeMillis() - eventStartTime, userLogin, delegator); } // set the default event return - if (eventReturnString == null) { - nextView = "none:"; + if (eventReturn == null) { + nextRequestResponse = ConfigXMLReader.emptyNoneRequestResponse; } } catch (EventHandlerException e) { // check to see if there is an "error" response, if so go there and make an request error message - String tryErrorMsg = requestManager.getRequestAttribute(requestUri, "error"); - - if (tryErrorMsg != null) { - eventReturnString = "error"; + if (requestMap.requestResponseMap.containsKey("error")) { + eventReturn = "error"; Locale locale = UtilHttp.getLocale(request); String errMsg = UtilProperties.getMessage(RequestHandler.err_resource, "requestHandler.error_call_event", locale); request.setAttribute("_ERROR_MESSAGE_", errMsg + ": " + e.toString()); @@ -317,35 +337,42 @@ public class RequestHandler implements Serializable { } } } + + // Process the eventReturn + // at this point eventReturnString is finalized, so get the RequestResponse + ConfigXMLReader.RequestResponse eventReturnBasedRequestResponse = eventReturn == null ? null : requestMap.requestResponseMap.get(eventReturn); + if (eventReturnBasedRequestResponse != null) { + //String eventReturnBasedResponse = requestResponse.value; + if (Debug.verboseOn()) Debug.logVerbose("[Response Qualified]: " + eventReturnBasedRequestResponse.name + ", " + eventReturnBasedRequestResponse.type + ":" + eventReturnBasedRequestResponse.value + " sessionId=" + UtilHttp.getSessionId(request), module); - // If error, then display more error messages: - if ("error".equals(eventReturnString)) { - if (Debug.errorOn()) { - String errorMessageHeader = "Request " + requestUri + " caused an error with the following message: "; - if (request.getAttribute("_ERROR_MESSAGE_") != null) { - Debug.logError(errorMessageHeader + request.getAttribute("_ERROR_MESSAGE_"), module); - } - if (request.getAttribute("_ERROR_MESSAGE_LIST_") != null) { - Debug.logError(errorMessageHeader + request.getAttribute("_ERROR_MESSAGE_LIST_"), module); + // If error, then display more error messages: + if ("error".equals(eventReturnBasedRequestResponse.name)) { + if (Debug.errorOn()) { + String errorMessageHeader = "Request " + requestMap.uri + " caused an error with the following message: "; + if (request.getAttribute("_ERROR_MESSAGE_") != null) { + Debug.logError(errorMessageHeader + request.getAttribute("_ERROR_MESSAGE_"), module); + } + if (request.getAttribute("_ERROR_MESSAGE_LIST_") != null) { + Debug.logError(errorMessageHeader + request.getAttribute("_ERROR_MESSAGE_LIST_"), module); + } } } + } else { + Debug.logWarning("Could not find response in request [" + requestMap.uri + "] for event return [" + eventReturn + "]", module); } - // Process the eventReturn. - String eventReturnBasedResponse = requestManager.getRequestResponseValue(requestUri, eventReturnString); - if (Debug.verboseOn()) Debug.logVerbose("[Response Qualified]: " + eventReturnBasedResponse + " sessionId=" + UtilHttp.getSessionId(request), module); - // Set the next view (don't use event return if success, default to nextView (which is set to eventReturn later if null); also even if success if it is a type "none" response ignore the nextView, ie use the eventReturn) - if (eventReturnBasedResponse != null && (!"success".equals(eventReturnString) || eventReturnBasedResponse.startsWith("none:"))) nextView = eventReturnBasedResponse; - if (Debug.verboseOn()) Debug.logVerbose("[Event Response Mapping]: " + nextView + " sessionId=" + UtilHttp.getSessionId(request), module); + if (eventReturnBasedRequestResponse != null && (!"success".equals(eventReturnBasedRequestResponse.name) || "none".equals(eventReturnBasedRequestResponse.type))) nextRequestResponse = eventReturnBasedRequestResponse; // get the previous request info String previousRequest = (String) request.getSession().getAttribute("_PREVIOUS_REQUEST_"); String loginPass = (String) request.getAttribute("_LOGIN_PASSED_"); - + // restore previous redirected request's attribute, so redirected page can display previous request's error msg etc. String preReqAttStr = (String) request.getSession().getAttribute("_REQ_ATTR_MAP_"); + Map previousRequestAttrMap = null; if (preReqAttStr != null) { + previousRequestAttrMap = FastMap.newInstance(); request.getSession().removeAttribute("_REQ_ATTR_MAP_"); byte[] reqAttrMapBytes = StringUtil.fromHexString(preReqAttStr); Map preRequestMap = checkMap(UtilObject.getObject(reqAttrMapBytes), String.class, Object.class); @@ -355,6 +382,7 @@ public class RequestHandler implements Serializable { if("_ERROR_MESSAGE_LIST_".equals(key) || "_ERROR_MESSAGE_MAP_".equals(key) || "_ERROR_MESSAGE_".equals(key) || "_EVENT_MESSAGE_LIST_".equals(key) || "_EVENT_MESSAGE_".equals(key)) { request.setAttribute(key, entry.getValue()); + previousRequestAttrMap.put(key, entry.getValue()); } } } @@ -370,86 +398,90 @@ public class RequestHandler implements Serializable { Debug.logWarning("Found special _PREVIOUS_REQUEST_ of [" + previousRequest + "], setting to null to avoid problems, not running request again", module); } else { if (Debug.infoOn()) Debug.logInfo("[Doing Previous Request]: " + previousRequest + " sessionId=" + UtilHttp.getSessionId(request), module); - doRequest(request, response, previousRequest, userLogin, delegator); - return; // this is needed or else we will run the view twice + + // note that the previous form parameters are not setup (only the URL ones here), they will be found in the session later and handled when the old request redirect comes back + Map previousParamMap = (Map) request.getSession().getAttribute("_PREVIOUS_PARAM_MAP_URL_"); + String queryString = UtilHttp.urlEncodeArgs(previousParamMap, false); + String redirectTarget = previousRequest; + if (UtilValidate.isNotEmpty(queryString)) { + redirectTarget += "?" + queryString; + } + callRedirect(makeLink(request, response, redirectTarget), response, request); + + // the old/uglier way: doRequest(request, response, previousRequest, userLogin, delegator); + + // this is needed as the request handled will be taking care of the view, etc + return; } } - String successView = requestManager.getViewName(requestUri); - if ("success".equals(eventReturnString) && successView.startsWith("request:")) { + ConfigXMLReader.RequestResponse successResponse = requestMap.requestResponseMap.get("success"); + if ("success".equals(eventReturn) && successResponse != null && "request".equals(successResponse.type)) { // chains will override any url defined views; but we will save the view for the very end - if (nextView != null) { - request.setAttribute("_POST_CHAIN_VIEW_", nextView); + if (nextRequestResponse != null) { + // NOTE: possible issue if nextRequestResponse.type != view + request.setAttribute("_POST_CHAIN_VIEW_", nextRequestResponse.value); } - nextView = successView; + nextRequestResponse = successResponse; } // Make sure we have some sort of response to go to - if (nextView == null) nextView = successView; - if (Debug.verboseOn()) Debug.logVerbose("[Current View]: " + nextView + " sessionId=" + UtilHttp.getSessionId(request), module); + if (nextRequestResponse == null) nextRequestResponse = successResponse; + + if (nextRequestResponse == null) { + throw new RequestHandlerException("Illegal response; handler could not process request [" + requestMap.uri + "] and event return [" + eventReturn + "]."); + } + + if (Debug.verboseOn()) Debug.logVerbose("[Event Response Selected] type=" + nextRequestResponse.type + ", value=" + nextRequestResponse.value + ", sessionId=" + UtilHttp.getSessionId(request), module); // Handle the responses - chains/views - if (nextView != null && nextView.startsWith("request:")) { + if (nextRequestResponse != null && "request".equals(nextRequestResponse.type)) { // chained request Debug.logInfo("[RequestHandler.doRequest]: Response is a chained request." + " sessionId=" + UtilHttp.getSessionId(request), module); - nextView = nextView.substring(8); - doRequest(request, response, nextView, userLogin, delegator); - } else { // handle views + doRequest(request, response, nextRequestResponse.value, userLogin, delegator); + } else { + // ======== handle views ======== + // first invoke the post-processor events. - Collection> postProcEvents = requestManager.getPostProcessor(); - if (chain == null && postProcEvents != null) { // don't run post-proc events on chained requests - for (Map eventMap: postProcEvents) { - String eType = eventMap.get(ConfigXMLReader.EVENT_TYPE); - String ePath = eventMap.get(ConfigXMLReader.EVENT_PATH); - String eMeth = eventMap.get(ConfigXMLReader.EVENT_METHOD); - try { - String returnString = this.runEvent(request, response, eType, ePath, eMeth); - if (returnString != null && !returnString.equalsIgnoreCase("success")) - throw new EventHandlerException("Post-Processor event did not return 'success'."); - else if (returnString == null) - nextView = "none:"; - } catch (EventHandlerException e) { - Debug.logError(e, module); + for (ConfigXMLReader.Event event: this.controllerConfig.postprocessorEventList) { + try { + String returnString = this.runEvent(request, response, event.type, event.path, event.invoke); + if (returnString != null && !returnString.equalsIgnoreCase("success")) { + throw new EventHandlerException("Post-Processor event did not return 'success'."); } + } catch (EventHandlerException e) { + Debug.logError(e, module); } } - if (nextView != null && nextView.startsWith("url:")) { + if ("url".equals(nextRequestResponse.type)) { // check for a url for redirection Debug.logInfo("[RequestHandler.doRequest]: Response is a URL redirect." + " sessionId=" + UtilHttp.getSessionId(request), module); - nextView = nextView.substring(4); - callRedirect(nextView, response, request); - } else if (nextView != null && nextView.startsWith("cross-redirect:")) { + callRedirect(nextRequestResponse.value, response, request); + } else if ("cross-redirect".equals(nextRequestResponse.type)) { // check for a cross-application redirect Debug.logInfo("[RequestHandler.doRequest]: Response is a Cross-Application redirect." + " sessionId=" + UtilHttp.getSessionId(request), module); - nextView = nextView.substring(15); - String url = nextView.startsWith("/") ? nextView : "/" + nextView; - callRedirect(url + this.makeQueryString(request), response, request); - } else if (nextView != null && nextView.startsWith("request-redirect:")) { + String url = nextRequestResponse.value.startsWith("/") ? nextRequestResponse.value : "/" + nextRequestResponse.value; + callRedirect(url + this.makeQueryString(request, nextRequestResponse), response, request); + } else if ("request-redirect".equals(nextRequestResponse.type)) { // check for a Request redirect Debug.logInfo("[RequestHandler.doRequest]: Response is a Request redirect." + " sessionId=" + UtilHttp.getSessionId(request), module); - nextView = nextView.substring(17); - callRedirect(makeLinkWithQueryString(request, response, "/" + nextView), response, request); - } else if (nextView != null && nextView.startsWith("request-redirect-noparam:")) { + callRedirect(makeLinkWithQueryString(request, response, "/" + nextRequestResponse.value, nextRequestResponse), response, request); + } else if ("request-redirect-noparam".equals(nextRequestResponse.type)) { // check for a Request redirect Debug.logInfo("[RequestHandler.doRequest]: Response is a Request redirect with no parameters." + " sessionId=" + UtilHttp.getSessionId(request), module); - nextView = nextView.substring(25); - callRedirect(makeLink(request, response, nextView), response, request); - } else if (nextView != null && nextView.startsWith("view:")) { + callRedirect(makeLink(request, response, nextRequestResponse.value), response, request); + } else if ("view".equals(nextRequestResponse.type)) { // check for a View Debug.logInfo("[RequestHandler.doRequest]: Response is a view." + " sessionId=" + UtilHttp.getSessionId(request), module); - nextView = nextView.substring(5); - renderView(nextView, requestManager.allowExtView(requestUri), request, response); - } else if (nextView != null && nextView.startsWith("none:")) { + + // check for an override view, only used if "success" = eventReturn + String viewName = (UtilValidate.isNotEmpty(overrideViewUri) && "success".equals(eventReturn)) ? overrideViewUri : nextRequestResponse.value; + + renderView(viewName, requestMap.securityExternalView, request, response); + } else if ("none".equals(nextRequestResponse.type)) { // check for a no dispatch return (meaning the return was processed by the event Debug.logInfo("[RequestHandler.doRequest]: Response is handled by the event." + " sessionId=" + UtilHttp.getSessionId(request), module); - } else if (nextView != null) { - // a page request - Debug.logInfo("[RequestHandler.doRequest]: Response is a page [" + nextView + "]" + " sessionId=" + UtilHttp.getSessionId(request), module); - renderView(nextView, requestManager.allowExtView(requestUri), request, response); - } else { - // unknown request - throw new RequestHandlerException("Illegal response; handler could not process [" + eventReturnString + "]."); } } } @@ -463,35 +495,8 @@ public class RequestHandler implements Serializable { /** Returns the default error page for this request. */ public String getDefaultErrorPage(HttpServletRequest request) { - //String requestUri = RequestHandler.getRequestUri(request.getPathInfo()); - //return requestManager.getErrorPage(requestUri); - return requestManager.getDefaultErrorPage(); - } - - public String makeQueryString(HttpServletRequest request) { - Map paramMap = UtilHttp.getParameterMap(request); - StringBuilder queryString = new StringBuilder(); - if (UtilValidate.isNotEmpty(paramMap)) { - queryString.append("?"); - for (Map.Entry entry: paramMap.entrySet()) { - String name = entry.getKey(); - Object value = entry.getValue(); - if (value instanceof String) { - if (queryString.length() > 1) { - queryString.append("&"); - } - queryString.append(name); - queryString.append("="); - queryString.append(value); - } - } - } - return queryString.toString(); - } - - /** Returns the RequestManager Object. */ - public RequestManager getRequestManager() { - return requestManager; + if (controllerConfig.errorpage != null) return controllerConfig.errorpage; + return "/error/error.jsp"; } /** Returns the ServletContext Object. */ @@ -522,20 +527,20 @@ public class RequestHandler implements Serializable { } } - public static String getNextPageUri(String path) { - List pathInfo = StringUtil.split(path, "/"); - if (pathInfo == null) { + public static String getOverrideViewUri(String path) { + List pathItemList = StringUtil.split(path, "/"); + if (pathItemList == null) { return null; } - pathInfo = pathInfo.subList(1, pathInfo.size()); + pathItemList = pathItemList.subList(1, pathItemList.size()); String nextPage = null; - for (String element: pathInfo) { - if (element.indexOf('~') != 0) { - if (element.indexOf('?') > -1) { - element = element.substring(0, element.indexOf('?')); + for (String pathItem: pathItemList) { + if (pathItem.indexOf('~') != 0) { + if (pathItem.indexOf('?') > -1) { + pathItem = pathItem.substring(0, pathItem.indexOf('?')); } - nextPage = (nextPage == null ? element : nextPage + "/" + element); + nextPage = (nextPage == null ? pathItem : nextPage + "/" + pathItem); } } return nextPage; @@ -599,18 +604,21 @@ public class RequestHandler implements Serializable { // before mapping the view, set a session attribute so we know where we are req.setAttribute("_CURRENT_VIEW_", view); - String viewType = requestManager.getViewType(view); - String tempView = requestManager.getViewPage(view); + ConfigXMLReader.ViewMap viewMap = view == null ? null : controllerConfig.viewMapMap.get(view); + if (viewMap == null) { + throw new RequestHandlerException("No defitinition found for view with name [" + view + "]"); + } + String nextPage; - if (tempView == null) { + if (viewMap.page == null) { if (!allowExtView) { throw new RequestHandlerException("No view to render."); } else { nextPage = "/" + oldView; } } else { - nextPage = tempView; + nextPage = viewMap.page; } if (Debug.verboseOn()) Debug.logVerbose("[Mapped To]: " + nextPage + " sessionId=" + UtilHttp.getSessionId(req), module); @@ -618,10 +626,9 @@ public class RequestHandler implements Serializable { long viewStartTime = System.currentTimeMillis(); // setup chararcter encoding and content type - String charset = UtilFormatOut.checkEmpty(getServletContext().getInitParameter("charset"), - req.getCharacterEncoding(), "UTF-8"); + String charset = UtilFormatOut.checkEmpty(getServletContext().getInitParameter("charset"), req.getCharacterEncoding(), "UTF-8"); - String viewCharset = requestManager.getViewEncoding(view); + String viewCharset = this.controllerConfig.viewMapMap.get(view).encoding; //NOTE: if the viewCharset is "none" then no charset will be used if (UtilValidate.isNotEmpty(viewCharset)) { charset = viewCharset; @@ -639,7 +646,7 @@ public class RequestHandler implements Serializable { // setup content type String contentType = "text/html"; - String viewContentType = requestManager.getViewContentType(view); + String viewContentType = viewMap.contentType; if (UtilValidate.isNotEmpty(viewContentType)) { contentType = viewContentType; } @@ -653,9 +660,9 @@ public class RequestHandler implements Serializable { if (Debug.verboseOn()) Debug.logVerbose("The ContentType for the " + view + " view is: " + contentType, module); try { - if (Debug.verboseOn()) Debug.logVerbose("Rendering view [" + nextPage + "] of type [" + viewType + "]", module); - ViewHandler vh = viewFactory.getViewHandler(viewType); - vh.render(view, nextPage, requestManager.getViewInfo(view), contentType, charset, req, resp); + if (Debug.verboseOn()) Debug.logVerbose("Rendering view [" + nextPage + "] of type [" + viewMap.type + "]", module); + ViewHandler vh = viewFactory.getViewHandler(viewMap.type); + vh.render(view, nextPage, viewMap.info, contentType, charset, req, resp); } catch (ViewHandlerException e) { Throwable throwable = e.getNested() != null ? e.getNested() : e; @@ -713,10 +720,48 @@ public class RequestHandler implements Serializable { return newURL.toString(); } + + /** + * Creates a query string based on the redirect parameters for a request response, if specified, or for all request parameters if no redirect parameters are specified. + * + * @param request + * @param requestUri + * @param eventReturnString + * @return + */ + public String makeQueryString(HttpServletRequest request, ConfigXMLReader.RequestResponse requestResponse) { + if (requestResponse == null || requestResponse.redirectParameterMap.size() == 0) { + Map urlParams = UtilHttp.getUrlOnlyParameterMap(request); + String queryString = UtilHttp.urlEncodeArgs(urlParams, false); + return queryString; + } else { + StringBuilder queryString = new StringBuilder(); + queryString.append("?"); + for (Map.Entry entry: requestResponse.redirectParameterMap.entrySet()) { + String name = entry.getKey(); + String from = entry.getValue(); + + Object value = request.getAttribute(from); + if (value == null) { + value = request.getParameter(from); + } + + if (UtilValidate.isNotEmpty(value)) { + if (queryString.length() > 1) { + queryString.append("&"); + } + queryString.append(name); + queryString.append("="); + queryString.append(value); + } + } + return queryString.toString(); + } + } - public String makeLinkWithQueryString(HttpServletRequest request, HttpServletResponse response, String url) { + public String makeLinkWithQueryString(HttpServletRequest request, HttpServletResponse response, String url, ConfigXMLReader.RequestResponse requestResponse) { String initialLink = this.makeLink(request, response, url); - String queryString = this.makeQueryString(request); + String queryString = this.makeQueryString(request, requestResponse); return initialLink + queryString; } @@ -772,12 +817,15 @@ public class RequestHandler implements Serializable { String controlPath = (String) request.getAttribute("_CONTROL_PATH_"); String requestUri = RequestHandler.getRequestUri(url); + ConfigXMLReader.RequestMap requestMap = controllerConfig.requestMapMap.get(requestUri); + StringBuilder newURL = new StringBuilder(); boolean didFullSecure = false; boolean didFullStandard = false; - if (enableHttps || fullPath || secure) { - if (secure || (enableHttps && requestManager.requiresHttps(requestUri) && !request.isSecure())) { + if (requestMap != null && (enableHttps || fullPath || secure)) { + if (Debug.verboseOn()) Debug.logVerbose("In makeLink requestUri=" + requestUri, module); + if (secure || (enableHttps && requestMap.securityHttps && !request.isSecure())) { String server = httpsServer; if (UtilValidate.isEmpty(server)) { server = request.getServerName(); @@ -790,7 +838,7 @@ public class RequestHandler implements Serializable { } didFullSecure = true; - } else if (fullPath || (enableHttps && !requestManager.requiresHttps(requestUri) && request.isSecure())) { + } else if (fullPath || (enableHttps && !requestMap.securityHttps && request.isSecure())) { String server = httpServer; if (UtilValidate.isEmpty(server)) { server = request.getServerName(); @@ -873,39 +921,27 @@ public class RequestHandler implements Serializable { } public void runAfterLoginEvents(HttpServletRequest request, HttpServletResponse response) { - List> afterLoginEvents = requestManager.getAfterLoginEventList(); - if (afterLoginEvents != null) { - for (Map eventMap: afterLoginEvents) { - String eType = eventMap.get(ConfigXMLReader.EVENT_TYPE); - String ePath = eventMap.get(ConfigXMLReader.EVENT_PATH); - String eMeth = eventMap.get(ConfigXMLReader.EVENT_METHOD); - try { - String returnString = this.runEvent(request, response, eType, ePath, eMeth); - if (returnString != null && !returnString.equalsIgnoreCase("success")) { - throw new EventHandlerException("Pre-Processor event did not return 'success'."); - } - } catch (EventHandlerException e) { - Debug.logError(e, module); + for (ConfigXMLReader.Event event: this.controllerConfig.afterLoginEventList) { + try { + String returnString = this.runEvent(request, response, event.type, event.path, event.invoke); + if (returnString != null && !returnString.equalsIgnoreCase("success")) { + throw new EventHandlerException("Pre-Processor event did not return 'success'."); } + } catch (EventHandlerException e) { + Debug.logError(e, module); } } } public void runBeforeLogoutEvents(HttpServletRequest request, HttpServletResponse response) { - List> beforeLogoutEvents = requestManager.getBeforeLogoutEventList(); - if (beforeLogoutEvents != null) { - for (Map eventMap: beforeLogoutEvents) { - String eType = eventMap.get(ConfigXMLReader.EVENT_TYPE); - String ePath = eventMap.get(ConfigXMLReader.EVENT_PATH); - String eMeth = eventMap.get(ConfigXMLReader.EVENT_METHOD); - try { - String returnString = this.runEvent(request, response, eType, ePath, eMeth); - if (returnString != null && !returnString.equalsIgnoreCase("success")) { - throw new EventHandlerException("Pre-Processor event did not return 'success'."); - } - } catch (EventHandlerException e) { - Debug.logError(e, module); + for (ConfigXMLReader.Event event: this.controllerConfig.beforeLogoutEventList) { + try { + String returnString = this.runEvent(request, response, event.type, event.path, event.invoke); + if (returnString != null && !returnString.equalsIgnoreCase("success")) { + throw new EventHandlerException("Pre-Processor event did not return 'success'."); } + } catch (EventHandlerException e) { + Debug.logError(e, module); } } } @@ -913,7 +949,7 @@ public class RequestHandler implements Serializable { public boolean trackStats(HttpServletRequest request) { if (!"false".equalsIgnoreCase(context.getInitParameter("track-serverhit"))) { String uriString = RequestHandler.getRequestUri(request.getPathInfo()); - return !"false".equalsIgnoreCase(requestManager.getRequestAttribute(uriString, ConfigXMLReader.REQUEST_TRACK_STATS)); + return controllerConfig.requestMapMap.get(uriString).trackServerHit; } else { return false; } @@ -922,7 +958,7 @@ public class RequestHandler implements Serializable { public boolean trackVisit(HttpServletRequest request) { if (!"false".equalsIgnoreCase(context.getInitParameter("track-visit"))) { String uriString = RequestHandler.getRequestUri(request.getPathInfo()); - return !"false".equalsIgnoreCase(requestManager.getRequestAttribute(uriString, ConfigXMLReader.REQUEST_TRACK_VISIT)); + return controllerConfig.requestMapMap.get(uriString).trackVisit; } else { return false; } diff --git a/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java b/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java deleted file mode 100644 index c1b84ab431..0000000000 --- a/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java +++ /dev/null @@ -1,395 +0,0 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.webapp.control; - -import java.io.Serializable; -import java.net.URL; -import java.net.MalformedURLException; -import java.util.Collection; -import java.util.Map; -import java.util.List; -import javax.servlet.ServletContext; - -import javolution.util.FastList; - -import org.ofbiz.base.util.Debug; -import static org.ofbiz.base.util.UtilGenerics.checkMap; -import org.ofbiz.base.util.UtilValidate; - -/** - * RequestManager - Manages request, config and view mappings. - */ -public class RequestManager implements Serializable { - - public static final String module = RequestManager.class.getName(); - public static final int VIEW_HANDLER_KEY = 1; - public static final int EVENT_HANDLER_KEY = 0; - - private URL configFileUrl; - private URL webInfUrl; - - public RequestManager(ServletContext context) { - - /** Loads the site configuration from servlet context parameter. */ - try { - configFileUrl = context.getResource("/WEB-INF/controller.xml"); - webInfUrl = context.getResource("/WEB-INF"); - } catch (Exception e) { - Debug.logError(e, "[RequestManager.constructor] Error Finding XML Config File: " + - "/WEB-INF/controller.xml", module); - } - // do quick inits: - ConfigXMLReader.getConfigMap(configFileUrl); - ConfigXMLReader.getHandlerMap(configFileUrl); - ConfigXMLReader.getRequestMap(configFileUrl); - ConfigXMLReader.getViewMap(configFileUrl); - } - - /** Gets the entire handler mapping */ - public Map> getHandlerMap() { - return ConfigXMLReader.getHandlerMap(configFileUrl); - } - - /** Gets the class name of the named handler */ - public String getHandlerClass(String name, int type) { - Map> map = getHandlerMap(); - Map hMap; - - if (type == RequestManager.VIEW_HANDLER_KEY) { - hMap = checkMap(map.get("view"), String.class, String.class); - } else { - hMap = checkMap(map.get("event"), String.class, String.class); - } - - if (!hMap.containsKey(name)) { - return null; - } else { - return hMap.get(name); - } - } - - public List getHandlerKeys(int type) { - Map> map = getHandlerMap(); - Map hMap; - - if (type == RequestManager.VIEW_HANDLER_KEY) { - hMap = checkMap(map.get("view"), String.class, String.class); - } else { - hMap = checkMap(map.get("event"), String.class, String.class); - } - - if (hMap != null) { - List result = FastList.newInstance(); - result.addAll(hMap.keySet()); - return result; - } else { - return null; - } - } - - public Map getRequestMapMap(String uriStr) { - if (UtilValidate.isNotEmpty(uriStr)) { - return ConfigXMLReader.getRequestMap(configFileUrl).get(uriStr); - } else { - return null; - } - } - - public String getRequestAttribute(String uriStr, String attribute) { - Map uri = getRequestMapMap(uriStr); - - if (uri != null && attribute != null) { - String value = (String) uri.get(attribute); - if (value == null) { - // not found, try the response Map (though better to hit that directly when desired) - Map responseMap = checkMap(uri.get(ConfigXMLReader.RESPONSE_MAP), String.class, String.class); - value = responseMap.get(attribute); - } - return value; - } else { - Debug.logInfo("[RequestManager.getRequestAttribute] Value for attribute \"" + attribute + - "\" of uri \"" + uriStr + "\" not found", module); - return null; - } - } - - public String getRequestResponseValue(String uriStr, String responseName) { - if (responseName == null) return null; - - Map uri = getRequestMapMap(uriStr); - if (uri == null) return null; - Map responseMap = checkMap(uri.get(ConfigXMLReader.RESPONSE_MAP), String.class, String.class); - if (responseMap == null) return null; - - return responseMap.get(responseName); - } - - /** Gets the event class from the requestMap */ - public String getEventPath(String uriStr) { - Map uri = getRequestMapMap(uriStr); - - if (uri != null) - return (String) uri.get(ConfigXMLReader.EVENT_PATH); - else { - Debug.logWarning("[RequestManager.getEventPath] Path of event for request \"" + uriStr + - "\" not found", module); - return null; - } - } - - /** Gets the event type from the requestMap */ - public String getEventType(String uriStr) { - Map uri = getRequestMapMap(uriStr); - - if (uri != null) - return (String) uri.get(ConfigXMLReader.EVENT_TYPE); - else { - Debug.logWarning("[RequestManager.getEventType] Type of event for request \"" + uriStr + - "\" not found", module); - return null; - } - } - - /** Gets the event method from the requestMap */ - public String getEventMethod(String uriStr) { - Map uri = getRequestMapMap(uriStr); - - if (uri != null) { - return (String) uri.get(ConfigXMLReader.EVENT_METHOD); - } else { - Debug.logWarning("[RequestManager.getEventMethod] Method of event for request \"" + - uriStr + "\" not found", module); - return null; - } - } - - /** Gets the event global-transaction from the requestMap */ - public boolean getEventGlobalTransaction(String uriStr) { - Map uri = getRequestMapMap(uriStr); - - if (uri != null) { - return Boolean.valueOf((String) uri.get(ConfigXMLReader.EVENT_GLOBAL_TRANSACTION)).booleanValue(); - } else { - if (Debug.verboseOn()) { - Debug.logWarning("[RequestManager.getEventGlobalTransaction] Global-transaction of event for request \"" + - uriStr + "\" not found, defaulting to true", module); - } - return false; - } - } - - /** Gets the view name from the requestMap */ - public String getViewName(String uriStr) { - Map uri = getRequestMapMap(uriStr); - - if (uri != null) - return checkMap(uri.get(ConfigXMLReader.RESPONSE_MAP), String.class, String.class).get(ConfigXMLReader.NEXT_PAGE_DEFAULT); - else { - Debug.logWarning("[RequestManager.getViewName] View name for uri \"" + uriStr + "\" not found", module); - return null; - } - } - - /** Gets the next page (jsp) from the viewMap */ - public String getViewPage(String viewStr) { - if (viewStr != null && viewStr.startsWith("view:")) viewStr = viewStr.substring(viewStr.indexOf(':') + 1); - Map page = ConfigXMLReader.getViewMap(configFileUrl).get(viewStr); - - if (page != null) { - return page.get(ConfigXMLReader.VIEW_PAGE); - } else { - Debug.logWarning("[RequestManager.getViewPage] View with name \"" + viewStr + "\" not found", module); - return null; - } - } - - /** Gets the type of this view */ - public String getViewType(String viewStr) { - Map view = ConfigXMLReader.getViewMap(configFileUrl).get(viewStr); - - if (view != null) { - return view.get(ConfigXMLReader.VIEW_TYPE); - } else { - Debug.logWarning("[RequestManager.getViewType] View with name \"" + viewStr + "\" not found", module); - return null; - } - } - - /** Gets the info of this view */ - public String getViewInfo(String viewStr) { - Map view = ConfigXMLReader.getViewMap(configFileUrl).get(viewStr); - - if (view != null) { - return view.get(ConfigXMLReader.VIEW_INFO); - } else { - Debug.logWarning("[RequestManager.getViewInfo] View with name \"" + viewStr + "\" not found", module); - return null; - } - } - - /** Gets the content-type of this view */ - public String getViewContentType(String viewStr) { - Map view = ConfigXMLReader.getViewMap(configFileUrl).get(viewStr); - - if (view != null) { - return view.get(ConfigXMLReader.VIEW_CONTENT_TYPE); - } else { - Debug.logWarning("[RequestManager.getViewInfo] View with name \"" + viewStr + "\" not found", module); - return null; - } - } - - /** Gets the content-type of this view */ - public String getViewEncoding(String viewStr) { - Map view = (Map) ConfigXMLReader.getViewMap(configFileUrl).get(viewStr); - - if (view != null) { - return (String) view.get(ConfigXMLReader.VIEW_ENCODING); - } else { - Debug.logWarning("[RequestManager.getViewInfo] View with name \"" + viewStr + "\" not found", module); - return null; - } - } - - /** Gets the error page from the requestMap, if none uses the default */ - public String getErrorPage(String uriStr) { - //Debug.logInfo("uriStr is: " + uriStr, module); - Map uri = getRequestMapMap(uriStr); - //Debug.logInfo("RequestMapMap is: " + uri, module); - - if (uri != null) { - String errorViewUri = checkMap(uri.get(ConfigXMLReader.RESPONSE_MAP), String.class, String.class).get(ConfigXMLReader.ERROR_PAGE_DEFAULT); - //Debug.logInfo("errorViewUri is: " + errorViewUri, module); - String returnPage = getViewPage(errorViewUri); - //Debug.logInfo("Got returnPage for ErrorPage: " + returnPage, module); - - if (returnPage != null) { - return returnPage; - } else { - return getDefaultErrorPage(); - } - } else { - return getDefaultErrorPage(); - } - } - - /** Gets the default error page from the configMap or static site default */ - public String getDefaultErrorPage() { - String errorPage; - errorPage = (String) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.DEFAULT_ERROR_PAGE); - //Debug.logInfo("For DefaultErrorPage got errorPage: " + errorPage, module); - if (errorPage != null) return errorPage; - return "/error/error.jsp"; - } - - /** Gets the default "protect" view; used when no "protect" response type and :_protect_: is used */ - public String getDefaultProtectView() { - return (String) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.DEFAULT_PROTECT_VIEW); - } - - public boolean requiresAuth(String uriStr) { - Map uri = getRequestMapMap(uriStr); - - if (uri != null) { - String value = (String) uri.get(ConfigXMLReader.SECURITY_AUTH); - - //if (Debug.verboseOn()) Debug.logVerbose("Require Auth: " + value, module); - return "true".equalsIgnoreCase(value); - } else - return false; - } - - public boolean requiresHttps(String uriStr) { - Map uri = getRequestMapMap(uriStr); - - if (uri != null) { - String value = (String) uri.get(ConfigXMLReader.SECURITY_HTTPS); - - //if (Debug.verboseOn()) Debug.logVerbose("Requires HTTPS: " + value, module); - return "true".equalsIgnoreCase(value); - } else - return false; - } - - public boolean requiresHttpsClientCert(String uriStr) { - Map uri = getRequestMapMap(uriStr); - - if (uri != null) { - String value = (String) uri.get(ConfigXMLReader.SECURITY_CERT); - - //if (Debug.verboseOn()) Debug.logVerbose("Requires x.509 Cert: " + value, module); - return "true".equalsIgnoreCase(value); - } else - return false; - - } - - public boolean allowExtView(String uriStr) { - Map uri = getRequestMapMap(uriStr); - - if (uri != null) { - String value = (String) uri.get(ConfigXMLReader.SECURITY_EXTVIEW); - - //if (Debug.verboseOn()) Debug.logVerbose("Allow External View: " + value, module); - return !"false".equalsIgnoreCase(value); - } else - return true; - } - - public boolean allowDirectRequest(String uriStr) { - Map uri = getRequestMapMap(uriStr); - - if (uri != null) { - String value = (String) uri.get(ConfigXMLReader.SECURITY_DIRECT); - - //if (Debug.verboseOn()) Debug.logVerbose("Allow Direct Request: " + value, module); - return !"false".equalsIgnoreCase(value); - } else - return false; - } - - public String getDefaultRequest() { - return ConfigXMLReader.getDefaultRequest(configFileUrl); - } - - @SuppressWarnings("unchecked") - public Collection> getFirstVisitEvents() { - return (Collection>) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.FIRSTVISIT); - } - - @SuppressWarnings("unchecked") - public Collection> getPreProcessor() { - return (Collection>) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.PREPROCESSOR); - } - - @SuppressWarnings("unchecked") - public Collection> getPostProcessor() { - return (Collection>) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.POSTPROCESSOR); - } - - @SuppressWarnings("unchecked") - public List> getAfterLoginEventList() { - return (List>) ConfigXMLReader.getConfigMap(configFileUrl).get("after-login"); - } - - @SuppressWarnings("unchecked") - public List> getBeforeLogoutEventList() { - return (List>) ConfigXMLReader.getConfigMap(configFileUrl).get("before-logout"); - } -} diff --git a/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java b/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java index 8876edc5b2..88df6446c8 100644 --- a/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java +++ b/framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java @@ -18,6 +18,9 @@ *******************************************************************************/ package org.ofbiz.webapp.event; +import static org.ofbiz.base.util.UtilGenerics.checkCollection; +import static org.ofbiz.base.util.UtilGenerics.checkMap; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -28,7 +31,6 @@ import java.util.Date; import java.util.Iterator; import java.util.Locale; import java.util.Map; -import java.util.Set; import java.util.TimeZone; import javax.servlet.http.HttpServletRequest; @@ -38,8 +40,6 @@ import javax.servlet.http.HttpSession; import javolution.util.FastMap; import org.ofbiz.base.util.Debug; -import static org.ofbiz.base.util.UtilGenerics.checkCollection; -import static org.ofbiz.base.util.UtilGenerics.checkMap; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; @@ -566,7 +566,7 @@ public class CoreEvents { public static String streamFile(HttpServletRequest request, HttpServletResponse response) { //RequestHandler rh = (RequestHandler) request.getAttribute("_REQUEST_HANDLER_"); - String filePath = RequestHandler.getNextPageUri(request.getPathInfo()); + String filePath = RequestHandler.getOverrideViewUri(request.getPathInfo()); //String fileName = filePath.substring(filePath.lastIndexOf("/")+1); // load the file diff --git a/framework/webapp/src/org/ofbiz/webapp/event/EventFactory.java b/framework/webapp/src/org/ofbiz/webapp/event/EventFactory.java index 6a8adc0e92..d63685bb93 100644 --- a/framework/webapp/src/org/ofbiz/webapp/event/EventFactory.java +++ b/framework/webapp/src/org/ofbiz/webapp/event/EventFactory.java @@ -18,8 +18,9 @@ *******************************************************************************/ package org.ofbiz.webapp.event; -import java.util.List; import java.util.Map; +import java.util.Set; + import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -29,8 +30,8 @@ import javolution.util.FastMap; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralRuntimeException; import org.ofbiz.base.util.ObjectType; +import org.ofbiz.webapp.control.ConfigXMLReader; import org.ofbiz.webapp.control.RequestHandler; -import org.ofbiz.webapp.control.RequestManager; /** * EventFactory - Event Handler Factory @@ -40,14 +41,12 @@ public class EventFactory { public static final String module = EventFactory.class.getName(); protected RequestHandler requestHandler = null; - protected RequestManager requestManager = null; protected ServletContext context = null; protected Map handlers = null; public EventFactory(RequestHandler requestHandler) { handlers = FastMap.newInstance(); this.requestHandler = requestHandler; - this.requestManager = requestHandler.getRequestManager(); this.context = requestHandler.getServletContext(); // pre-load all event handlers @@ -60,7 +59,7 @@ public class EventFactory { } private void preLoadAll() throws EventHandlerException { - List handlers = requestManager.getHandlerKeys(RequestManager.EVENT_HANDLER_KEY); + Set handlers = this.requestHandler.getControllerConfig().eventHandlerMap.keySet(); if (handlers != null) { for (String type: handlers) { this.handlers.put(type, this.loadEventHandler(type)); @@ -97,7 +96,7 @@ public class EventFactory { private EventHandler loadEventHandler(String type) throws EventHandlerException { EventHandler handler = null; - String handlerClass = requestManager.getHandlerClass(type, RequestManager.EVENT_HANDLER_KEY); + String handlerClass = this.requestHandler.getControllerConfig().eventHandlerMap.get(type); if (handlerClass == null) { throw new EventHandlerException("Unknown handler type: " + type); } @@ -121,10 +120,8 @@ public class EventFactory { throws EventHandlerException { ServletContext application = ((ServletContext) request.getAttribute("servletContext")); RequestHandler handler = (RequestHandler) application.getAttribute("_REQUEST_HANDLER_"); - RequestManager rm = handler.getRequestManager(); - String eventType = rm.getEventType(requestUri); - String eventPath = rm.getEventPath(requestUri); - String eventMethod = rm.getEventMethod(requestUri); - return handler.runEvent(request, response, eventType, eventPath, eventMethod); + ConfigXMLReader.ControllerConfig controllerConfig = handler.getControllerConfig(); + ConfigXMLReader.Event event = controllerConfig.requestMapMap.get(requestUri).event; + return handler.runEvent(request, response, event.type, event.path, event.invoke); } } diff --git a/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java b/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java index 4d3fca0f05..69e6522f2a 100644 --- a/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java +++ b/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java @@ -20,29 +20,20 @@ package org.ofbiz.webapp.event; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.Writer; import java.io.OutputStream; +import java.io.Writer; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; + +import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.ServletContext; -import javax.xml.soap.SOAPException; import javax.wsdl.WSDLException; +import javax.xml.soap.SOAPException; import javolution.util.FastMap; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilMisc; -import org.ofbiz.base.util.UtilXml; -import org.ofbiz.service.GenericServiceException; -import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.service.ModelService; -import org.ofbiz.service.DispatchContext; -import org.ofbiz.webapp.control.RequestHandler; - import org.apache.axis.AxisFault; import org.apache.axis.Constants; import org.apache.axis.Message; @@ -51,6 +42,14 @@ import org.apache.axis.message.RPCElement; import org.apache.axis.message.RPCParam; import org.apache.axis.message.SOAPEnvelope; import org.apache.axis.server.AxisServer; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.service.DispatchContext; +import org.ofbiz.service.GenericServiceException; +import org.ofbiz.service.LocalDispatcher; +import org.ofbiz.service.ModelService; +import org.ofbiz.webapp.control.RequestHandler; import org.w3c.dom.Document; /** @@ -84,7 +83,7 @@ public class SOAPEventHandler implements EventHandler { wsdlReq = request.getParameter("WSDL"); } if (wsdlReq != null) { - String serviceName = RequestHandler.getNextPageUri(request.getPathInfo()); + String serviceName = RequestHandler.getOverrideViewUri(request.getPathInfo()); DispatchContext dctx = dispatcher.getDispatchContext(); String locationUri = this.getLocationURI(request); diff --git a/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java b/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java index 044608558f..1fc72a799e 100644 --- a/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java +++ b/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java @@ -19,7 +19,6 @@ package org.ofbiz.webapp.event; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -48,8 +47,8 @@ import org.ofbiz.service.ModelService; import org.ofbiz.service.ServiceAuthException; import org.ofbiz.service.ServiceUtil; import org.ofbiz.service.ServiceValidationException; +import org.ofbiz.webapp.control.ConfigXMLReader; import org.ofbiz.webapp.control.RequestHandler; -import org.ofbiz.webapp.control.RequestManager; /** * ServiceMultiEventHandler - Event handler for running a service multiple times; for bulk forms @@ -60,15 +59,14 @@ public class ServiceMultiEventHandler implements EventHandler { public static final String SYNC = "sync"; public static final String ASYNC = "async"; - private RequestManager requestManager; - + + protected ServletContext servletContext; + /** * @see org.ofbiz.webapp.event.EventHandler#init(javax.servlet.ServletContext) */ - public void init(ServletContext context) throws EventHandlerException { - - // Provide a means to check the controller for event tag attributes at execution time - this.requestManager = new RequestManager(context); + public void init(ServletContext servletContext) throws EventHandlerException { + this.servletContext = servletContext; } /** @@ -158,7 +156,8 @@ public class ServiceMultiEventHandler implements EventHandler { // Check the global-transaction attribute of the event from the controller to see if the // event should be wrapped in a transaction String requestUri = RequestHandler.getRequestUri(request.getPathInfo()); - boolean eventGlobalTransaction = requestManager.getEventGlobalTransaction(requestUri); + ConfigXMLReader.ControllerConfig controllerConfig = ConfigXMLReader.getControllerConfig(ConfigXMLReader.getControllerConfigURL(servletContext)); + boolean eventGlobalTransaction = controllerConfig.requestMapMap.get(requestUri).event.globalTransaction; // big try/finally to make sure commit or rollback are run boolean beganTrans = false; diff --git a/framework/webapp/src/org/ofbiz/webapp/view/ViewFactory.java b/framework/webapp/src/org/ofbiz/webapp/view/ViewFactory.java index d90004054a..a6dfa23ff5 100644 --- a/framework/webapp/src/org/ofbiz/webapp/view/ViewFactory.java +++ b/framework/webapp/src/org/ofbiz/webapp/view/ViewFactory.java @@ -19,17 +19,16 @@ package org.ofbiz.webapp.view; import java.util.Map; -import java.util.List; -import java.util.Iterator; +import java.util.Set; + import javax.servlet.ServletContext; import javolution.util.FastMap; import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.ObjectType; import org.ofbiz.base.util.GeneralRuntimeException; +import org.ofbiz.base.util.ObjectType; import org.ofbiz.webapp.control.RequestHandler; -import org.ofbiz.webapp.control.RequestManager; /** * ViewFactory - View Handler Factory @@ -39,14 +38,12 @@ public class ViewFactory { public static final String module = ViewFactory.class.getName(); protected RequestHandler requestHandler = null; - protected RequestManager requestManager = null; protected ServletContext context = null; protected Map handlers = null; public ViewFactory(RequestHandler requestHandler) { this.handlers = FastMap.newInstance(); this.requestHandler = requestHandler; - this.requestManager = requestHandler.getRequestManager(); this.context = requestHandler.getServletContext(); // pre-load all the view handlers @@ -59,7 +56,7 @@ public class ViewFactory { } private void preLoadAll() throws ViewHandlerException { - List handlers = requestManager.getHandlerKeys(RequestManager.VIEW_HANDLER_KEY); + Set handlers = this.requestHandler.getControllerConfig().viewHandlerMap.keySet(); if (handlers != null) { for (String type: handlers) { this.handlers.put(type, this.loadViewHandler(type)); @@ -113,9 +110,10 @@ public class ViewFactory { private ViewHandler loadViewHandler(String type) throws ViewHandlerException { ViewHandler handler = null; - String handlerClass = requestManager.getHandlerClass(type, RequestManager.VIEW_HANDLER_KEY); - if (handlerClass == null) + String handlerClass = this.requestHandler.getControllerConfig().viewHandlerMap.get(type); + if (handlerClass == null) { throw new ViewHandlerException("Unknown handler type: " + type); + } try { handler = (ViewHandler) ObjectType.getInstance(handlerClass); diff --git a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java index 7627749471..d33eeadef6 100644 --- a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java +++ b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java @@ -19,9 +19,7 @@ package org.ofbiz.webtools.artifactinfo; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; -import java.io.FileNotFoundException; import java.net.MalformedURLException; import java.net.URL; import java.util.Collection; @@ -34,12 +32,11 @@ import javax.xml.parsers.ParserConfigurationException; import javolution.util.FastMap; import javolution.util.FastSet; -import javolution.util.FastList; import org.ofbiz.base.component.ComponentConfig; import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.FileUtil; +import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.entity.GenericEntityException; @@ -215,14 +212,14 @@ public class ArtifactInfoFactory { throw new GeneralException(mue.getMessage()); } ControllerConfig cc = ConfigXMLReader.getControllerConfig(controllerUrl); - for (String requestUri: cc.requestMap.keySet()) { + for (String requestUri: cc.requestMapMap.keySet()) { try { this.getControllerRequestArtifactInfo(controllerUrl, requestUri); } catch(GeneralException e) { Debug.logWarning(e.getMessage(), module); } } - for (String viewUri: cc.viewMap.keySet()) { + for (String viewUri: cc.viewMapMap.keySet()) { try { this.getControllerViewArtifactInfo(controllerUrl, viewUri); } catch(GeneralException e) { @@ -261,13 +258,13 @@ public class ArtifactInfoFactory { return ScreenFactory.getScreenFromLocation(screenLocation, screenName); } - public Map getControllerRequestInfoMap(URL controllerXmlUrl, String requestUri) { - return ConfigXMLReader.getControllerConfig(controllerXmlUrl).requestMap.get(requestUri); + public ConfigXMLReader.RequestMap getControllerRequestMap(URL controllerXmlUrl, String requestUri) { + return ConfigXMLReader.getControllerConfig(controllerXmlUrl).requestMapMap.get(requestUri); } - public Map getControllerViewInfoMap(URL controllerXmlUrl, String viewUri) { + public ConfigXMLReader.ViewMap getControllerViewMap(URL controllerXmlUrl, String viewUri) { ControllerConfig cc = ConfigXMLReader.getControllerConfig(controllerXmlUrl); - return cc.viewMap.get(viewUri); + return cc.viewMapMap.get(viewUri); } public EntityArtifactInfo getEntityArtifactInfo(String entityName) throws GeneralException { diff --git a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ControllerRequestArtifactInfo.java b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ControllerRequestArtifactInfo.java index e647149e61..2acdb68982 100644 --- a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ControllerRequestArtifactInfo.java +++ b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ControllerRequestArtifactInfo.java @@ -41,7 +41,7 @@ public class ControllerRequestArtifactInfo extends ArtifactInfoBase { protected URL controllerXmlUrl; protected String requestUri; - protected Map requestInfoMap; + protected ConfigXMLReader.RequestMap requestInfoMap; protected ServiceArtifactInfo serviceCalledByRequestEvent = null; protected Set requestsThatAreResponsesToThisRequest = new TreeSet(); @@ -52,7 +52,7 @@ public class ControllerRequestArtifactInfo extends ArtifactInfoBase { this.controllerXmlUrl = controllerXmlUrl; this.requestUri = requestUri; - this.requestInfoMap = aif.getControllerRequestInfoMap(controllerXmlUrl, requestUri); + this.requestInfoMap = aif.getControllerRequestMap(controllerXmlUrl, requestUri); if (this.requestInfoMap == null) { throw new GeneralException("Controller request with name [" + requestUri + "] is not defined in controller file [" + controllerXmlUrl + "]."); @@ -67,8 +67,8 @@ public class ControllerRequestArtifactInfo extends ArtifactInfoBase { public void populateAll() throws GeneralException { // populate serviceCalledByRequestEvent, requestsThatAreResponsesToThisRequest, viewsThatAreResponsesToThisRequest and related reverse maps - if ("service".equals(this.requestInfoMap.get(ConfigXMLReader.EVENT_TYPE))) { - String serviceName = (String) this.requestInfoMap.get(ConfigXMLReader.EVENT_METHOD); + if ("service".equals(this.requestInfoMap.event.type)) { + String serviceName = (String) this.requestInfoMap.event.invoke; try { this.serviceCalledByRequestEvent = this.aif.getServiceArtifactInfo(serviceName); if (this.serviceCalledByRequestEvent != null) { @@ -80,10 +80,10 @@ public class ControllerRequestArtifactInfo extends ArtifactInfoBase { } } - Map responseMap = UtilGenerics.checkMap(this.requestInfoMap.get(ConfigXMLReader.RESPONSE_MAP)); - for (String responseValue: responseMap.values()) { - if (responseValue.startsWith("view:")) { - String viewUri = responseValue.substring(5); + Map requestResponseMap = UtilGenerics.checkMap(this.requestInfoMap.requestResponseMap); + for (ConfigXMLReader.RequestResponse response: requestResponseMap.values()) { + if (response.type.equals("view")) { + String viewUri = response.value; if (viewUri.startsWith("/")) { viewUri = viewUri.substring(1); } @@ -95,8 +95,8 @@ public class ControllerRequestArtifactInfo extends ArtifactInfoBase { } catch (GeneralException e) { Debug.logWarning(e.toString(), module); } - } else if (responseValue.startsWith("request:")) { - String otherRequestUri = responseValue.substring(8); + } else if (response.type.equals("request")) { + String otherRequestUri = response.value; if (otherRequestUri.startsWith("/")) { otherRequestUri = otherRequestUri.substring(1); } @@ -107,13 +107,13 @@ public class ControllerRequestArtifactInfo extends ArtifactInfoBase { } catch (GeneralException e) { Debug.logWarning(e.toString(), module); } - } else if (responseValue.startsWith("request-redirect:")) { - String otherRequestUri = responseValue.substring(17); + } else if (response.type.equals("request-redirect")) { + String otherRequestUri = response.value; ControllerRequestArtifactInfo artInfo = this.aif.getControllerRequestArtifactInfo(controllerXmlUrl, otherRequestUri); this.requestsThatAreResponsesToThisRequest.add(artInfo); UtilMisc.addToSortedSetInMap(this, this.aif.allRequestInfosReferringToRequest, artInfo.getUniqueId()); - } else if (responseValue.startsWith("request-redirect-noparam:")) { - String otherRequestUri = responseValue.substring(25); + } else if (response.type.equals("request-redirect-noparam")) { + String otherRequestUri = response.value; ControllerRequestArtifactInfo artInfo = this.aif.getControllerRequestArtifactInfo(controllerXmlUrl, otherRequestUri); this.requestsThatAreResponsesToThisRequest.add(artInfo); UtilMisc.addToSortedSetInMap(this, this.aif.allRequestInfosReferringToRequest, artInfo.getUniqueId()); diff --git a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java index a85cf76964..c46dfd90ae 100644 --- a/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java +++ b/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java @@ -20,7 +20,6 @@ package org.ofbiz.webtools.artifactinfo; import java.net.MalformedURLException; import java.net.URL; -import java.util.Map; import java.util.Set; import org.ofbiz.base.util.Debug; @@ -40,7 +39,7 @@ public class ControllerViewArtifactInfo extends ArtifactInfoBase { protected URL controllerXmlUrl; protected String viewUri; - protected Map viewInfoMap; + protected ConfigXMLReader.ViewMap viewInfoMap; protected ScreenWidgetArtifactInfo screenCalledByThisView = null; @@ -49,7 +48,7 @@ public class ControllerViewArtifactInfo extends ArtifactInfoBase { this.controllerXmlUrl = controllerXmlUrl; this.viewUri = viewUri; - this.viewInfoMap = aif.getControllerViewInfoMap(controllerXmlUrl, viewUri); + this.viewInfoMap = aif.getControllerViewMap(controllerXmlUrl, viewUri); if (this.viewInfoMap == null) { throw new GeneralException("Could not find Controller View [" + viewUri + "] at URL [" + controllerXmlUrl.toExternalForm() + "]"); @@ -59,11 +58,9 @@ public class ControllerViewArtifactInfo extends ArtifactInfoBase { throw new GeneralException("Controller view with name [" + viewUri + "] is not defined in controller file [" + controllerXmlUrl + "]."); } // populate screenCalledByThisView and reverse in aif.allViewInfosReferringToScreen - if ("screen".equals(this.viewInfoMap.get(ConfigXMLReader.VIEW_TYPE)) || - "screenfop".equals(this.viewInfoMap.get(ConfigXMLReader.VIEW_TYPE)) || - "screentext".equals(this.viewInfoMap.get(ConfigXMLReader.VIEW_TYPE)) || - "screenxml".equals(this.viewInfoMap.get(ConfigXMLReader.VIEW_TYPE))) { - String fullScreenName = this.viewInfoMap.get(ConfigXMLReader.VIEW_PAGE); + if ("screen".equals(this.viewInfoMap.type) || "screenfop".equals(this.viewInfoMap.type) || + "screentext".equals(this.viewInfoMap.type) || "screenxml".equals(this.viewInfoMap.type)) { + String fullScreenName = this.viewInfoMap.page; if (UtilValidate.isNotEmpty(fullScreenName)) { int poundIndex = fullScreenName.indexOf('#'); try { diff --git a/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java b/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java index 5ba4ba9cab..e19bb8641d 100644 --- a/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java +++ b/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java @@ -234,7 +234,7 @@ public class ScreenRenderer { context.put("controlPath", request.getAttribute("_CONTROL_PATH_")); context.put("contextRoot", request.getAttribute("_CONTEXT_ROOT_")); context.put("serverRoot", request.getAttribute("_SERVER_ROOT_URL_")); - context.put("checkLoginUrl", LoginWorker.makeLoginUrl(request, "checkLogin")); + context.put("checkLoginUrl", LoginWorker.makeLoginUrl(request)); String externalLoginKey = LoginWorker.getExternalLoginKey(request); String externalKeyParam = externalLoginKey == null ? "" : "&externalLoginKey=" + externalLoginKey; context.put("externalLoginKey", externalLoginKey); diff --git a/specialpurpose/hhfacility/webapp/hhfacility/login.ftl b/specialpurpose/hhfacility/webapp/hhfacility/login.ftl index 27b15de7c1..5c8d065350 100644 --- a/specialpurpose/hhfacility/webapp/hhfacility/login.ftl +++ b/specialpurpose/hhfacility/webapp/hhfacility/login.ftl @@ -17,11 +17,6 @@ specific language governing permissions and limitations under the License. --> -<#assign previousParams = sessionAttributes._PREVIOUS_PARAMS_?if_exists> -<#if previousParams?has_content> - <#assign previousParams = "?" + previousParams> - - <#assign username = requestParameters.USERNAME?default((sessionAttributes.autoUserLogin.userLoginId)?default(""))> <#if username != ""> <#assign focusName = false> @@ -49,7 +44,7 @@ under the License.
    ${uiLabelMap.CommonUsername}
    - +
    diff --git a/specialpurpose/myportal/widget/login.ftl b/specialpurpose/myportal/widget/login.ftl index 7bf71d2dc1..49d47866df 100644 --- a/specialpurpose/myportal/widget/login.ftl +++ b/specialpurpose/myportal/widget/login.ftl @@ -19,11 +19,6 @@ under the License. <#if requestAttributes.uiLabelMap?exists><#assign uiLabelMap = requestAttributes.uiLabelMap> -<#assign previousParams = sessionAttributes._PREVIOUS_PARAMS_?if_exists> -<#if previousParams?has_content> - <#assign previousParams = "?" + previousParams> - - <#assign username = requestParameters.USERNAME?default((sessionAttributes.autoUserLogin.userLoginId)?default(""))> <#if username != ""> <#assign focusName = false> @@ -37,7 +32,7 @@ under the License.

    ${uiLabelMap.CommonRegistered}