Search in sources :

Example 66 with XPathExpressionException

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);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NamespaceContextImpl(org.apache.ws.commons.util.NamespaceContextImpl) Element(org.w3c.dom.Element) XmlUtils.writeToString(uk.gov.ida.shared.utils.xml.XmlUtils.writeToString)

Example 67 with XPathExpressionException

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;
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SubversionFile(org.gluu.oxtrust.model.SubversionFile) File(java.io.File) InvalidConfigurationException(org.xdi.util.exception.InvalidConfigurationException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EncryptionException(org.xdi.util.security.StringEncrypter.EncryptionException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 68 with XPathExpressionException

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;
}
Also used : XPath(javax.xml.xpath.XPath) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) Document(org.w3c.dom.Document) File(java.io.File) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException)

Example 69 with XPathExpressionException

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;
        }
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) XPathExpressionException(javax.xml.xpath.XPathExpressionException) XPathFactoryConfigurationException(javax.xml.xpath.XPathFactoryConfigurationException)

Example 70 with XPathExpressionException

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;
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Aggregations

XPathExpressionException (javax.xml.xpath.XPathExpressionException)157 XPath (javax.xml.xpath.XPath)79 NodeList (org.w3c.dom.NodeList)74 Document (org.w3c.dom.Document)51 Node (org.w3c.dom.Node)50 IOException (java.io.IOException)47 XPathExpression (javax.xml.xpath.XPathExpression)42 SAXException (org.xml.sax.SAXException)32 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)29 XPathFactory (javax.xml.xpath.XPathFactory)29 ArrayList (java.util.ArrayList)23 Element (org.w3c.dom.Element)22 InputSource (org.xml.sax.InputSource)20 HashMap (java.util.HashMap)19 Test (org.junit.Test)17 DocumentBuilder (javax.xml.parsers.DocumentBuilder)14 Response (com.jayway.restassured.response.Response)12 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)12 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)12 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)12