svn commit: r509068 - in /ofbiz/trunk/framework/webapp: dtd/site-conf.xsd src/org/ofbiz/webapp/control/ConfigXMLReader.java src/org/ofbiz/webapp/control/RequestHandler.java src/org/ofbiz/webapp/control/RequestManager.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r509068 - in /ofbiz/trunk/framework/webapp: dtd/site-conf.xsd src/org/ofbiz/webapp/control/ConfigXMLReader.java src/org/ofbiz/webapp/control/RequestHandler.java src/org/ofbiz/webapp/control/RequestManager.java

jaz-3
Author: jaz
Date: Sun Feb 18 18:52:31 2007
New Revision: 509068

URL: http://svn.apache.org/viewvc?view=rev&rev=509068
Log:
implemented default request for web applications; setting a default-request will forward all requests which do not have a valid mapping to this specific request. Here you can process additional information, forward to a landing page, etc

Modified:
    ofbiz/trunk/framework/webapp/dtd/site-conf.xsd
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java

Modified: ofbiz/trunk/framework/webapp/dtd/site-conf.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd?view=diff&rev=509068&r1=509067&r2=509068
==============================================================================
--- ofbiz/trunk/framework/webapp/dtd/site-conf.xsd (original)
+++ ofbiz/trunk/framework/webapp/dtd/site-conf.xsd Sun Feb 18 18:52:31 2007
@@ -31,6 +31,7 @@
                 <xs:element minOccurs="0" ref="postprocessor"/>
                 <xs:element minOccurs="0" ref="after-login"/>
                 <xs:element minOccurs="0" ref="before-logout"/>
+                <xs:element minOccurs="0" maxOccurs="1" ref="default-request"/>
                 <xs:element minOccurs="0" maxOccurs="unbounded" ref="request-map"/>
                 <xs:element minOccurs="0" maxOccurs="unbounded" ref="view-map"/>
             </xs:sequence>
@@ -108,6 +109,14 @@
             </xs:sequence>
         </xs:complexType>
     </xs:element>
+    <xs:element name="default-request">
+        <xs:complexType>
+            <xs:attributeGroup ref="attlist.default-request"/>
+        </xs:complexType>
+    </xs:element>
+    <xs:attributeGroup name="attlist.default-request">
+        <xs:attribute type="xs:string" name="request-uri" use="required"/>        
+    </xs:attributeGroup>
     <xs:element name="request-map">
         <xs:complexType>
             <xs:sequence>

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java?view=diff&rev=509068&r1=509067&r2=509068
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java Sun Feb 18 18:52:31 2007
@@ -67,6 +67,7 @@
         public Map handlerMap = FastMap.newInstance();
         public Map requestMap = FastMap.newInstance();
         public Map viewMap = FastMap.newInstance();
+        public String defaultRequest = null;
 
         public ControllerConfig(URL url) {
             this.url = url;
@@ -77,6 +78,7 @@
                 this.handlerMap = loadHandlerMap(rootElement, url);
                 this.requestMap = loadRequestMap(rootElement, url);
                 this.viewMap = loadViewMap(rootElement, url);
+                this.defaultRequest = loadDefaultRequest(rootElement, url);
             }
         }
     }
