This is an automated email from the ASF dual-hosted git repository.
dixitdeepak pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new 2d3874bea8 Fixed xmldsrawdump StackOverflowError by streaming XML from
Groovy event (OFBIZ-13400) (#1165)
2d3874bea8 is described below
commit 2d3874bea861c9497eb69ce0551d1be88172bf60
Author: Deepak Dixit <[email protected]>
AuthorDate: Wed May 6 11:14:06 2026 +0530
Fixed xmldsrawdump StackOverflowError by streaming XML from Groovy event
(OFBIZ-13400) (#1165)
Route the WebTools xmldsrawdump request to a Groovy event and return a
none response instead of rendering the legacy JSP view. The JSP view
could re-enter the controller/view rendering path and repeatedly render
xmldsrawdump until Tomcat failed with StackOverflowError.
Remove the obsolete xmldsrawdump.jsp view and its view-map. The new raw
dump event streams XML directly, uses EntityQuery, and closes the
iterator with withCloseable.
---
.../ofbiz/webtools/entity/XmlDsRawDump.groovy | 70 ++++++++++++++++
.../webtools/template/entity/xmldsrawdump.jsp | 95 ----------------------
.../webapp/webtools/WEB-INF/controller.xml | 5 +-
3 files changed, 73 insertions(+), 97 deletions(-)
diff --git
a/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/XmlDsRawDump.groovy
b/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/XmlDsRawDump.groovy
new file mode 100644
index 0000000000..cc2c713788
--- /dev/null
+++
b/framework/webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/XmlDsRawDump.groovy
@@ -0,0 +1,70 @@
+/*
+ * 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.apache.ofbiz.webtools.entity
+
+import org.apache.ofbiz.entity.condition.EntityCondition
+import org.apache.ofbiz.entity.model.ModelViewEntity
+import org.apache.ofbiz.entity.util.EntityQuery
+
+if (!security.hasPermission('ENTITY_MAINT', session)) {
+ response.contentType = 'text/plain; charset=UTF-8'
+ response.writer.println('ERROR: You do not have permission to use this
page (ENTITY_MAINT needed)')
+ return 'success'
+}
+
+passedEntityNames = session.getAttribute('xmlrawdump_entitylist')
+session.removeAttribute('xmlrawdump_entitylist')
+EntityCondition entityDateCond = session.getAttribute('entityDateCond')
+session.removeAttribute('entityDateCond')
+
+if (!passedEntityNames) {
+ response.contentType = 'text/plain; charset=UTF-8'
+ response.writer.println('ERROR: No entityName list was found in the
session, go back to the export page and try again.')
+ return 'success'
+}
+
+reader = delegator.getModelReader()
+response.contentType = 'text/xml; charset=UTF-8'
+writer = response.writer
+writer.println('<?xml version="1.0" encoding="UTF-8"?>')
+writer.println('<entity-engine-xml>')
+
+numberWritten = 0
+try {
+ passedEntityNames.each { curEntityName ->
+ me = reader.getModelEntity(curEntityName)
+ entityQuery =
EntityQuery.use(delegator).from(curEntityName).cursorScrollInsensitive()
+ if (!me.getNoAutoStamp() && !(me instanceof ModelViewEntity) &&
entityDateCond) {
+ entityQuery.where(entityDateCond)
+ }
+ entityQuery.queryIterator().withCloseable { values ->
+ while ((value = values.next()) != null) {
+ value.writeXmlText(writer, '')
+ numberWritten++
+ }
+ }
+ }
+} catch (Exception e) {
+ logError(e, 'Failure in raw XML data source dump')
+ throw e
+}
+
+writer.println('</entity-engine-xml>')
+logInfo("Total records written from all entities: $numberWritten")
+return 'success'
diff --git a/framework/webtools/template/entity/xmldsrawdump.jsp
b/framework/webtools/template/entity/xmldsrawdump.jsp
deleted file mode 100644
index b3017b46f2..0000000000
--- a/framework/webtools/template/entity/xmldsrawdump.jsp
+++ /dev/null
@@ -1,95 +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.
---%><%@ page import="java.io.*, java.util.*, java.net.*, org.w3c.dom.*,
org.apache.ofbiz.security.*, org.apache.ofbiz.entity.*,
org.apache.ofbiz.entity.condition.*, org.apache.ofbiz.entity.util.*,
org.apache.ofbiz.base.util.*, org.apache.ofbiz.entity.model.*,
org.apache.ofbiz.entity.transaction.*" %><jsp:useBean id="security"
type="org.apache.ofbiz.security.Security" scope="request" /><jsp:useBean
id="delegator" type="org.apache.ofbiz.entity.GenericDelegator" scope="request"
/><%
- if(security.hasPermission("ENTITY_MAINT", session)) {
- TreeSet passedEntityNames = (TreeSet)
session.getAttribute("xmlrawdump_entitylist");
- session.removeAttribute("xmlrawdump_entitylist");
- EntityExpr entityDateCond = (EntityExpr)
session.getAttribute("entityDateCond");
- session.removeAttribute("entityDateCond");
- if (passedEntityNames != null) {
-
- ModelReader reader = delegator.getModelReader();
- Collection ec = reader.getEntityNames();
- TreeSet entityNames = new TreeSet(ec);
-
- int numberOfEntities = 0;
- long numberWritten = 0;
-
- response.setContentType("text/xml; charset=UTF-8");
- //UtilXml.writeXmlDocument(, document);
-
- if(!passedEntityNames.isEmpty()) {
- numberOfEntities = passedEntityNames.size();
-
- PrintWriter writer = null;
- ServletContext context = pageContext.getServletContext();
- writer = response.getWriter();
-
- writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- writer.println("<entity-engine-xml>");
-
- boolean beganTransaction = false;
- try {
- beganTransaction = TransactionUtil.begin();
-
- Iterator i = passedEntityNames.iterator();
- while(i.hasNext()) {
- String curEntityName = (String)i.next();
-
- ModelEntity me = reader.getModelEntity(curEntityName);
- EntityListIterator values = null;
- if (me.getNoAutoStamp() == true) {
- values = delegator.find(curEntityName, null, null,
null, null, null);
- } else {
- values = delegator.find(curEntityName, entityDateCond,
null, null, null, null);
- }
-
- GenericValue value = null;
- while ((value = (GenericValue) values.next()) != null) {
- value.writeXmlText(writer, "");
- numberWritten++;
- }
- values.close();
- }
- TransactionUtil.commit(beganTransaction);
- } catch (GenericEntityException e) {
- String errMsg = "Failure in operation, rolling back
transaction";
- String module = "xmldsrawdump.jsp";
- Debug.logError(e, errMsg, module);
- try {
- // only rollback the transaction if we started one...
- TransactionUtil.rollback(beganTransaction, errMsg, e);
- } catch (GenericEntityException e2) {
- Debug.logError(e2, "Could not rollback transaction: " +
e2.toString(), module);
- }
- // after rolling back, rethrow the exception
- throw e;
- } finally {
- // only commit the transaction if we started one... this will
throw an exception if it fails
- TransactionUtil.commit(beganTransaction);
- }
-
- writer.println("</entity-engine-xml>");
- }
-
- } else {%>
-ERROR: No entityName list was found in the session, go back to the export page
and try again.
- <%}%>
-<%} else {%>
- ERROR: You do not have permission to use this page (ENTITY_MAINT needed)
-<%}%>
diff --git a/framework/webtools/webapp/webtools/WEB-INF/controller.xml
b/framework/webtools/webapp/webtools/WEB-INF/controller.xml
index 783acb468a..375dd08768 100644
--- a/framework/webtools/webapp/webtools/WEB-INF/controller.xml
+++ b/framework/webtools/webapp/webtools/WEB-INF/controller.xml
@@ -501,7 +501,9 @@ under the License.
</request-map>
<request-map uri="xmldsrawdump">
<security https="true" auth="true"/>
- <response name="success" type="view" value="xmldsrawdump"/>
+ <event type="groovy"
path="component://webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/XmlDsRawDump.groovy"
transaction-timeout="3600"/>
+ <response name="success" type="none"/>
+ <response name="error" type="none"/>
</request-map>
<!-- EntitySync requests -->
@@ -664,7 +666,6 @@ under the License.
<view-map name="checkdb" type="screen"
page="component://webtools/widget/EntityScreens.xml#CheckDb"/>
<view-map name="xmldsdump" type="screen"
page="component://webtools/widget/EntityScreens.xml#xmldsdump"/>
- <view-map name="xmldsrawdump" page="template/entity/xmldsrawdump.jsp"/>
<view-map name="FindUtilCache" type="screen"
page="component://webtools/widget/CacheScreens.xml#FindUtilCache"/>
<view-map name="FindUtilCacheElements" type="screen"
page="component://webtools/widget/CacheScreens.xml#FindUtilCacheElements"/>