Re: svn commit: r1862333 - /ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java

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

Re: svn commit: r1862333 - /ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java

Jacques Le Roux
Administrator
Hi Mathieu,

This may help you:

2019-06-30 10:12:28,884 |main                 |ConfigXMLReader               |I| controller loaded: 0.0s, 0 requests, 0 views in file:/C:/projectsASF/ofbiz/framework/common/webcommon/WEB-INF/handlers-controller.xml
Jun 30, 2019 10:12:28 AM org.apache.catalina.core.ApplicationContext log
SEVERE: Servlet.init() for servlet [ControlServlet] threw exception
org.apache.ofbiz.base.util.GeneralRuntimeException: null ()
         at org.apache.ofbiz.webapp.view.ViewFactory.<init>(ViewFactory.java:63)
         at org.apache.ofbiz.webapp.control.RequestHandler.<init>(RequestHandler.java:168)
         at org.apache.ofbiz.webapp.control.RequestHandler.getRequestHandler(RequestHandler.java:153)
         at org.apache.ofbiz.webapp.control.ControlServlet.init(ControlServlet.java:78)
         at javax.servlet.GenericServlet.init(GenericServlet.java:203)
         at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1122)

HTH

Jacques

Le 30/06/2019 à 10:38, [hidden email] a écrit :