@@ -136,7 +138,7 @@
 
     /** Loads the XML file and returns the root element */
     public static Element loadDocument(URL location) {
-        Document document = null;
+        Document document;
         try {
             document = UtilXml.readXmlDocument(location, true);
             Element rootElement = document.getDocumentElement();
@@ -250,15 +252,14 @@
         /* Debugging */
         if (Debug.verboseOn()) {
             Debug.logVerbose("-------- Request Mappings --------", module);
-            FastMap debugMap = map;
-            Set debugSet = debugMap.keySet();
+            //FastMap debugMap = map;
+            Set debugSet = map.keySet();
             Iterator i = debugSet.iterator();
 
             while (i.hasNext()) {
                 Object o = i.next();
                 String request = (String) o;
-                FastMap thisURI = (FastMap) debugMap.get(o);
-
+                Map thisURI = (Map) map.get(o);
 
                 StringBuffer verboseMessageBuffer = new StringBuffer();
 
@@ -268,7 +269,7 @@
                     String name = (String) lo;
                     String value = (String) thisURI.get(lo);
 
-                    verboseMessageBuffer.append("[" + name + "=>" + value + "]");
+                    verboseMessageBuffer.append("[").append(name).append("=>").append(value).append("]");
                 }
                 Debug.logVerbose(request + " :: " + verboseMessageBuffer.toString(), module);
             }
@@ -345,14 +346,14 @@
         /* Debugging */
         if (Debug.verboseOn()) {
             Debug.logVerbose("-------- View Mappings --------", module);
-            FastMap debugMap = map;
-            Set debugSet = debugMap.keySet();
+            //FastMap debugMap = map;
+            Set debugSet = map.keySet();
             Iterator i = debugSet.iterator();
     
             while (i.hasNext()) {
                 Object o = i.next();
                 String request = (String) o;
-                FastMap thisURI = (FastMap) debugMap.get(o);
+                Map thisURI = (Map) map.get(o);
     
                 StringBuffer verboseMessageBuffer = new StringBuffer();
     
@@ -362,7 +363,7 @@
                     String name = (String) lo;
                     String value = (String) thisURI.get(lo);
     
-                    verboseMessageBuffer.append("[" + name + "=>" + value + "]");
+                    verboseMessageBuffer.append("[").append(name).append("=>").append(value).append("]");
                 }
                 Debug.logVerbose(request + " :: " + verboseMessageBuffer.toString(), module);
             }
@@ -546,6 +547,27 @@
         double totalSeconds = (System.currentTimeMillis() - startTime)/1000.0;
         if (Debug.infoOn()) Debug.logInfo("ConfigMap Created: (" + map.size() + ") records in " + totalSeconds + "s", module);
         return map;
+    }
+
+    /** Gets the default-request from the configuration */
+    public static String getDefaultRequest(URL xml) {
+        ControllerConfig controllerConfig = getControllerConfig(xml);
+        return controllerConfig != null ? controllerConfig.defaultRequest : null;
+    }
+
+    public static String loadDefaultRequest(Element root, URL xml) {
+        if (root == null) {
+            root = loadDocument(xml);
+        }
+        if (root == null) {
+            return null;
+        }
+
+        Element e = UtilXml.firstChildElement(root, "default-request");
+        if (e != null) {
+            return e.getAttribute("request-uri");
+        }
+        return null;
     }
 
     /** Gets a FastMap of handler mappings. */

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?view=diff&rev=509068&r1=509067&r2=509068
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java Sun Feb 18 18:52:31 2007
@@ -85,11 +85,11 @@
     }
 
     public void doRequest(HttpServletRequest request, HttpServletResponse response, String chain,
-                          GenericValue userLogin, GenericDelegator delegator) throws RequestHandlerException {
+            GenericValue userLogin, GenericDelegator delegator) throws RequestHandlerException {
 
-        String eventType = null;
-        String eventPath = null;
-        String eventMethod = null;
+        String eventType;
+        String eventPath;
+        String eventMethod;
 
         // workaraound if we are in the root webapp
         String cname = UtilHttp.getApplicationName(request);
@@ -116,8 +116,13 @@
             if (Debug.infoOn()) Debug.logInfo("[RequestHandler]: Chain in place: requestUri=" + requestUri + " nextView=" + nextView + " sessionId=" + UtilHttp.getSessionId(request), module);
         } else {
             // 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)) {
-                throw new RequestHandlerException("Unknown request [" + requestUri + "]; this request does not exist or cannot be called directly.");
+                if (!requestManager.allowDirectRequest(requestManager.getDefaultRequest())) {
+                    throw new RequestHandlerException("Unknown request [" + requestUri + "]; this request does not exist or cannot be called directly.");
+                } else {
+                    requestUri = requestManager.getDefaultRequest();
+                }
             }
 
             // Check if we SHOULD be secure and are not. If we are posting let it pass to not lose data. (too late now anyway)
