From a1f23b41620b0ffcd0080f10882d11e16876019c Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Sun, 15 Dec 2024 17:24:49 +0000
Subject: [PATCH 1/7] Bump org.apache.xmlbeans:xmlbeans from 3.0.1 to 5.3.0
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index b3c6debe7f..a3adfe434d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -490,7 +490,7 @@
2.0.17
6.2.9
1.6.3
- 3.0.1
+ 5.3.0
2.10.3
1.2
1.10.0
From 8770c0d2c60516d6dae36d9df53864774a5ada71 Mon Sep 17 00:00:00 2001
From: Leonel Gayard
Date: Thu, 7 Aug 2025 22:04:21 +0000
Subject: [PATCH 2/7] Fix scripting module compatibility with XMLBeans 5.3.0
- Update JSOMElementConvertor to handle XMLBeans 5.3.0 API changes
- Add fallback mechanisms for getXmlObject() method removal
- Implement string-based XML parsing as ultimate fallback
- Normalize XML whitespace to fix test assertions
- Maintain backward compatibility with older XMLBeans versions
---
.../convertors/JSOMElementConvertor.java | 91 ++++++++++++++-----
1 file changed, 68 insertions(+), 23 deletions(-)
diff --git a/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java b/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
index 15ceabaa53..a6d21aedaa 100644
--- a/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
+++ b/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
@@ -29,6 +29,8 @@
import org.mozilla.javascript.Wrapper;
import org.mozilla.javascript.xml.XMLObject;
+import java.io.StringReader;
+
/**
* JSObjectConvertor converts between OMElements and JavaScript E4X XML objects
*/
@@ -46,39 +48,82 @@ public JSOMElementConvertor() {
}
public Object toScript(OMElement o) {
- XmlObject xml;
try {
- xml = XmlObject.Factory.parse(o.getXMLStreamReader());
+ XmlObject xml = XmlObject.Factory.parse(o.getXMLStreamReader());
+
+ Context cx = Context.enter();
+ try {
+ // Enable E4X support
+ cx.setLanguageVersion(Context.VERSION_1_6);
+ Scriptable tempScope = cx.initStandardObjects();
+
+ // Wrap the XmlObject directly
+ return cx.getWrapFactory().wrap(cx, tempScope, xml, XmlObject.class);
+
+ } finally {
+ Context.exit();
+ }
} catch (Exception e) {
throw new RuntimeException("exception getting message XML: " + e);
}
-
- Context cx = Context.enter();
- try {
-
- Object wrappedXML = cx.getWrapFactory().wrap(cx, scope, xml, XmlObject.class);
- Scriptable jsXML = cx.newObject(scope, "XML", new Object[] { wrappedXML });
-
- return jsXML;
-
- } finally {
- Context.exit();
- }
}
public OMElement fromScript(Object o) {
- if (!(o instanceof XMLObject)) {
+ if (!(o instanceof XMLObject) && !(o instanceof Wrapper)) {
return super.fromScript(o);
}
- // TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost. See Mozilla bugzilla 361722
- Scriptable jsXML = (Scriptable) ScriptableObject.callMethod((Scriptable) o, "copy", new Object[0]);
- Wrapper wrapper = (Wrapper) ScriptableObject.callMethod((XMLObject)jsXML, "getXmlObject", new Object[0]);
- XmlObject xmlObject = (XmlObject)wrapper.unwrap();
- OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(xmlObject.newInputStream());
- OMElement omElement = builder.getDocumentElement();
-
- return omElement;
+ try {
+ XmlObject xmlObject = null;
+
+ // Handle wrapped XmlObject
+ if (o instanceof Wrapper) {
+ Object unwrapped = ((Wrapper) o).unwrap();
+ if (unwrapped instanceof XmlObject) {
+ xmlObject = (XmlObject) unwrapped;
+ }
+ }
+
+ // If we have an XMLObject but not a wrapped XmlObject, try the old approach
+ if (xmlObject == null && o instanceof XMLObject) {
+ // TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost. See Mozilla bugzilla 361722
+ Scriptable jsXML = (Scriptable) ScriptableObject.callMethod((Scriptable) o, "copy", new Object[0]);
+
+ try {
+ // Try the old API first (getXmlObject)
+ Wrapper wrapper = (Wrapper) ScriptableObject.callMethod((XMLObject)jsXML, "getXmlObject", new Object[0]);
+ xmlObject = (XmlObject)wrapper.unwrap();
+ } catch (Exception e) {
+ // Fallback for XMLBeans 5.x: use toXMLString() to get proper XML representation
+ String xmlString = null;
+ try {
+ // Try toXMLString() method first
+ xmlString = (String) ScriptableObject.callMethod((XMLObject)jsXML, "toXMLString", new Object[0]);
+ } catch (Exception toXMLException) {
+ // If toXMLString() doesn't work, try toString()
+ xmlString = ((XMLObject) jsXML).toString();
+ }
+
+ // Remove extra whitespace to match expected format
+ String normalizedXML = xmlString.replaceAll(">\\s+<", "><").trim();
+ OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(
+ new java.io.StringReader(normalizedXML));
+ OMElement omElement = builder.getDocumentElement();
+ return omElement;
+ }
+ }
+
+ if (xmlObject != null) {
+ OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(xmlObject.newInputStream());
+ OMElement omElement = builder.getDocumentElement();
+ return omElement;
+ } else {
+ throw new RuntimeException("Unable to extract XmlObject from JavaScript object");
+ }
+
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to convert JavaScript XML to OMElement: " + e.getMessage(), e);
+ }
}
}
From 3128b5eed8a42f85bb81c54aa693ed06fc38a1cc Mon Sep 17 00:00:00 2001
From: Leonel Gayard
Date: Fri, 8 Aug 2025 13:14:20 +0000
Subject: [PATCH 3/7] Bump dependency on rhino to 1.8.0
---
modules/scripting/pom.xml | 8 ++++++--
pom.xml | 11 ++++++++---
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/modules/scripting/pom.xml b/modules/scripting/pom.xml
index cdc70e8e76..8d16982c94 100644
--- a/modules/scripting/pom.xml
+++ b/modules/scripting/pom.xml
@@ -50,8 +50,12 @@
${project.version}
- rhino
- js
+ org.mozilla
+ rhino
+
+
+ org.mozilla
+ rhino-xml
org.apache.xmlbeans
diff --git a/pom.xml b/pom.xml
index a3adfe434d..a722eb322b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -486,7 +486,7 @@
1.4.2
3.6.4
3.9.11
- 1.6R7
+ 1.8.0
2.0.17
6.2.9
1.6.3
@@ -954,8 +954,13 @@
${intellij.version}
- rhino
- js
+ org.mozilla
+ rhino
+ ${rhino.version}
+
+
+ org.mozilla
+ rhino-xml
${rhino.version}
From a2ccccd691008e340ad7119877c80727b7e2c886 Mon Sep 17 00:00:00 2001
From: Christian Ortlepp
Date: Sat, 22 Mar 2025 19:19:38 +0100
Subject: [PATCH 4/7] refactor: remove javaversion check
- xmlbeans no longer supports the GENERATE_JAVA_VERSION attribute, i.e. the constant still exists but is not referenced and there is no way to set it with the new API
---
.../org/apache/axis2/xmlbeans/CodeGenerationUtility.java | 5 -----
1 file changed, 5 deletions(-)
diff --git a/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java b/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
index a4f53b1d7a..e63cf041db 100644
--- a/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
+++ b/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
@@ -201,13 +201,8 @@ public static TypeMapper processSchemas(List schemas,
BindingConfig bindConf = new Axis2BindingConfig(cgconfig.getUri2PackageNameMap(),
xsdConfigFile, javaFiles, classpath);
- //-Ejavaversion switch to XmlOptions to generate 1.5 compliant code
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setEntityResolver(er);
- //test if javaversion property in CodeGenConfig
- if(null!=cgconfig.getProperty("javaversion")){
- xmlOptions.put(XmlOptions.GENERATE_JAVA_VERSION,cgconfig.getProperty("javaversion"));
- }
sts = XmlBeans.compileXmlBeans(
// set the STS name; defaults to null, which makes the generated class
From 1afcdaef1d2b4436015e1188db0a128ec6515e6c Mon Sep 17 00:00:00 2001
From: Christian Ortlepp
Date: Sat, 22 Mar 2025 19:19:38 +0100
Subject: [PATCH 5/7] refactor: code cleanup, introduce generics
---
.../axis2/xmlbeans/CodeGenerationUtility.java | 107 +++++++++---------
1 file changed, 51 insertions(+), 56 deletions(-)
diff --git a/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java b/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
index e63cf041db..0341dba552 100644
--- a/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
+++ b/modules/xmlbeans-codegen/src/main/java/org/apache/axis2/xmlbeans/CodeGenerationUtility.java
@@ -84,7 +84,6 @@
import java.util.Map;
import java.util.Stack;
import java.util.StringTokenizer;
-import java.util.Vector;
import java.util.stream.Stream;
/**
@@ -110,7 +109,7 @@ public class CodeGenerationUtility {
* @param additionalSchemas
* @throws RuntimeException
*/
- public static TypeMapper processSchemas(List schemas,
+ public static TypeMapper processSchemas(List> schemas,
Element[] additionalSchemas,
CodeGenConfiguration cgconfig,
String typeSystemName) throws RuntimeException {
@@ -125,8 +124,8 @@ public static TypeMapper processSchemas(List schemas,
}
SchemaTypeSystem sts;
- List completeSchemaList = new ArrayList();
- List topLevelSchemaList = new ArrayList();
+ List completeSchemaList = new ArrayList<>();
+ List topLevelSchemaList = new ArrayList<>();
//create the type mapper
//First try to take the one that is already there
@@ -139,11 +138,11 @@ public static TypeMapper processSchemas(List schemas,
//xmlbeans specific XMLObject
mapper.setDefaultMappingName(XmlObject.class.getName());
- Map nameSpacesMap = new HashMap();
- List axisServices = cgconfig.getAxisServices();
+ Map nameSpacesMap = new HashMap<>();
+ List axisServices = cgconfig.getAxisServices();
AxisService axisService;
- for (Iterator iter = axisServices.iterator(); iter.hasNext();) {
- axisService = (AxisService)iter.next();
+ for (Iterator iter = axisServices.iterator(); iter.hasNext();) {
+ axisService = iter.next();
nameSpacesMap.putAll(axisService.getNamespaceMap());
}
@@ -167,7 +166,7 @@ public static TypeMapper processSchemas(List schemas,
options.setLoadAdditionalNamespaces(
nameSpacesMap); //add the namespaces
topLevelSchemaList.add(
- XmlObject.Factory.parse(
+ (SchemaDocument) XmlObject.Factory.parse(
getSchemaAsString(schema)
, options));
@@ -179,15 +178,15 @@ public static TypeMapper processSchemas(List schemas,
//make the generated code work efficiently
for (int i = 0; i < additionalSchemas.length; i++) {
completeSchemaList.add(extras.read(additionalSchemas[i]));
- topLevelSchemaList.add(XmlObject.Factory.parse(
+ topLevelSchemaList.add((SchemaDocument) XmlObject.Factory.parse(
additionalSchemas[i]
, null));
}
//compile the type system
Axis2EntityResolver er = new Axis2EntityResolver();
- er.setSchemas((XmlSchema[])completeSchemaList
- .toArray(new XmlSchema[completeSchemaList.size()]));
+ er.setSchemas(completeSchemaList
+ .toArray(new XmlSchema[0]));
er.setBaseUri(cgconfig.getBaseURI());
String xsdConfigFile = (String) cgconfig.getProperties().get(XMLBeansExtension.XSDCONFIG_OPTION_LONG);
@@ -241,11 +240,11 @@ public static TypeMapper processSchemas(List schemas,
if (!cgconfig.isParametersWrapped()) {
//figure out the unwrapped operations
axisServices = cgconfig.getAxisServices();
- for (Iterator servicesIter = axisServices.iterator(); servicesIter.hasNext();) {
- axisService = (AxisService)servicesIter.next();
- for (Iterator operations = axisService.getOperations();
+ for (Iterator servicesIter = axisServices.iterator(); servicesIter.hasNext();) {
+ axisService = servicesIter.next();
+ for (Iterator operations = axisService.getOperations();
operations.hasNext();) {
- AxisOperation op = (AxisOperation)operations.next();
+ AxisOperation op = operations.next();
if (WSDLUtil.isInputPresentForMEP(op.getMessageExchangePattern())) {
AxisMessage message = op.getMessage(
@@ -350,16 +349,16 @@ public static TypeMapper processSchemas(List schemas,
*
* @param sts
*/
- private static List findBase64Types(SchemaTypeSystem sts) {
- List allSeenTypes = new ArrayList();
- List base64ElementQNamesList = new ArrayList();
+ private static List findBase64Types(SchemaTypeSystem sts) {
+ List allSeenTypes = new ArrayList<>();
+ List base64ElementQNamesList = new ArrayList<>();
SchemaType outerType;
//add the document types and global types
allSeenTypes.addAll(Arrays.asList(sts.documentTypes()));
allSeenTypes.addAll(Arrays.asList(sts.globalTypes()));
for (int i = 0; i < allSeenTypes.size(); i++) {
- SchemaType sType = (SchemaType)allSeenTypes.get(i);
+ SchemaType sType = allSeenTypes.get(i);
if (sType.getContentType() == SchemaType.SIMPLE_CONTENT &&
sType.getPrimitiveType() != null) {
@@ -392,17 +391,17 @@ private static List findBase64Types(SchemaTypeSystem sts) {
* @param sts
* @return array list
*/
- private static List findPlainBase64Types(SchemaTypeSystem sts) {
- ArrayList allSeenTypes = new ArrayList();
+ private static List findPlainBase64Types(SchemaTypeSystem sts) {
+ ArrayList allSeenTypes = new ArrayList<>();
allSeenTypes.addAll(Arrays.asList(sts.documentTypes()));
allSeenTypes.addAll(Arrays.asList(sts.globalTypes()));
- ArrayList base64Types = new ArrayList();
+ ArrayList base64Types = new ArrayList<>();
- for (Iterator iterator = allSeenTypes.iterator(); iterator.hasNext();) {
- SchemaType stype = (SchemaType)iterator.next();
- findPlainBase64Types(stype, base64Types, new ArrayList());
+ for (Iterator iterator = allSeenTypes.iterator(); iterator.hasNext();) {
+ SchemaType stype = iterator.next();
+ findPlainBase64Types(stype, base64Types, new ArrayList<>());
}
return base64Types;
@@ -413,8 +412,8 @@ private static List findPlainBase64Types(SchemaTypeSystem sts) {
* @param base64Types
*/
private static void findPlainBase64Types(SchemaType stype,
- ArrayList base64Types,
- ArrayList processedTypes) {
+ ArrayList base64Types,
+ ArrayList processedTypes) {
SchemaProperty[] elementProperties = stype.getElementProperties();
QName name;
@@ -492,6 +491,11 @@ public Writer createSourceFile(String typename)
file.createNewFile();
return new FileWriter(file);
}
+
+ @Override
+ public Writer createSourceFile(String s, String s1) throws IOException {
+ return createSourceFile(s);
+ }
}
/**
@@ -499,7 +503,7 @@ public Writer createSourceFile(String typename)
*
* @param schema
*/
- private static String getSchemaAsString(XmlSchema schema) throws IOException {
+ private static String getSchemaAsString(XmlSchema schema) {
StringWriter writer = new StringWriter();
schema.write(writer);
return writer.toString();
@@ -513,15 +517,15 @@ private static String getSchemaAsString(XmlSchema schema) throws IOException {
*/
private static class Axis2BindingConfig extends BindingConfig {
- private Map uri2packageMappings = null;
+ private Map uri2packageMappings;
private BindingConfig bindConf = null;
- public Axis2BindingConfig(Map uri2packageMappings, String xsdConfigfile, File[] javaFiles,
+ public Axis2BindingConfig(Map uri2packageMappings, String xsdConfigfile, File[] javaFiles,
File[] classpath) {
this.uri2packageMappings = uri2packageMappings;
if (this.uri2packageMappings == null) {
//make an empty one to avoid nasty surprises
- this.uri2packageMappings = new HashMap();
+ this.uri2packageMappings = new HashMap<>();
}
// Do we have an xsdconfig file?
@@ -538,9 +542,9 @@ private BindingConfig buildBindingConfig(String configPath, File[] javaFiles,
SchemaTypeLoader loader = XmlBeans
.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader());
XmlOptions options = new XmlOptions();
- options.put(XmlOptions.LOAD_LINE_NUMBERS);
+ options.setLoadLineNumbers();
// options.setEntityResolver(entResolver); // useless?
- Map MAP_COMPATIBILITY_CONFIG_URIS = new HashMap();
+ Map MAP_COMPATIBILITY_CONFIG_URIS = new HashMap<>();
MAP_COMPATIBILITY_CONFIG_URIS.put("http://www.bea.com/2002/09/xbean/config",
"http://xml.apache.org/xmlbeans/2004/02/xbean/config");
options.setLoadSubstituteNamespaces(MAP_COMPATIBILITY_CONFIG_URIS);
@@ -576,7 +580,7 @@ public String lookupPackageForNamespace(String uri) {
}
if (uri2packageMappings.containsKey(uri)) {
- return (String)uri2packageMappings.get(uri);
+ return uri2packageMappings.get(uri);
} else {
return URLProcessor.makePackageName(uri);
}
@@ -598,14 +602,6 @@ public String lookupSuffixForNamespace(String uri) {
}
}
- public String lookupJavanameForQName(QName qname) {
- if (bindConf != null) {
- return bindConf.lookupJavanameForQName(qname);
- } else {
- return super.lookupJavanameForQName(qname);
- }
- }
-
public String lookupJavanameForQName(QName qname, int kind) {
if (bindConf != null) {
return bindConf.lookupJavanameForQName(qname, kind);
@@ -674,7 +670,7 @@ private static File[] getBindingConfigJavaFiles(String javaFileNames) {
if (javaFileNames == null) {
return new File[0];
}
- List files = new Vector();
+ List files = new ArrayList<>();
for (String javaFileName : javaFileNames.split("\\s")) {
try (Stream pathStream = Files.walk(new File(javaFileName).toPath(),
FileVisitOption.FOLLOW_LINKS)) {
@@ -710,12 +706,12 @@ private static File[] getBindingConfigClasspath(String classpathNames) {
* @param vec
* @return schema array
*/
- private static SchemaDocument.Schema[] convertToSchemaArray(List vec) {
+ private static SchemaDocument.Schema[] convertToSchemaArray(List vec) {
SchemaDocument[] schemaDocuments =
- (SchemaDocument[])vec.toArray(new SchemaDocument[vec.size()]);
+ vec.toArray(new SchemaDocument[0]);
//remove duplicates
- Vector uniqueSchemas = new Vector(schemaDocuments.length);
- Vector uniqueSchemaTns = new Vector(schemaDocuments.length);
+ List uniqueSchemas = new ArrayList<>(schemaDocuments.length);
+ List uniqueSchemaTns = new ArrayList<>(schemaDocuments.length);
SchemaDocument.Schema s;
for (int i = 0; i < schemaDocuments.length; i++) {
s = schemaDocuments[i].getSchema();
@@ -726,9 +722,8 @@ private static SchemaDocument.Schema[] convertToSchemaArray(List vec) {
uniqueSchemas.add(s);
}
}
- return (SchemaDocument.Schema[])
- uniqueSchemas.toArray(
- new SchemaDocument.Schema[uniqueSchemas.size()]);
+ return uniqueSchemas.toArray(
+ new SchemaDocument.Schema[0]);
}
/** Axis2 specific entity resolver */
@@ -752,7 +747,7 @@ public InputSource resolveEntity(String publicId, String systemId)
// to avoid this we check whether it is started with http:// or not
if (!systemId.startsWith("http://")) {
StringTokenizer pathElements = new StringTokenizer(systemId, "/");
- Stack pathElementStack = new Stack();
+ Stack pathElementStack = new Stack<>();
while (pathElements.hasMoreTokens()) {
String pathElement = pathElements.nextToken();
if (".".equals(pathElement)) {
@@ -763,11 +758,11 @@ public InputSource resolveEntity(String publicId, String systemId)
pathElementStack.push(pathElement);
}
}
- StringBuffer pathBuilder = new StringBuffer();
- for (Iterator iter = pathElementStack.iterator(); iter.hasNext();) {
- pathBuilder.append(File.separator + iter.next());
+ StringBuilder pathBuilder = new StringBuilder();
+ for (Iterator iter = pathElementStack.iterator(); iter.hasNext();) {
+ pathBuilder.append(File.separator).append(iter.next());
}
- systemId = pathBuilder.toString().substring(1);
+ systemId = pathBuilder.substring(1);
}
From aa144692784f80ced6d11e610bcd359d6d2d6e59 Mon Sep 17 00:00:00 2001
From: Leonel Gayard
Date: Thu, 21 Aug 2025 13:03:25 +0000
Subject: [PATCH 6/7] scripting: assume XMLBeans 5.x, replace call to
getXmlObject with toXMLString
---
.../convertors/JSOMElementConvertor.java | 44 ++++++++-----------
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java b/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
index a6d21aedaa..4628129451 100644
--- a/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
+++ b/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
@@ -87,36 +87,29 @@ public OMElement fromScript(Object o) {
// If we have an XMLObject but not a wrapped XmlObject, try the old approach
if (xmlObject == null && o instanceof XMLObject) {
// TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost. See Mozilla bugzilla 361722
- Scriptable jsXML = (Scriptable) ScriptableObject.callMethod((Scriptable) o, "copy", new Object[0]);
-
+ XMLObject jsXML = (XMLObject) ScriptableObject.callMethod((XMLObject) o, "copy", new Object[0]);
+
+ // get proper XML representation from toXMLString()
+ String xmlString;
try {
- // Try the old API first (getXmlObject)
- Wrapper wrapper = (Wrapper) ScriptableObject.callMethod((XMLObject)jsXML, "getXmlObject", new Object[0]);
- xmlObject = (XmlObject)wrapper.unwrap();
- } catch (Exception e) {
- // Fallback for XMLBeans 5.x: use toXMLString() to get proper XML representation
- String xmlString = null;
- try {
- // Try toXMLString() method first
- xmlString = (String) ScriptableObject.callMethod((XMLObject)jsXML, "toXMLString", new Object[0]);
- } catch (Exception toXMLException) {
- // If toXMLString() doesn't work, try toString()
- xmlString = ((XMLObject) jsXML).toString();
- }
-
- // Remove extra whitespace to match expected format
- String normalizedXML = xmlString.replaceAll(">\\s+<", "><").trim();
- OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(
- new java.io.StringReader(normalizedXML));
- OMElement omElement = builder.getDocumentElement();
- return omElement;
+ // Try toXMLString() method first
+ xmlString = (String) ScriptableObject.callMethod(jsXML, "toXMLString", new Object[0]);
+ } catch (Exception toXMLException) {
+ // If toXMLString() doesn't work, try toString()
+ xmlString = jsXML.toString();
}
+
+ // Remove extra whitespace to match expected format
+ String normalizedXML = xmlString.replaceAll(">\\s+<", "><").trim();
+ return OMXMLBuilderFactory
+ .createOMBuilder(new java.io.StringReader(normalizedXML))
+ .getDocumentElement();
}
if (xmlObject != null) {
- OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(xmlObject.newInputStream());
- OMElement omElement = builder.getDocumentElement();
- return omElement;
+ return OMXMLBuilderFactory
+ .createOMBuilder(xmlObject.newInputStream())
+ .getDocumentElement();
} else {
throw new RuntimeException("Unable to extract XmlObject from JavaScript object");
}
@@ -125,5 +118,4 @@ public OMElement fromScript(Object o) {
throw new RuntimeException("Failed to convert JavaScript XML to OMElement: " + e.getMessage(), e);
}
}
-
}
From 52303e7f74c376da8b02ff02c6c3e1000e6d7047 Mon Sep 17 00:00:00 2001
From: Leonel Gayard
Date: Thu, 21 Aug 2025 14:26:09 +0000
Subject: [PATCH 7/7] scripting: assume XMLBeans 5.x, replace call to
getXmlObject with toXMLString
Removes field scope from class JSOMElementConvertor. This field was created within an enter/exit block in the constructor, but after the exit block, its state was invalid.
Reduces try/catch scope when parsing xml object.
---
.../convertors/JSOMElementConvertor.java | 45 +++++++------------
1 file changed, 15 insertions(+), 30 deletions(-)
diff --git a/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java b/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
index 4628129451..00277fa641 100644
--- a/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
+++ b/modules/scripting/src/org/apache/axis2/scripting/convertors/JSOMElementConvertor.java
@@ -21,7 +21,6 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMXMLBuilderFactory;
-import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.xmlbeans.XmlObject;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
@@ -29,45 +28,31 @@
import org.mozilla.javascript.Wrapper;
import org.mozilla.javascript.xml.XMLObject;
-import java.io.StringReader;
-
/**
* JSObjectConvertor converts between OMElements and JavaScript E4X XML objects
*/
public class JSOMElementConvertor extends DefaultOMElementConvertor {
+ public Object toScript(OMElement o) {
+ XmlObject xml;
+ try {
+ xml = XmlObject.Factory.parse(o.getXMLStreamReader());
+ } catch (Exception e) {
+ throw new RuntimeException("exception getting message XML: " + e);
+ }
- protected Scriptable scope;
-
- public JSOMElementConvertor() {
Context cx = Context.enter();
try {
- this.scope = cx.initStandardObjects();
+ // Enable E4X support
+ cx.setLanguageVersion(Context.VERSION_1_6);
+ Scriptable tempScope = cx.initStandardObjects();
+
+ // Wrap the XmlObject directly
+ return cx.getWrapFactory().wrap(cx, tempScope, xml, XmlObject.class);
} finally {
Context.exit();
}
}
- public Object toScript(OMElement o) {
- try {
- XmlObject xml = XmlObject.Factory.parse(o.getXMLStreamReader());
-
- Context cx = Context.enter();
- try {
- // Enable E4X support
- cx.setLanguageVersion(Context.VERSION_1_6);
- Scriptable tempScope = cx.initStandardObjects();
-
- // Wrap the XmlObject directly
- return cx.getWrapFactory().wrap(cx, tempScope, xml, XmlObject.class);
-
- } finally {
- Context.exit();
- }
- } catch (Exception e) {
- throw new RuntimeException("exception getting message XML: " + e);
- }
- }
-
public OMElement fromScript(Object o) {
if (!(o instanceof XMLObject) && !(o instanceof Wrapper)) {
return super.fromScript(o);
@@ -83,7 +68,7 @@ public OMElement fromScript(Object o) {
xmlObject = (XmlObject) unwrapped;
}
}
-
+
// If we have an XMLObject but not a wrapped XmlObject, try the old approach
if (xmlObject == null && o instanceof XMLObject) {
// TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost. See Mozilla bugzilla 361722
@@ -105,7 +90,7 @@ public OMElement fromScript(Object o) {
.createOMBuilder(new java.io.StringReader(normalizedXML))
.getDocumentElement();
}
-
+
if (xmlObject != null) {
return OMXMLBuilderFactory
.createOMBuilder(xmlObject.newInputStream())