use of javax.xml.xpath.XPathExpressionException in project verify-hub by alphagov.
the class SoapMessageManager method unwrapSoapMessage.
public Element unwrapSoapMessage(Element soapElement) {
XPath xpath = XPathFactory.newInstance().newXPath();
NamespaceContextImpl context = new NamespaceContextImpl();
context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
context.startPrefixMapping("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
context.startPrefixMapping("ds", "http://www.w3.org/2000/09/xmldsig#");
xpath.setNamespaceContext(context);
try {
final String expression = "/soapenv:Envelope/soapenv:Body/samlp:Response";
Element element = (Element) xpath.evaluate(expression, soapElement, XPathConstants.NODE);
if (element == null) {
String errorMessage = format("Document{0}{1}{0}does not have element {2} inside it.", NEW_LINE, writeToString(soapElement), expression);
LOG.error(errorMessage);
throw new IllegalArgumentException(errorMessage);
}
return element;
} catch (XPathExpressionException e) {
throw propagate(e);
}
}
use of javax.xml.xpath.XPathExpressionException in project oxTrust by GluuFederation.
the class Shibboleth3ConfService method isFederationMetadata.
public boolean isFederationMetadata(String spMetaDataFN) {
if (spMetaDataFN == null) {
return false;
}
File spMetaDataFile = new File(getSpMetadataFilePath(spMetaDataFN));
InputStream is = null;
InputStreamReader isr = null;
Document xmlDocument = null;
try {
is = FileUtils.openInputStream(spMetaDataFile);
isr = new InputStreamReader(is, "UTF-8");
try {
xmlDocument = xmlService.getXmlDocument(new InputSource(isr));
} catch (Exception ex) {
log.error("Failed to parse metadata file '{}'", spMetaDataFile.getAbsolutePath(), ex);
ex.printStackTrace();
}
} catch (IOException ex) {
log.error("Failed to read metadata file '{}'", spMetaDataFile.getAbsolutePath(), ex);
ex.printStackTrace();
} finally {
IOUtils.closeQuietly(isr);
IOUtils.closeQuietly(is);
}
if (xmlDocument == null) {
return false;
}
XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
String federationTag = null;
try {
federationTag = xPath.compile("count(//*[local-name() = 'EntitiesDescriptor'])").evaluate(xmlDocument);
} catch (XPathExpressionException ex) {
log.error("Failed to find IDP metadata file in relaying party file '{}'", spMetaDataFile.getAbsolutePath(), ex);
ex.printStackTrace();
}
return Integer.parseInt(federationTag) > 0;
}
use of javax.xml.xpath.XPathExpressionException in project linuxtools by eclipse.
the class RPMStubbyUtils method findPom.
/**
* Find the parent pom.xml of a file by recursively checking
* the current directory for the parent pom.xml and moving up
* the directory structure if there is none.
*
* @param folderPath The container of the file to check.
* @return The path of the parent pom. Null otherwise.
*/
public boolean findPom(IPath folderPath) {
IPath filePath = folderPath.append(new Path("pom.xml"));
File file = filePath.toFile();
boolean rc = false;
if (file.exists()) {
try {
Document xmlDocument = builder.parse(new FileInputStream(file));
String parent = xPath.compile(PARENT_NODE).evaluate(xmlDocument);
if (!parent.equals("")) {
rc = findPom(folderPath.removeLastSegments(1));
} else {
rc = true;
}
} catch (SAXException e) {
StubbyLog.logError(e);
} catch (IOException e) {
StubbyLog.logError(e);
} catch (XPathExpressionException e) {
StubbyLog.logError(e);
}
}
return rc;
}
use of javax.xml.xpath.XPathExpressionException in project cxf by apache.
the class XMLSource method evaluate.
private Object evaluate(String expression, Map<String, String> namespaces, QName type) {
XPathFactory factory = XPathFactory.newInstance();
try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
} catch (XPathFactoryConfigurationException e) {
throw new RuntimeException(e);
}
XPath xpath = factory.newXPath();
xpath.setNamespaceContext(new NamespaceContextImpl(namespaces));
boolean releaseDoc = false;
try {
if (stream != null) {
// xalan xpath evaluate parses to a DOM via a DocumentBuilderFactory, but doesn't
// set the SecureProcessing on that. Since a DOM is always created, might as well
// do it via stax and avoid the service factory performance hits that the
// DocumentBuilderFactory will entail as well as get the extra security
// that woodstox provides
setBuffering();
releaseDoc = true;
}
return xpath.compile(expression).evaluate(doc, type);
} catch (XPathExpressionException ex) {
throw new IllegalArgumentException("Illegal XPath expression '" + expression + "'", ex);
} finally {
if (releaseDoc) {
// don't need to maintain the doc
doc = null;
}
}
}
use of javax.xml.xpath.XPathExpressionException in project cxf by apache.
the class FilteringUtil method isValidFilter.
public static boolean isValidFilter(String xPathString) {
if (xPathString == null) {
return true;
}
try {
XPath xPath = xPathFactory.newXPath();
xPath.compile(xPathString);
return true;
} catch (XPathExpressionException ex) {
return false;
}
}
Aggregations