A few related changes:
Big refactor of ControlServlet, RequestManager, RequestHandler, and ConfigXMLReader so that simple objects are used instead of Maps within Maps within Maps for the data from the controller.xml file, which results in eliminating hundreds of lines of code including the entire RequestHandler class. I have tested this a lot with different apps that use the ControlServlet differently, but this is a very big change so there could still be issues. Based on this cleanup future issues and new features should be easier and less error prone, and that is why doing it now in order to help with a number of other improvements and bug fixes that are part of this commit. Also added redirect-parameter element to go under the request-map -> response element which allows you to specify which parameters will be passed on in a redirect instead of using all of them. Also improved default there and in various places to only include parameters from the URL to avoid issues with form data, but if the ID to display (like following a crAlso added redirect-parameter element to go under the request-map -> response element which allows you to specify which parameters will be passed on in a redirect instead of using all of them. Also improved default there and in various places to only include parameters from the URL to avoid issues with form data, but if the ID to display (like following a crAlso added redirect-parameter element to go under the request-map -> response element which allows you to specify which parameters will be passed on in a redirect instead of using all of them. Also improved default there and in various places to only include parameters from the URL to avoid issues wd in and also going to the same page after login from auth=true or from clicking on the login link. Related to cleaning up login URLs also changed how the request and parameters passed to a request before a login are saved and used after a login is successful so that it URL parameters go on the URL in a redirect to the original request to make it more transparent, and non-URL parameters just stay in the session and are used when the original request is run again to avoid putting sensitive information like passwords and big information like textarea data in the URL, which has been a problem before. To see what some of these things combined can do try going to the example app, login, click on the New Example link, then logout in another tab or window, then go back to the New Example page and enter a name and a whole bunch of text in the long description then click Create, the system will show you the login page so enter username/password, and then after login you'll see a nice URL to EditExample with the correct exampleId parameter and all of the data entered before login successfully saved and never appearing in a URL. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@741374 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -34,7 +34,7 @@ under the License.
|
||||
<div class="boxhead">${uiLabelMap.CommonRegistered}</div>
|
||||
</div>
|
||||
<div class="screenlet-body" style="text-align: center;">
|
||||
<form method="post" action="<@ofbizUrl>login${previousParams}</@ofbizUrl>" name="loginform">
|
||||
<form method="post" action="<@ofbizUrl>login</@ofbizUrl>" name="loginform">
|
||||
<div class="tabletext">
|
||||
${uiLabelMap.CommonUsername}:
|
||||
<input type="text" class="inputBox" name="USERNAME" value="<#if requestParameters.USERNAME?has_content>${requestParameters.USERNAME}<#elseif autoUserLogin?has_content>${autoUserLogin.userLoginId}</#if>" size="20"/>
|
||||
@@ -60,7 +60,7 @@ under the License.
|
||||
<div class="boxhead">${uiLabelMap.CommonForgotYourPassword}?</div>
|
||||
</div>
|
||||
<div class="screenlet-body" style="text-align: center;">
|
||||
<form method="post" action="<@ofbizUrl>forgotpassword${previousParams}</@ofbizUrl>" name="forgotpassword" style="margin: 0;">
|
||||
<form method="post" action="<@ofbizUrl>forgotpassword</@ofbizUrl>" name="forgotpassword" style="margin: 0;">
|
||||
<span class="tabletext">${uiLabelMap.CommonUsername}: </span><input type="text" size="20" class="inputBox" name="USERNAME" value="<#if requestParameters.USERNAME?has_content>${requestParameters.USERNAME}<#elseif autoUserLogin?has_content>${autoUserLogin.userLoginId}</#if>"/>
|
||||
<div><input type="submit" name="GET_PASSWORD_HINT" class="smallSubmit" value="${uiLabelMap.CommonGetPasswordHint}"/> <input type="submit" name="EMAIL_PASSWORD" class="smallSubmit" value="${uiLabelMap.CommonEmailPassword}"/></div>
|
||||
</form>
|
||||
@@ -74,7 +74,7 @@ under the License.
|
||||
<div class="boxhead">${uiLabelMap.CommonNewUser}</div>
|
||||
</div>
|
||||
<div class="screenlet-body" style="text-align: center;">
|
||||
<form method="post" action="<@ofbizUrl>newcustomer${previousParams}</@ofbizUrl>" style="margin: 0;">
|
||||
<form method="post" action="<@ofbizUrl>newcustomer</@ofbizUrl>" style="margin: 0;">
|
||||
<div class="tabletext">${uiLabelMap.CommonMayCreateNewAccountHere}:</div>
|
||||
<div><input type="submit" class="smallSubmit" value="${uiLabelMap.CommonMayCreate}"/></div>
|
||||
</form>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<String, Object> getParameterMap(HttpServletRequest request) {
|
||||
return getParameterMap(request, null);
|
||||
return getParameterMap(request, null, null);
|
||||
}
|
||||
|
||||
public static Map<String, Object> getParameterMap(HttpServletRequest request, Set<? extends String> 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<String, Object> getParameterMap(HttpServletRequest request, Set<? extends String> namesToSkip) {
|
||||
public static Map<String, Object> getParameterMap(HttpServletRequest request, Set<? extends String> nameSet, Boolean onlyIncludeOrSkip) {
|
||||
boolean onlyIncludeOrSkipPrim = onlyIncludeOrSkip == null ? true : onlyIncludeOrSkip.booleanValue();
|
||||
Map<String, Object> paramMap = FastMap.newInstance();
|
||||
|
||||
// add all the actual HTTP request parameters
|
||||
Enumeration e = request.getParameterNames();
|
||||
Enumeration<String> 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<String, Object> 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<String, Object> getQueryStringOnlyParameterMap(HttpServletRequest request) {
|
||||
Map<String, Object> 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<String, Object> getPathInfoOnlyParameterMap(HttpServletRequest request, Set<? extends String> nameSet, Boolean onlyIncludeOrSkip) {
|
||||
boolean onlyIncludeOrSkipPrim = onlyIncludeOrSkip == null ? true : onlyIncludeOrSkip.booleanValue();
|
||||
Map<String, Object> 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<String, Object> 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<String, Object> getUrlOnlyParameterMap(HttpServletRequest request) {
|
||||
Map<String, Object> 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
|
||||
|
||||
@@ -77,7 +77,7 @@ under the License.
|
||||
<request-map uri="logout">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="java" path="org.ofbiz.webapp.control.LoginWorker" invoke="logout"/>
|
||||
<response name="success" type="request" value="checkLogin"/>
|
||||
<response name="success" type="request-redirect" value="main"/>
|
||||
<response name="error" type="view" value="main"/>
|
||||
</request-map>
|
||||
<request-map uri="forgotPassword">
|
||||
|
||||
@@ -106,10 +106,8 @@ under the License.
|
||||
<li>
|
||||
<#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}]</#if>
|
||||
<#elseif partyGroup?has_content>
|
||||
${uiLabelMap.CommonWelcome} ${partyGroup.groupName?if_exists} [${userLogin.userLoginId}]
|
||||
<#if defaultOrganizationPartyId?exists>${uiLabelMap.CommonDefaultOrganizationPartyId} : ${defaultOrganizationPartyGroupName?if_exists} [${defaultOrganizationPartyId}]</#if>
|
||||
<#else>
|
||||
${uiLabelMap.CommonWelcome}!
|
||||
</#if>
|
||||
@@ -134,27 +132,23 @@ under the License.
|
||||
<li class="control-area"<#if layoutSettings.headerRightBackgroundUrl?has_content> background="${layoutSettings.headerRightBackgroundUrl}"</#if>>
|
||||
<#if userLogin?exists>
|
||||
<p class="expanded">
|
||||
<#if person?has_content>
|
||||
${uiLabelMap.CommonWelcome} ${person.firstName?if_exists} ${person.lastName?if_exists}
|
||||
<#elseif partyGroup?has_content>
|
||||
${uiLabelMap.CommonWelcome} ${partyGroup.groupName?if_exists}
|
||||
</#if>
|
||||
[${userLogin.userLoginId}]
|
||||
<a href="<@ofbizUrl>logout</@ofbizUrl>">${uiLabelMap.CommonLogout}</a>
|
||||
<a href="setUserPreference?userPrefGroupTypeId=GLOBAL_PREFERENCES&userPrefTypeId=COMPACT_HEADER&userPrefValue=Y"> </a>
|
||||
</p>
|
||||
</#if>
|
||||
<p>
|
||||
<#if person?has_content>
|
||||
${uiLabelMap.CommonWelcome} ${person.firstName?if_exists} ${person.lastName?if_exists} [${userLogin.userLoginId}]
|
||||
</p>
|
||||
<#if defaultOrganizationPartyId?exists><p>${uiLabelMap.CommonDefaultOrganizationPartyId} : ${defaultOrganizationPartyGroupName?if_exists} [${defaultOrganizationPartyId}]</p></#if>
|
||||
<#elseif partyGroup?has_content>
|
||||
${uiLabelMap.CommonWelcome} ${partyGroup.groupName?if_exists} [${userLogin.userLoginId}]
|
||||
</p>
|
||||
<#if defaultOrganizationPartyId?exists><p>${uiLabelMap.CommonDefaultOrganizationPartyId} : ${defaultOrganizationPartyGroupName?if_exists} [${defaultOrganizationPartyId}]</p></#if>
|
||||
<#else>
|
||||
<#else/>
|
||||
<p>
|
||||
${uiLabelMap.CommonWelcome}! <a href="<@ofbizUrl>${checkLoginUrl}</@ofbizUrl>">${uiLabelMap.CommonLogin}</a>
|
||||
</p>
|
||||
</p>
|
||||
</#if>
|
||||
<ul id="preferences-menu">
|
||||
<!--
|
||||
<li class="first"><a href="<@ofbizUrl>Preferences</@ofbizUrl>">${uiLabelMap.CommonPreferences}</a></li>
|
||||
-->
|
||||
<!-- <li class="first"><a href="<@ofbizUrl>Preferences</@ofbizUrl>">${uiLabelMap.CommonPreferences}</a></li> -->
|
||||
<li class="first"><a href="<@ofbizUrl>LookupLocales</@ofbizUrl>">${uiLabelMap.CommonLanguageTitle} : ${locale.getDisplayName(locale)}</a></li>
|
||||
<#if userLogin?exists>
|
||||
<li><a href="<@ofbizUrl>LookupVisualThemes</@ofbizUrl>">${uiLabelMap.CommonVisualThemes}</a></li>
|
||||
@@ -163,5 +157,5 @@ under the License.
|
||||
</li>
|
||||
</#if>
|
||||
</ul>
|
||||
<br class="clear" />
|
||||
<br class="clear"/>
|
||||
</div>
|
||||
|
||||
@@ -19,11 +19,6 @@ under the License.
|
||||
|
||||
<#if requestAttributes.uiLabelMap?exists><#assign uiLabelMap = requestAttributes.uiLabelMap></#if>
|
||||
|
||||
<#assign previousParams = sessionAttributes._PREVIOUS_PARAMS_?if_exists>
|
||||
<#if previousParams?has_content>
|
||||
<#assign previousParams = "?" + previousParams>
|
||||
</#if>
|
||||
|
||||
<#assign username = requestParameters.USERNAME?default((sessionAttributes.autoUserLogin.userLoginId)?default(""))>
|
||||
<#if username != "">
|
||||
<#assign focusName = false>
|
||||
@@ -36,7 +31,7 @@ under the License.
|
||||
<h3>${uiLabelMap.CommonRegistered}</h3>
|
||||
</div>
|
||||
<div class="screenlet-body">
|
||||
<form method="post" action="<@ofbizUrl>login${previousParams?if_exists}</@ofbizUrl>" name="loginform">
|
||||
<form method="post" action="<@ofbizUrl>login</@ofbizUrl>" name="loginform">
|
||||
<table class="basic-table" cellspacing="0">
|
||||
<tr>
|
||||
<td class="label">${uiLabelMap.CommonUsername}</td>
|
||||
|
||||
@@ -60,20 +60,24 @@ under the License.
|
||||
<request-map uri="createExample">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="createExample"/>
|
||||
<response name="success" type="view" value="EditExample"/>
|
||||
<response name="success" type="request-redirect" value="EditExample">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExample"/>
|
||||
</request-map>
|
||||
<request-map uri="updateExample">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="updateExample"/>
|
||||
<response name="success" type="view" value="EditExample"/>
|
||||
<response name="success" type="request-redirect" value="EditExample">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExample"/>
|
||||
</request-map>
|
||||
<request-map uri="createExampleAjax">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="jsonservice" invoke="createExample"/>
|
||||
<response name="success" type="none" value="findExampleAjax"/>
|
||||
<response name="error" type="none" value="findExampleAjax"/>
|
||||
<response name="success" type="none"/>
|
||||
<response name="error" type="none"/>
|
||||
</request-map>
|
||||
<request-map uri="updateExampleAjax">
|
||||
<security https="true" auth="true"/>
|
||||
@@ -86,19 +90,25 @@ under the License.
|
||||
<request-map uri="createExampleItem">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="createExampleItem"/>
|
||||
<response name="success" type="view" value="EditExampleItems"/>
|
||||
<response name="success" type="request-redirect" value="EditExampleItems">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExampleItems"/>
|
||||
</request-map>
|
||||
<request-map uri="updateExampleItem">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="updateExampleItem"/>
|
||||
<response name="success" type="view" value="EditExampleItems"/>
|
||||
<response name="success" type="request-redirect" value="EditExampleItems">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExampleItems"/>
|
||||
</request-map>
|
||||
<request-map uri="deleteExampleItem">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="deleteExampleItem"/>
|
||||
<response name="success" type="view" value="EditExampleItems"/>
|
||||
<response name="success" type="request-redirect" value="EditExampleItems">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExampleItems"/>
|
||||
</request-map>
|
||||
|
||||
@@ -106,19 +116,25 @@ under the License.
|
||||
<request-map uri="example_createExampleFeatureAppl">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="createExampleFeatureAppl"/>
|
||||
<response name="success" type="view" value="EditExampleFeatureAppls"/>
|
||||
<response name="success" type="request-redirect" value="EditExampleFeatureAppls">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExampleFeatureAppls"/>
|
||||
</request-map>
|
||||
<request-map uri="example_updateExampleFeatureAppl">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="updateExampleFeatureAppl"/>
|
||||
<response name="success" type="view" value="EditExampleFeatureAppls"/>
|
||||
<response name="success" type="request-redirect" value="EditExampleFeatureAppls">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExampleFeatureAppls"/>
|
||||
</request-map>
|
||||
<request-map uri="example_deleteExampleFeatureAppl">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="deleteExampleFeatureAppl"/>
|
||||
<response name="success" type="view" value="EditExampleFeatureAppls"/>
|
||||
<response name="success" type="request-redirect" value="EditExampleFeatureAppls">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExampleFeatureAppls"/>
|
||||
</request-map>
|
||||
|
||||
@@ -128,13 +144,17 @@ under the License.
|
||||
<request-map uri="createExampleFeature">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="createExampleFeature"/>
|
||||
<response name="success" type="view" value="EditExampleFeature"/>
|
||||
<response name="success" type="request-redirect" value="EditExampleFeature">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExampleFeature"/>
|
||||
</request-map>
|
||||
<request-map uri="updateExampleFeature">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="updateExampleFeature"/>
|
||||
<response name="success" type="view" value="EditExampleFeature"/>
|
||||
<response name="success" type="request-redirect" value="EditExampleFeature">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExampleFeature"/>
|
||||
</request-map>
|
||||
|
||||
@@ -142,19 +162,25 @@ under the License.
|
||||
<request-map uri="feature_createExampleFeatureAppl">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="createExampleFeatureAppl"/>
|
||||
<response name="success" type="view" value="EditExampleFeatureExampleAppls"/>
|
||||
<response name="success" type="request-redirect" value="EditExampleFeatureExampleAppls">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExampleFeatureExampleAppls"/>
|
||||
</request-map>
|
||||
<request-map uri="feature_updateExampleFeatureAppl">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="updateExampleFeatureAppl"/>
|
||||
<response name="success" type="view" value="EditExampleFeatureExampleAppls"/>
|
||||
<response name="success" type="request-redirect" value="EditExampleFeatureExampleAppls">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExampleFeatureExampleAppls"/>
|
||||
</request-map>
|
||||
<request-map uri="feature_deleteExampleFeatureAppl">
|
||||
<security https="true" auth="true"/>
|
||||
<event type="service" invoke="deleteExampleFeatureAppl"/>
|
||||
<response name="success" type="view" value="EditExampleFeatureExampleAppls"/>
|
||||
<response name="success" type="request-redirect" value="EditExampleFeatureExampleAppls">
|
||||
<redirect-parameter name="exampleId"/>
|
||||
</response>
|
||||
<response name="error" type="view" value="EditExampleFeatureExampleAppls"/>
|
||||
</request-map>
|
||||
<request-map uri="findExampleFeatures">
|
||||
|
||||
@@ -231,6 +231,9 @@ under the License.
|
||||
</xs:attributeGroup>
|
||||
<xs:element name="response">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" ref="redirect-parameter"/>
|
||||
</xs:sequence>
|
||||
<xs:attributeGroup ref="attlist.response"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
@@ -250,6 +253,18 @@ under the License.
|
||||
</xs:attribute>
|
||||
<xs:attribute type="xs:string" name="value"/>
|
||||
</xs:attributeGroup>
|
||||
<xs:element name="redirect-parameter">
|
||||
<xs:annotation><xs:documentation>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.</xs:documentation></xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:attributeGroup ref="attlist.redirect-parameter"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:attributeGroup name="attlist.redirect-parameter">
|
||||
<xs:attribute type="xs:string" name="name" use="required"/>
|
||||
<xs:attribute type="xs:string" name="from" use="optional">
|
||||
<xs:annotation><xs:documentation>If specified used instead of the value of name for the key to find a request attribute or parameter.</xs:documentation></xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:attributeGroup>
|
||||
<xs:element name="view-map">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
|
||||
@@ -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<URL, ControllerConfig> controllerCache = new UtilCache<URL, ControllerConfig>("webapp.ControllerConfig");
|
||||
public static UtilCache<String, List<ControllerConfig>> controllerSearchResultsCache = new UtilCache<String, List<ControllerConfig>>("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<String, Object> configMap = FastMap.newInstance();
|
||||
public Map<String, Map<String, String>> handlerMap = FastMap.newInstance();
|
||||
public Map<String, Map<String, Object>> requestMap = FastMap.newInstance();
|
||||
public Map<String, Map<String, String>> viewMap = FastMap.newInstance();
|
||||
public String defaultRequest = null;
|
||||
public String errorpage;
|
||||
public String protectView;
|
||||
public String owner;
|
||||
public String securityClass;
|
||||
public String defaultRequest;
|
||||
|
||||
public List<Event> firstVisitEventList = FastList.newInstance();
|
||||
public List<Event> preprocessorEventList = FastList.newInstance();
|
||||
public List<Event> postprocessorEventList = FastList.newInstance();
|
||||
public List<Event> afterLoginEventList = FastList.newInstance();
|
||||
public List<Event> beforeLogoutEventList = FastList.newInstance();
|
||||
|
||||
public Map<String, String> eventHandlerMap = FastMap.newInstance();
|
||||
public Map<String, String> viewHandlerMap = FastMap.newInstance();
|
||||
|
||||
public Map<String, RequestMap> requestMapMap = FastMap.newInstance();
|
||||
public Map<String, ViewMap> 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<String> 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<String, Map<String, Object>> getRequestMap(URL xml) {
|
||||
ControllerConfig controllerConfig = getControllerConfig(xml);
|
||||
return controllerConfig != null ? controllerConfig.requestMap : null;
|
||||
}
|
||||
|
||||
/** Gets a FastMap of request mappings. */
|
||||
public static Map<String, Map<String, Object>> loadRequestMap(Element root, URL xml) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Map<String, Map<String, Object>> 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<String, Map<String, Object>> 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<String, Object> 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<String, String> 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<String> debugSet = map.keySet();
|
||||
Iterator<String> i = debugSet.iterator();
|
||||
while (i.hasNext()) {
|
||||
Object o = i.next();
|
||||
String request = (String) o;
|
||||
Map<String, Object> thisURI = map.get(o);
|
||||
|
||||
StringBuilder verboseMessageBuffer = new StringBuilder();
|
||||
|
||||
Iterator<String> 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<String, Map<String, String>> getViewMap(URL xml) {
|
||||
ControllerConfig controllerConfig = getControllerConfig(xml);
|
||||
return controllerConfig != null ? controllerConfig.viewMap : null;
|
||||
}
|
||||
|
||||
/** Gets a FastMap of view mappings. */
|
||||
public static Map<String, Map<String, String>> loadViewMap(Element root, URL xml) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Map<String, Map<String, String>> 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<String, Map<String, String>> 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<String, String> 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<String, Object> getConfigMap(URL xml) {
|
||||
ControllerConfig controllerConfig = getControllerConfig(xml);
|
||||
return controllerConfig != null ? controllerConfig.configMap : null;
|
||||
}
|
||||
|
||||
/** Gets a FastMap of site configuration variables. */
|
||||
public static Map<String, Object> loadConfigMap(Element root, URL xml) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
FastMap<String, Object> 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<String, Object> 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<String, RequestResponse> 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<Map<String, String>> eventList = FastList.newInstance();
|
||||
for (Element eventElement: UtilXml.childElementList(firstvisitElement, EVENT)) {
|
||||
Map<String, String> 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<Map<String, String>> eventList = FastList.newInstance();
|
||||
for (Element eventElement: UtilXml.childElementList(preprocessorElement, EVENT)) {
|
||||
Map<String, String> 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<Map<String, String>> eventList = FastList.newInstance();
|
||||
for (Element eventElement: UtilXml.childElementList(postprocessorElement, EVENT)) {
|
||||
Map<String, String> 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<Map<String, String>> eventList = FastList.newInstance();
|
||||
for (Element eventElement: UtilXml.childElementList(afterLoginElement, EVENT)) {
|
||||
Map<String, String> 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<Map<String, String>> eventList = FastList.newInstance();
|
||||
List<? extends Element> eventElementList = UtilXml.childElementList(beforeLogoutElement, EVENT);
|
||||
for (Element eventElement: UtilXml.childElementList(beforeLogoutElement, EVENT)) {
|
||||
Map<String, String> 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<String, String> 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<String, Map<String, String>> getHandlerMap(URL xml) {
|
||||
ControllerConfig controllerConfig = getControllerConfig(xml);
|
||||
return controllerConfig != null ? controllerConfig.handlerMap : null;
|
||||
}
|
||||
|
||||
public static Map<String, Map<String, String>> loadHandlerMap(Element root, URL xml) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Map<String, Map<String, String>> 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<String, Map<String, String>> subMap = loadHandlerMap(null, FlexibleLocation.resolveLocation(includeLocation));
|
||||
|
||||
Map<String, String> newViewHandlerMap = checkMap(subMap.get("view"), String.class, String.class);
|
||||
Map<String, String> viewHandlerMap = checkMap(map.get("view"), String.class, String.class);
|
||||
if (viewHandlerMap == null) {
|
||||
map.put("view", newViewHandlerMap);
|
||||
} else {
|
||||
if (newViewHandlerMap != null) {
|
||||
viewHandlerMap.putAll(newViewHandlerMap);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> newEventHandlerMap = checkMap(subMap.get("event"), String.class, String.class);
|
||||
Map<String, String> 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<String, String> eventMap = FastMap.newInstance();
|
||||
Map<String, String> 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<String, String> viewHandlerMap = checkMap(map.get("view"), String.class, String.class);
|
||||
if (viewHandlerMap == null) {
|
||||
map.put("view", viewMap);
|
||||
} else {
|
||||
if (viewMap != null) {
|
||||
viewHandlerMap.putAll(viewMap);
|
||||
}
|
||||
}
|
||||
Map<String, String> 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<String, String> debugMap = checkMap(map.get("event"), String.class, String.class);
|
||||
|
||||
if (UtilValidate.isNotEmpty(debugMap)) {
|
||||
Debug.logVerbose("-------------- EVENT -------------", module);
|
||||
for (Map.Entry<String, String> 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<String, String> 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 "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String, Object> 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<String, Object> 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<String, Object> urlParams = UtilHttp.getUrlOnlyParameterMap(request);
|
||||
if (urlParams != null && urlParams.size() > 0) {
|
||||
session.setAttribute("_PREVIOUS_PARAM_MAP_URL_", urlParams);
|
||||
}
|
||||
Map<String, Object> 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");
|
||||
|
||||
@@ -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<Map<String, String>> events = requestManager.getFirstVisitEvents();
|
||||
|
||||
if (visit != null && events != null) {
|
||||
for (Map<String, String> 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<Map<String, String>> preProcEvents = requestManager.getPreProcessor();
|
||||
if (preProcEvents != null) {
|
||||
for (Map<String, String> 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<String, Object> previousParamMap = (Map<String, Object>) request.getSession().getAttribute("_PREVIOUS_PARAM_MAP_FORM_");
|
||||
for (Map.Entry<String, Object> 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<String, Object> previousRequestAttrMap = null;
|
||||
if (preReqAttStr != null) {
|
||||
previousRequestAttrMap = FastMap.newInstance();
|
||||
request.getSession().removeAttribute("_REQ_ATTR_MAP_");
|
||||
byte[] reqAttrMapBytes = StringUtil.fromHexString(preReqAttStr);
|
||||
Map<String, Object> 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<String, Object> previousParamMap = (Map<String, Object>) 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<Map<String, String>> postProcEvents = requestManager.getPostProcessor();
|
||||
if (chain == null && postProcEvents != null) { // don't run post-proc events on chained requests
|
||||
for (Map<String, String> 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<String, Object> paramMap = UtilHttp.getParameterMap(request);
|
||||
StringBuilder queryString = new StringBuilder();
|
||||
if (UtilValidate.isNotEmpty(paramMap)) {
|
||||
queryString.append("?");
|
||||
for (Map.Entry<String, Object> 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<String> pathInfo = StringUtil.split(path, "/");
|
||||
if (pathInfo == null) {
|
||||
public static String getOverrideViewUri(String path) {
|
||||
List<String> 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<String, Object> urlParams = UtilHttp.getUrlOnlyParameterMap(request);
|
||||
String queryString = UtilHttp.urlEncodeArgs(urlParams, false);
|
||||
return queryString;
|
||||
} else {
|
||||
StringBuilder queryString = new StringBuilder();
|
||||
queryString.append("?");
|
||||
for (Map.Entry<String, String> 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<Map<String, String>> afterLoginEvents = requestManager.getAfterLoginEventList();
|
||||
if (afterLoginEvents != null) {
|
||||
for (Map<String, String> 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<Map<String, String>> beforeLogoutEvents = requestManager.getBeforeLogoutEventList();
|
||||
if (beforeLogoutEvents != null) {
|
||||
for (Map<String, String> 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;
|
||||
}
|
||||
|
||||
@@ -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<String, Map<String, String>> getHandlerMap() {
|
||||
return ConfigXMLReader.getHandlerMap(configFileUrl);
|
||||
}
|
||||
|
||||
/** Gets the class name of the named handler */
|
||||
public String getHandlerClass(String name, int type) {
|
||||
Map<String, Map<String, String>> map = getHandlerMap();
|
||||
Map<String, String> 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<String> getHandlerKeys(int type) {
|
||||
Map<String, Map<String, String>> map = getHandlerMap();
|
||||
Map<String, String> 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<String> result = FastList.newInstance();
|
||||
result.addAll(hMap.keySet());
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> getRequestMapMap(String uriStr) {
|
||||
if (UtilValidate.isNotEmpty(uriStr)) {
|
||||
return ConfigXMLReader.getRequestMap(configFileUrl).get(uriStr);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getRequestAttribute(String uriStr, String attribute) {
|
||||
Map<String, Object> 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<String, String> 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<String, Object> uri = getRequestMapMap(uriStr);
|
||||
if (uri == null) return null;
|
||||
Map<String, String> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<Map<String, String>> getFirstVisitEvents() {
|
||||
return (Collection<Map<String, String>>) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.FIRSTVISIT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<Map<String, String>> getPreProcessor() {
|
||||
return (Collection<Map<String, String>>) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.PREPROCESSOR);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<Map<String, String>> getPostProcessor() {
|
||||
return (Collection<Map<String, String>>) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.POSTPROCESSOR);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Map<String, String>> getAfterLoginEventList() {
|
||||
return (List<Map<String, String>>) ConfigXMLReader.getConfigMap(configFileUrl).get("after-login");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Map<String, String>> getBeforeLogoutEventList() {
|
||||
return (List<Map<String, String>>) ConfigXMLReader.getConfigMap(configFileUrl).get("before-logout");
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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<String, EventHandler> 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<String> handlers = requestManager.getHandlerKeys(RequestManager.EVENT_HANDLER_KEY);
|
||||
Set<String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<String, ViewHandler> 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<String> handlers = requestManager.getHandlerKeys(RequestManager.VIEW_HANDLER_KEY);
|
||||
Set<String> 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);
|
||||
|
||||
@@ -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<String, Object> 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<String, String> 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 {
|
||||
|
||||
+14
-14
@@ -41,7 +41,7 @@ public class ControllerRequestArtifactInfo extends ArtifactInfoBase {
|
||||
protected URL controllerXmlUrl;
|
||||
protected String requestUri;
|
||||
|
||||
protected Map<String, Object> requestInfoMap;
|
||||
protected ConfigXMLReader.RequestMap requestInfoMap;
|
||||
|
||||
protected ServiceArtifactInfo serviceCalledByRequestEvent = null;
|
||||
protected Set<ControllerRequestArtifactInfo> requestsThatAreResponsesToThisRequest = new TreeSet<ControllerRequestArtifactInfo>();
|
||||
@@ -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<String, String> responseMap = UtilGenerics.checkMap(this.requestInfoMap.get(ConfigXMLReader.RESPONSE_MAP));
|
||||
for (String responseValue: responseMap.values()) {
|
||||
if (responseValue.startsWith("view:")) {
|
||||
String viewUri = responseValue.substring(5);
|
||||
Map<String, ConfigXMLReader.RequestResponse> 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());
|
||||
|
||||
+5
-8
@@ -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<String, String> 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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
</#if>
|
||||
|
||||
<#assign username = requestParameters.USERNAME?default((sessionAttributes.autoUserLogin.userLoginId)?default(""))>
|
||||
<#if username != "">
|
||||
<#assign focusName = false>
|
||||
@@ -49,7 +44,7 @@ under the License.
|
||||
<table width='100%' border='0' cellspacing='0' cellpadding='0' class='boxbottom'>
|
||||
<tr>
|
||||
<td align="center" valign="middle" width='100%'>
|
||||
<form method="post" action="<@ofbizUrl>login${previousParams?if_exists}</@ofbizUrl>" name="loginform" style='margin: 0;'>
|
||||
<form method="post" action="<@ofbizUrl>login</@ofbizUrl>" name="loginform" style='margin: 0;'>
|
||||
<table width='100%' border='0' cellpadding='0' cellspacing='2'>
|
||||
<tr>
|
||||
<td align="right">
|
||||
|
||||
@@ -19,11 +19,6 @@ under the License.
|
||||
|
||||
<#if requestAttributes.uiLabelMap?exists><#assign uiLabelMap = requestAttributes.uiLabelMap></#if>
|
||||
|
||||
<#assign previousParams = sessionAttributes._PREVIOUS_PARAMS_?if_exists>
|
||||
<#if previousParams?has_content>
|
||||
<#assign previousParams = "?" + previousParams>
|
||||
</#if>
|
||||
|
||||
<#assign username = requestParameters.USERNAME?default((sessionAttributes.autoUserLogin.userLoginId)?default(""))>
|
||||
<#if username != "">
|
||||
<#assign focusName = false>
|
||||
@@ -37,7 +32,7 @@ under the License.
|
||||
<h3>${uiLabelMap.CommonRegistered}</h3>
|
||||
</div>
|
||||
<div class="screenlet-body">
|
||||
<form method="post" action="<@ofbizUrl>login${previousParams?if_exists}</@ofbizUrl>" name="loginform">
|
||||
<form method="post" action="<@ofbizUrl>login</@ofbizUrl>" name="loginform">
|
||||
<table class="basic-table" cellspacing="0">
|
||||
<tr>
|
||||
<td class="label" style="width: 31%;">${uiLabelMap.CommonUsername}</td>
|
||||
@@ -55,9 +50,9 @@ under the License.
|
||||
</table>
|
||||
<input type="hidden" name="JavaScriptEnabled" value="N"/>
|
||||
<br/>
|
||||
<a href="<@ofbizUrl>forgotPassword${previousParams?if_exists}</@ofbizUrl>">${uiLabelMap.CommonForgotYourPassword}?</a>
|
||||
<a href="<@ofbizUrl>forgotPassword</@ofbizUrl>">${uiLabelMap.CommonForgotYourPassword}?</a>
|
||||
<br/>
|
||||
<a href="<@ofbizUrl>newRegisterLogin${previousParams?if_exists}</@ofbizUrl>">${uiLabelMap.NewRegistration}</a>
|
||||
<a href="<@ofbizUrl>newRegisterLogin</@ofbizUrl>">${uiLabelMap.NewRegistration}</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user