> Author: jleroux
> Date: Sun Jun 30 08:38:58 2019
> New Revision: 1862333
>
> URL: http://svn.apache.org/viewvc?rev=1862333&view=rev
> Log:
> Reverted: Mathieu's changes in ConfigXMLReader.java from yesterday
>
> OFBiz was crashing
>
> Reverts rev. 1862324, 1862323, 1862322
>
>
>
> Modified:
>      ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java
>
> Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java
> URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java?rev=1862333&r1=1862332&r2=1862333&view=diff
> ==============================================================================
> --- ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java (original)
> +++ ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java Sun Jun 30 08:38:58 2019
> @@ -31,7 +31,6 @@ import java.util.List;
>   import java.util.Map;
>   import java.util.Set;
>   import java.util.function.Function;
> -import java.util.stream.Collectors;
>  
>   import javax.servlet.ServletContext;
>  
> @@ -188,13 +187,13 @@ public class ConfigXMLReader {
>           private String defaultRequest;
>           private String statusCode;
>           private List<URL> includes = new ArrayList<>();
> -        private final Map<String, Event> firstVisitEventList = new LinkedHashMap<>();
> -        private final Map<String, Event> preprocessorEventList = new LinkedHashMap<>();
> -        private final Map<String, Event> postprocessorEventList = new LinkedHashMap<>();
> -        private final Map<String, Event> afterLoginEventList = new LinkedHashMap<>();
> -        private final Map<String, Event> beforeLogoutEventList = new LinkedHashMap<>();
> -        private final Map<String, String> eventHandlerMap = new HashMap<>();
> -        private final Map<String, String> viewHandlerMap = new HashMap<>();
> +        private Map<String, Event> firstVisitEventList = new LinkedHashMap<>();
> +        private Map<String, Event> preprocessorEventList = new LinkedHashMap<>();
> +        private Map<String, Event> postprocessorEventList = new LinkedHashMap<>();
> +        private Map<String, Event> afterLoginEventList = new LinkedHashMap<>();
> +        private Map<String, Event> beforeLogoutEventList = new LinkedHashMap<>();
> +        private Map<String, String> eventHandlerMap = new HashMap<>();
> +        private Map<String, String> viewHandlerMap = new HashMap<>();
>           private MultivaluedMapContext<String, RequestMap> requestMapMap = new MultivaluedMapContext<>();
>           private Map<String, ViewMap> viewMapMap = new HashMap<>();
>  
> @@ -310,35 +309,6 @@ public class ConfigXMLReader {
>               return pushIncludes(ccfg -> ccfg.viewMapMap);
>           }
>  
> -        /**
> -         * Computes the name of an XML element.
> -         *
> -         * @param el  the element containing "type" and/or "name" attributes
> -         * @return the derived name.
> -         * @throws NullPointerException when {@code el} is {@code null}
> -         */
> -        private static String elementToName(Element el) {
> -            String eventName = el.getAttribute("name");
> -            return eventName.isEmpty()
> -                    ? el.getAttribute("type") + "::" + el.getAttribute("path") + "::" + el.getAttribute("invoke")
> -                    : eventName;
> -        }
> -
> -        /**
> -         * Collects some events defined in an XML tree.
> -         *
> -         * @param root  the root of the XML tree
> -         * @param childName  the name of the element inside {@code root} containing the events
> -         * @return a map associating element derived names to an event objects.
> -         */
> -        private static void collectEvents(Element root, String childName, Map<String, Event> coll) {
> -            Element child = UtilXml.firstChildElement(root, childName);
> -            if (child != null) {
> -                UtilXml.childElementList(child, "event").stream()
> -                       .forEachOrdered(ev -> coll.put(elementToName(ev), new Event(ev)));
> -            }
> -        }
> -
>           private void loadGeneralConfig(Element rootElement) {
>               this.errorpage = UtilXml.childElementValue(rootElement, "errorpage");
>               this.statusCode = UtilXml.childElementValue(rootElement, "status-code");
> @@ -352,19 +322,75 @@ public class ConfigXMLReader {
>               if (defaultRequestElement != null) {
>                   this.defaultRequest = defaultRequestElement.getAttribute("request-uri");
>               }
> -            collectEvents(rootElement, "firstvisit", firstVisitEventList);
> -            collectEvents(rootElement, "preprocessor", preprocessorEventList);
> -            collectEvents(rootElement, "postprocessor", postprocessorEventList);
> -            collectEvents(rootElement, "after-login", afterLoginEventList);
> -            collectEvents(rootElement, "before-logout", beforeLogoutEventList);
> +            // first visit event
> +            Element firstvisitElement = UtilXml.firstChildElement(rootElement, "firstvisit");
> +            if (firstvisitElement != null) {
> +                for (Element eventElement : UtilXml.childElementList(firstvisitElement, "event")) {
> +                    String eventName = eventElement.getAttribute("name");
> +                    if (eventName.isEmpty()) {
> +                        eventName = eventElement.getAttribute("type") + "::" + eventElement.getAttribute("path") + "::" + eventElement.getAttribute("invoke");
> +                    }
> +                    this.firstVisitEventList.put(eventName, new Event(eventElement));
> +                }
> +            }
> +            // preprocessor events
> +            Element preprocessorElement = UtilXml.firstChildElement(rootElement, "preprocessor");
> +            if (preprocessorElement != null) {
> +                for (Element eventElement : UtilXml.childElementList(preprocessorElement, "event")) {
> +                    String eventName = eventElement.getAttribute("name");
> +                    if (eventName.isEmpty()) {
> +                        eventName = eventElement.getAttribute("type") + "::" + eventElement.getAttribute("path") + "::" + eventElement.getAttribute("invoke");
> +                    }
> +                    this.preprocessorEventList.put(eventName, new Event(eventElement));
> +                }
> +            }
> +            // postprocessor events
> +            Element postprocessorElement = UtilXml.firstChildElement(rootElement, "postprocessor");
> +            if (postprocessorElement != null) {
> +                for (Element eventElement : UtilXml.childElementList(postprocessorElement, "event")) {
> +                    String eventName = eventElement.getAttribute("name");
> +                    if (eventName.isEmpty()) {
> +                        eventName = eventElement.getAttribute("type") + "::" + eventElement.getAttribute("path") + "::" + eventElement.getAttribute("invoke");
> +                    }
> +                    this.postprocessorEventList.put(eventName, new Event(eventElement));
> +                }
> +            }
> +            // after-login events
> +            Element afterLoginElement = UtilXml.firstChildElement(rootElement, "after-login");
> +            if (afterLoginElement != null) {
> +                for (Element eventElement : UtilXml.childElementList(afterLoginElement, "event")) {
> +                    String eventName = eventElement.getAttribute("name");
> +                    if (eventName.isEmpty()) {
> +                        eventName = eventElement.getAttribute("type") + "::" + eventElement.getAttribute("path") + "::" + eventElement.getAttribute("invoke");
> +                    }
> +                    this.afterLoginEventList.put(eventName, new Event(eventElement));
> +                }
> +            }
> +            // before-logout events
> +            Element beforeLogoutElement = UtilXml.firstChildElement(rootElement, "before-logout");
> +            if (beforeLogoutElement != null) {
> +                for (Element eventElement : UtilXml.childElementList(beforeLogoutElement, "event")) {
> +                    String eventName = eventElement.getAttribute("name");
> +                    if (eventName.isEmpty()) {
> +                        eventName = eventElement.getAttribute("type") + "::" + eventElement.getAttribute("path") + "::" + eventElement.getAttribute("invoke");
> +                    }
> +                    this.beforeLogoutEventList.put(eventName, new Event(eventElement));
> +                }
> +            }
>           }
>  
>           private void loadHandlerMap(Element rootElement) {
> -            Map<Boolean, Map<String, String>> handlers = UtilXml.childElementList(rootElement, "handler").stream()
> -                    .collect(Collectors.partitioningBy(el -> "view".equals(el.getAttribute("type")),
> -                            Collectors.toMap(el -> el.getAttribute("name"), el -> el.getAttribute("className"))));
> -            viewHandlerMap.putAll(handlers.get(true));
> -            eventHandlerMap.putAll(handlers.get(false));
> +            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);
> +                }
> +            }
>           }
>  
>           protected void loadIncludes(Element rootElement) {
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r1862333 - /ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java

Mathieu Lirzin
Hello Jacques,

Jacques Le Roux <[hidden email]> writes:

> This may help you:
>
> 2019-06-30 10:12:28,884 |main                
> |ConfigXMLReader               |I| controller loaded: 0.0s, 0
> requests, 0 views in
> file:/C:/projectsASF/ofbiz/framework/common/webcommon/WEB-INF/handlers-controller.xml
> Jun 30, 2019 10:12:28 AM org.apache.catalina.core.ApplicationContext log
> SEVERE: Servlet.init() for servlet [ControlServlet] threw exception
> org.apache.ofbiz.base.util.GeneralRuntimeException: null ()
>         at org.apache.ofbiz.webapp.view.ViewFactory.<init>(ViewFactory.java:63)
>         at org.apache.ofbiz.webapp.control.RequestHandler.<init>(RequestHandler.java:168)
>         at org.apache.ofbiz.webapp.control.RequestHandler.getRequestHandler(RequestHandler.java:153)
>         at org.apache.ofbiz.webapp.control.ControlServlet.init(ControlServlet.java:78)
>         at javax.servlet.GenericServlet.init(GenericServlet.java:203)
>         at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1122)

There was a typo added in revision 1862323

--8<---------------cut here---------------start------------->8---
private void loadHandlerMap(Element rootElement) {
    Map<Boolean, Map<String, String>> handlers = UtilXml.childElementList(rootElement, "handler").stream()
            .collect(Collectors.partitioningBy(el -> "view".equals(el.getAttribute("type")),
                    Collectors.toMap(el -> el.getAttribute("name"), el -> el.getAttribute("className"))));
    viewHandlerMap.putAll(handlers.get(true));
    eventHandlerMap.putAll(handlers.get(false));
}
--8<---------------cut here---------------end--------------->8---

The "classname" attribute does not exist and should be "class".  I will
commit the fixed version.

Thanks for spotting my mistake and taking care of the revert.

--
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761  070D 0ADE E100 9460 4D37