Skip to content

Commit 2d3874b

Browse files
authored
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.
1 parent 732d462 commit 2d3874b

3 files changed

Lines changed: 73 additions & 97 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.ofbiz.webtools.entity
20+
21+
import org.apache.ofbiz.entity.condition.EntityCondition
22+
import org.apache.ofbiz.entity.model.ModelViewEntity
23+
import org.apache.ofbiz.entity.util.EntityQuery
24+
25+
if (!security.hasPermission('ENTITY_MAINT', session)) {
26+
response.contentType = 'text/plain; charset=UTF-8'
27+
response.writer.println('ERROR: You do not have permission to use this page (ENTITY_MAINT needed)')
28+
return 'success'
29+
}
30+
31+
passedEntityNames = session.getAttribute('xmlrawdump_entitylist')
32+
session.removeAttribute('xmlrawdump_entitylist')
33+
EntityCondition entityDateCond = session.getAttribute('entityDateCond')
34+
session.removeAttribute('entityDateCond')
35+
36+
if (!passedEntityNames) {
37+
response.contentType = 'text/plain; charset=UTF-8'
38+
response.writer.println('ERROR: No entityName list was found in the session, go back to the export page and try again.')
39+
return 'success'
40+
}
41+
42+
reader = delegator.getModelReader()
43+
response.contentType = 'text/xml; charset=UTF-8'
44+
writer = response.writer
45+
writer.println('<?xml version="1.0" encoding="UTF-8"?>')
46+
writer.println('<entity-engine-xml>')
47+
48+
numberWritten = 0
49+
try {
50+
passedEntityNames.each { curEntityName ->
51+
me = reader.getModelEntity(curEntityName)
52+
entityQuery = EntityQuery.use(delegator).from(curEntityName).cursorScrollInsensitive()
53+
if (!me.getNoAutoStamp() && !(me instanceof ModelViewEntity) && entityDateCond) {
54+
entityQuery.where(entityDateCond)
55+
}
56+
entityQuery.queryIterator().withCloseable { values ->
57+
while ((value = values.next()) != null) {
58+
value.writeXmlText(writer, '')
59+
numberWritten++
60+
}
61+
}
62+
}
63+
} catch (Exception e) {
64+
logError(e, 'Failure in raw XML data source dump')
65+
throw e
66+
}
67+
68+
writer.println('</entity-engine-xml>')
69+
logInfo("Total records written from all entities: $numberWritten")
70+
return 'success'

framework/webtools/template/entity/xmldsrawdump.jsp

Lines changed: 0 additions & 95 deletions
This file was deleted.

framework/webtools/webapp/webtools/WEB-INF/controller.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,9 @@ under the License.
501501
</request-map>
502502
<request-map uri="xmldsrawdump">
503503
<security https="true" auth="true"/>
504-
<response name="success" type="view" value="xmldsrawdump"/>
504+
<event type="groovy" path="component://webtools/src/main/groovy/org/apache/ofbiz/webtools/entity/XmlDsRawDump.groovy" transaction-timeout="3600"/>
505+
<response name="success" type="none"/>
506+
<response name="error" type="none"/>
505507
</request-map>
506508

507509
<!-- EntitySync requests -->
@@ -664,7 +666,6 @@ under the License.
664666

665667
<view-map name="checkdb" type="screen" page="component://webtools/widget/EntityScreens.xml#CheckDb"/>
666668
<view-map name="xmldsdump" type="screen" page="component://webtools/widget/EntityScreens.xml#xmldsdump"/>
667-
<view-map name="xmldsrawdump" page="template/entity/xmldsrawdump.jsp"/>
668669

669670
<view-map name="FindUtilCache" type="screen" page="component://webtools/widget/CacheScreens.xml#FindUtilCache"/>
670671
<view-map name="FindUtilCacheElements" type="screen" page="component://webtools/widget/CacheScreens.xml#FindUtilCacheElements"/>

0 commit comments

Comments
 (0)