@@ -209,7 +214,7 @@
             String checkLoginType = requestManager.getEventType("checkLogin");
             String checkLoginPath = requestManager.getEventPath("checkLogin");
             String checkLoginMethod = requestManager.getEventMethod("checkLogin");
-            String checkLoginReturnString = null;
+            String checkLoginReturnString;
 
             try {
                 checkLoginReturnString = this.runEvent(request, response, checkLoginType,
@@ -220,10 +225,7 @@
             if (!"success".equalsIgnoreCase(checkLoginReturnString)) {
                 // previous URL already saved by event, so just do as the return says...
                 eventReturnString = checkLoginReturnString;
-                eventType = checkLoginType;
-                eventPath = checkLoginPath;
-                eventMethod = checkLoginMethod;
-                requestUri = "checkLogin";
+                requestUri = "checkLogin";                            
             }
         }
 
@@ -290,7 +292,7 @@
 
         // 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 preRequestMap = null;
+        Map preRequestMap;
         if(preReqAttStr!=null){
             request.getSession().removeAttribute("_REQ_ATTR_MAP_");
             byte [] reqAttrMapBytes = StringUtil.fromHexString(preReqAttStr);
@@ -338,8 +340,6 @@
             Debug.logInfo("[RequestHandler.doRequest]: Response is a chained request." + " sessionId=" + UtilHttp.getSessionId(request), module);
             nextView = nextView.substring(8);
             doRequest(request, response, nextView, userLogin, delegator);
-            return; // this just to be safe; not really needed
-
         } else { // handle views
             // first invoke the post-processor events.
             Collection postProcEvents = requestManager.getPostProcessor();
@@ -404,7 +404,7 @@
 
     /** Find the event handler and invoke an event. */
     public String runEvent(HttpServletRequest request, HttpServletResponse response, String type,
-                           String path, String method) throws EventHandlerException {
+            String path, String method) throws EventHandlerException {
         EventHandler eventHandler = eventFactory.getEventHandler(type);
         return eventHandler.invoke(path, method, request, response);
     }
@@ -550,7 +550,7 @@
 
         String viewType = requestManager.getViewType(view);
         String tempView = requestManager.getViewPage(view);
-        String nextPage = null;
+        String nextPage;
 
         if (tempView == null) {
             if (!allowExtView) {
@@ -682,7 +682,7 @@
         Boolean enableHttps = null;
 
         // load the properties from the website entity
-        GenericValue webSite = null;
+        GenericValue webSite;
         if (webSiteId != null) {
             try {
                 webSite = delegator.findByPrimaryKeyCache("WebSite", UtilMisc.toMap("webSiteId", webSiteId));
@@ -712,7 +712,7 @@
             httpServer = UtilProperties.getPropertyValue("url.properties", "force.http.host");
         }
         if (enableHttps == null) {
-            enableHttps = new Boolean(UtilProperties.propertyValueEqualsIgnoreCase("url.properties", "port.https.enabled", "Y"));
+            enableHttps = Boolean.valueOf(UtilProperties.propertyValueEqualsIgnoreCase("url.properties", "port.https.enabled", "Y"));
         }
 
         // create the path the the control servlet
@@ -747,7 +747,7 @@
                 newURL.append("http://");
                 newURL.append(server);
                 if (!httpPort.equals("80")) {
-                    newURL.append(":" + httpPort);
+                    newURL.append(":").append(httpPort);
                 }
 
                 didFullStandard = true;
@@ -762,7 +762,7 @@
         }
         newURL.append(url);
 
-        String encodedUrl = null;
+        String encodedUrl;
         if (encode) {
             boolean forceManualJsessionid = false;
 

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java?view=diff&rev=509068&r1=509067&r2=509068
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java Sun Feb 18 18:52:31 2007
@@ -64,7 +64,7 @@
     /** Gets the class name of the named handler */
     public String getHandlerClass(String name, int type) {
         Map map = getHandlerMap();
-        Map hMap = null;
+        Map hMap;
 
         if (type == 1) {
             hMap = (Map) map.get("view");
@@ -81,7 +81,7 @@
 
     public List getHandlerKeys(int type) {
         Map map = getHandlerMap();
-        Map hMap = null;
+        Map hMap;
 
         if (type == 1) {
             hMap = (Map) map.get("view");
@@ -160,8 +160,7 @@
         Map uri = getRequestMapMap(uriStr);
 
         if (uri != null) {
-            String EVENT_GLOBAL_TRANSACTION = "global-transaction";
-            return new Boolean((String) uri.get(ConfigXMLReader.EVENT_GLOBAL_TRANSACTION)).booleanValue();
+            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 \"" +
@@ -268,7 +267,7 @@
 
     /** Gets the default error page from the configMap or static site default */
     public String getDefaultErrorPage() {
-        String errorPage = null;
+        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;
@@ -282,10 +281,7 @@
             String value = (String) uri.get(ConfigXMLReader.SECURITY_AUTH);
 
             //if (Debug.verboseOn()) Debug.logVerbose("Require Auth: " + value, module);
-            if ("true".equalsIgnoreCase(value))
-                return true;
-            else
-                return false;
+            return "true".equalsIgnoreCase(value);
         } else
             return false;
     }
@@ -297,10 +293,7 @@
             String value = (String) uri.get(ConfigXMLReader.SECURITY_HTTPS);
 
             //if (Debug.verboseOn()) Debug.logVerbose("Requires HTTPS: " + value, module);
-            if ("true".equalsIgnoreCase(value))
-                return true;
-            else
-                return false;
+            return "true".equalsIgnoreCase(value);
         } else
             return false;
     }
@@ -312,10 +305,7 @@
             String value = (String) uri.get(ConfigXMLReader.SECURITY_EXTVIEW);
 
             //if (Debug.verboseOn()) Debug.logVerbose("Allow External View: " + value, module);
-            if ("false".equalsIgnoreCase(value))
-                return false;
-            else
-                return true;
+            return !"false".equalsIgnoreCase(value);
         } else
             return true;
     }
@@ -327,36 +317,32 @@
             String value = (String) uri.get(ConfigXMLReader.SECURITY_DIRECT);
 
             //if (Debug.verboseOn()) Debug.logVerbose("Allow Direct Request: " + value, module);
-            if ("false".equalsIgnoreCase(value))
-                return false;
-            else
-                return true;
+            return !"false".equalsIgnoreCase(value);
         } else
             return false;
     }
 
+    public String getDefaultRequest() {
+        return ConfigXMLReader.getDefaultRequest(configFileUrl);
+    }
+
     public Collection getFirstVisitEvents() {
-        Collection c = (Collection) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.FIRSTVISIT);
-        return c;
+        return (Collection) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.FIRSTVISIT);
     }
 
     public Collection getPreProcessor() {
-        Collection c = (Collection) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.PREPROCESSOR);
-        return c;
+        return (Collection) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.PREPROCESSOR);
     }
 
     public Collection getPostProcessor() {
-        Collection c = (Collection) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.POSTPROCESSOR);
-        return c;
+        return (Collection) ConfigXMLReader.getConfigMap(configFileUrl).get(ConfigXMLReader.POSTPROCESSOR);
     }
 
     public List getAfterLoginEventList() {
-        List lst = (List) ConfigXMLReader.getConfigMap(configFileUrl).get("after-login");
-        return lst;
+        return (List) ConfigXMLReader.getConfigMap(configFileUrl).get("after-login");
     }
 
     public List getBeforeLogoutEventList() {
-        List lst = (List) ConfigXMLReader.getConfigMap(configFileUrl).get("before-logout");
-        return lst;
+        return (List) ConfigXMLReader.getConfigMap(configFileUrl).get("before-logout");        
     }
 }