Commit 7508917a authored by Mathieu Lirzin's avatar Mathieu Lirzin

Improved: Remove ‘RequestHandler#ControllerConfig’ wrapper

(OFBIZ-11313)

‘RequestHandler#ControllerConfig’ was a wrapper around
‘ConfigXMLReader#ControllerConfig’ used as a convenience to gather
error handling when accessing configuration properties. Since the
later is now only throwing exceptions when instantiating the object,
‘RequestHandler#ControllerConfig’ is not useful anymore.
parent 6c745f6e
......@@ -285,7 +285,7 @@ checkstyle {
// the sum of errors that were present before introducing the
// ‘checkstyle’ tool present in the framework and in the official
// plugins.
tasks.checkstyleMain.maxErrors = 37725
tasks.checkstyleMain.maxErrors = 37713
// Currently there are a lot of errors so we need to temporarily
// hide them to avoid polluting the terminal output.
showViolations = false
......
......@@ -182,6 +182,9 @@ public class ConfigXMLReader {
}
public static class ControllerConfig {
private static final String DEFAULT_REDIRECT_STATUS_CODE =
UtilProperties.getPropertyValue("requestHandler", "status-code", "302");
public URL url;
private String errorpage;
private String protectView;
......@@ -299,8 +302,14 @@ public class ConfigXMLReader {
return getIncludes(ccfg -> ccfg.securityClass);
}
/**
* Provides the status code that should be used when redirecting an HTTP client.
*
* @return an HTTP response status code.
*/
public String getStatusCode() {
return getIncludes(ccfg -> ccfg.statusCode);
String status = getIncludes(ccfg -> ccfg.statusCode);
return UtilValidate.isEmpty(status) ? DEFAULT_REDIRECT_STATUS_CODE : status;
}
public Map<String, String> getViewHandlerMap() {
......
......@@ -161,12 +161,7 @@ public class ServiceMultiEventHandler implements EventHandler {
} catch (WebAppConfigurationException e) {
throw new EventHandlerException(e);
}
boolean eventGlobalTransaction;
try {
eventGlobalTransaction = controllerConfig.getRequestMapMap().get(requestUri).event.globalTransaction;
} catch (WebAppConfigurationException e) {
throw new EventHandlerException(e);
}
boolean eventGlobalTransaction = controllerConfig.getRequestMapMap().get(requestUri).event.globalTransaction;
// big try/finally to make sure commit or rollback are run
boolean beganTrans = false;
......
......@@ -40,6 +40,7 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.ofbiz.base.util.collections.MultivaluedMapContext;
import org.apache.ofbiz.webapp.control.ConfigXMLReader.ControllerConfig;
import org.apache.ofbiz.webapp.control.ConfigXMLReader.RequestMap;
import org.apache.ofbiz.webapp.control.ConfigXMLReader.ViewMap;
import org.junit.Before;
......@@ -52,15 +53,15 @@ public class RequestHandlerTests {
private Map<String, ViewMap> viewMaps;
private HttpServletRequest req;
private Element dummyElement;
private RequestHandler.ControllerConfig ccfg;
private ControllerConfig ccfg;
@Before
public void setUp() {
ccfg = mock(RequestHandler.ControllerConfig.class);
ccfg = mock(ControllerConfig.class);
reqMaps = new MultivaluedMapContext<>();
viewMaps = new HashMap<>();
when(ccfg.getDefaultRequest()).thenReturn(null);
when(ccfg.getRequestMapMap()).thenReturn(reqMaps);
when(ccfg.getRequestMapMultiMap()).thenReturn(reqMaps);
when(ccfg.getViewMapMap()).thenReturn(viewMaps);
req = mock(HttpServletRequest.class);
dummyElement = mock(Element.class);
......
......@@ -27,7 +27,6 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.UtilCodec;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.apache.ofbiz.base.util.UtilHttp;
......@@ -36,7 +35,6 @@ import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.service.LocalDispatcher;
import org.apache.ofbiz.webapp.control.ConfigXMLReader;
import org.apache.ofbiz.webapp.control.RequestHandler;
import org.apache.ofbiz.webapp.control.WebAppConfigurationException;
import org.apache.ofbiz.webapp.taglib.ContentUrlTag;
import org.apache.ofbiz.widget.model.ModelForm;
import org.apache.ofbiz.widget.model.ModelFormField;
......@@ -300,12 +298,7 @@ public final class WidgetWorker {
String requestUri = (target.indexOf('?') > -1) ? target.substring(0, target.indexOf('?')) : target;
ServletContext servletContext = request.getSession().getServletContext();
RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_");
ConfigXMLReader.RequestMap requestMap = null;
try {
requestMap = rh.getControllerConfig().getRequestMapMap().get(requestUri);
} catch (WebAppConfigurationException e) {
Debug.logError(e, "Exception thrown while parsing controller.xml file: ", module);
}
ConfigXMLReader.RequestMap requestMap = rh.getControllerConfig().getRequestMapMap().get(requestUri);
if (requestMap != null && requestMap.event != null) {
return "hidden-form";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment