Skip to content

Commit

Permalink
Add changes to read XMLInputFactory.properties
Browse files Browse the repository at this point in the history
Read XMLInputFactory.properties in both regex and freemarker template processors.
  • Loading branch information
GDLMadushanka committed Dec 5, 2023
1 parent ce6c782 commit 48d5449
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,6 @@ public class PayloadFactoryMediator extends AbstractMediator {
private static final Log log = LogFactory.getLog(PayloadFactoryMediator.class);

public PayloadFactoryMediator() {
//ignore DTDs for XML Input
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
inputFactory.setProperty(XMLInputFactory.IS_COALESCING, true);
Map props = StAXUtils.loadFactoryProperties("XMLInputFactory.properties");
if (props != null) {
for (Object o : props.entrySet()) {
Map.Entry entry = (Map.Entry) o;
inputFactory.setProperty((String) entry.getKey(), entry.getValue());
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -60,6 +61,7 @@
import java.util.Map;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLInputFactory;

import static org.apache.synapse.mediators.transform.pfutils.Constants.ARGS_INJECTING_NAME;
import static org.apache.synapse.mediators.transform.pfutils.Constants.ARGS_INJECTING_PREFIX;
Expand Down Expand Up @@ -119,6 +121,7 @@ public void init() {
compileFreeMarkerTemplate(format, getMediaType());
templateLoaded = true;
}
this.readInputFactoryProperties();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String processTemplate(String template, String mediaType, MessageContext

@Override
public void init() {
// nothing to do since no pre processing is needed
this.readInputFactoryProperties();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.impl.builder.StAXBuilder;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axis2.AxisFault;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -526,4 +527,19 @@ protected void handleException(String msg) {

public abstract boolean getTemplateStatus();

/**
* Read XMLInputFactory properties from XMLInputFactory.properties file.
*/
public void readInputFactoryProperties() {
//ignore DTDs for XML Input
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
inputFactory.setProperty(XMLInputFactory.IS_COALESCING, true);
Map props = StAXUtils.loadFactoryProperties("XMLInputFactory.properties");
if (props != null) {
for (Object o : props.entrySet()) {
Map.Entry entry = (Map.Entry) o;
inputFactory.setProperty((String) entry.getKey(), entry.getValue());
}
}
}
}

0 comments on commit 48d5449

Please sign in to comment.