svn commit: r1761234 - in /ofbiz/trunk/framework/webapp: dtd/site-conf.xsd src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java src/main/java/org/apache/ofbiz/webapp/event/JavaEventHandler.java

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

svn commit: r1761234 - in /ofbiz/trunk/framework/webapp: dtd/site-conf.xsd src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java src/main/java/org/apache/ofbiz/webapp/event/JavaEventHandler.java

ashish-18
Author: ashish
Date: Sat Sep 17 13:38:23 2016
New Revision: 1761234

URL: http://svn.apache.org/viewvc?rev=1761234&view=rev
Log:
Improved: Enhance Event Handler to support an transaction-timeout attribute in the <event> element.
(OFBIZ-8160)
Thanks: Ravi for the contribution. Thanks Jacopo for your comment, it was very helpful.

Modified:
    ofbiz/trunk/framework/webapp/dtd/site-conf.xsd
    ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java
    ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/JavaEventHandler.java

Modified: ofbiz/trunk/framework/webapp/dtd/site-conf.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd?rev=1761234&r1=1761233&r2=1761234&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/dtd/site-conf.xsd (original)
+++ ofbiz/trunk/framework/webapp/dtd/site-conf.xsd Sat Sep 17 13:38:23 2016
@@ -470,6 +470,14 @@ under the License.
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
+        <xs:attribute name="transaction-timeout" type="xs:int" default="0">
+            <xs:annotation>
+                <xs:documentation>
+                    Defines the timeout for the transaction, in seconds.
+                    Defaults to the value set in the TransactionFactory being used (typically 60 seconds).
+                </xs:documentation>
+            </xs:annotation>
+        </xs:attribute>
     </xs:attributeGroup>
     <xs:element name="response">
         <xs:annotation>

Modified: ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java?rev=1761234&r1=1761233&r2=1761234&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java (original)
+++ ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ConfigXMLReader.java Sat Sep 17 13:38:23 2016
@@ -503,6 +503,7 @@ public class ConfigXMLReader {
         public String path;
         public String invoke;
         public boolean globalTransaction = true;
+        public int transactionTimeout;
         public Metrics metrics = null;
 
         public Event(Element eventElement) {
@@ -510,6 +511,7 @@ public class ConfigXMLReader {
             this.path = eventElement.getAttribute("path");
             this.invoke = eventElement.getAttribute("invoke");
             this.globalTransaction = !"false".equals(eventElement.getAttribute("global-transaction"));
+            this.transactionTimeout = Integer.valueOf(eventElement.getAttribute("transaction-timeout"));
             // Get metrics.
             Element metricsElement = UtilXml.firstChildElement(eventElement, "metric");
             if (metricsElement != null) {

Modified: ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/JavaEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/JavaEventHandler.java?rev=1761234&r1=1761233&r2=1761234&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/JavaEventHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/event/JavaEventHandler.java Sat Sep 17 13:38:23 2016
@@ -77,10 +77,10 @@ public class JavaEventHandler implements
         Debug.logVerbose("*[[Event invocation]]*", module);
         Object[] params = new Object[] {request, response};
 
-        return invoke(event.path, event.invoke, eventClass, paramTypes, params);
+        return invoke(event.path, event.invoke, eventClass, paramTypes, params, event.transactionTimeout);
     }
 
-    private String invoke(String eventPath, String eventMethod, Class<?> eventClass, Class<?>[] paramTypes, Object[] params) throws EventHandlerException {
+    private String invoke(String eventPath, String eventMethod, Class<?> eventClass, Class<?>[] paramTypes, Object[] params, int transactionTimeout) throws EventHandlerException {
         boolean beganTransaction = false;
         if (eventClass == null) {
             throw new EventHandlerException("Error invoking event, the class " + eventPath + " was not found");
@@ -91,7 +91,11 @@ public class JavaEventHandler implements
 
         Debug.logVerbose("[Processing]: JAVA Event", module);
         try {
-            beganTransaction = TransactionUtil.begin();
+            if (transactionTimeout > 0) {
+                beganTransaction = TransactionUtil.begin(transactionTimeout);
+            } else {
+                beganTransaction = TransactionUtil.begin();
+            }
             Method m = eventClass.getMethod(eventMethod, paramTypes);
             String eventReturn = (String) m.invoke(null, params);