Skip to content

Commit

Permalink
Merge pull request #422 from terrestris/wfs-transaction-fix
Browse files Browse the repository at this point in the history
Allow namespace aware reading of xml
  • Loading branch information
jansule authored Jan 27, 2022
2 parents 9189dbd + 6ff3adc commit 952c40f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -131,7 +133,7 @@ public static String getRequestParameterValue(HttpServletRequest httpServletRequ

LOG.trace("The request contains a POST body.");

Document document = OgcXmlUtil.getDocumentFromString(xml);
Document document = OgcXmlUtil.getDocumentFromString(xml, true);

if (parameter.equalsIgnoreCase(OgcEnum.Service.SERVICE.toString())) {
value = OgcXmlUtil.getPathInDocument(
Expand All @@ -151,6 +153,12 @@ public static String getRequestParameterValue(HttpServletRequest httpServletRequ
value = OgcXmlUtil.getPathInDocument(document,
"//@typeName | //@typeNames");
}
if (StringUtils.isEmpty(value)) {
NodeList nl = OgcXmlUtil.getPathInDocumentAsNodeList(document,
"//Insert/*");
Node node = nl.item(0);
value = node.getNamespaceURI();
}
}

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,18 @@ public static String getRequestBody(HttpServletRequest request) {

/**
* @param xml
* @param namespaceAware
* @return
* @throws IOException
*/
public static Document getDocumentFromString(String xml) throws IOException {
public static Document getDocumentFromString(String xml, boolean namespaceAware) throws IOException {

Document document = null;

try {
InputSource source = new InputSource(new StringReader(xml));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(namespaceAware);
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(source);
} catch (ParserConfigurationException | SAXException | IOException e) {
Expand All @@ -92,6 +94,15 @@ public static Document getDocumentFromString(String xml) throws IOException {

}

/**
* @param xml
* @return
* @throws IOException
*/
public static Document getDocumentFromString(String xml) throws IOException {
return getDocumentFromString(xml, false);
}

/**
* @param document
* @param path
Expand Down

0 comments on commit 952c40f

Please sign in to comment.