Example usage for javax.xml.xpath XPathExpressionException printStackTrace

List of usage examples for javax.xml.xpath XPathExpressionException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.xpath XPathExpressionException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Print stack trace to System.err .

Usage

From source file:Main.java

public static NodeList getNodeList(Node node, String path) {
    try {/*from   w w w. j ava2s  . c  o  m*/
        slowGetValue++;
        // System.out.println("slow : " + slowGetValue + " - " + path);

        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xpath = xPathFactory.newXPath();
        XPathExpression expr;
        expr = xpath.compile(path);
        NodeList list = (NodeList) expr.evaluate(node, XPathConstants.NODESET);

        return list;
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static NodeList getXPathNodes(String search, Document domDocument, XPath xpathInstance) {
    try {/*from  w w  w.j ava2 s . c  o  m*/
        XPathExpression expr = xpathInstance.compile(search);
        return (NodeList) expr.evaluate(domDocument, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

/**
 * Read application-context file, and return fully qualified class name for
 * given <code>beanName</code>
 * /*from  w w w  . j ava2  s .c  om*/
 * @param beanName
 * @return
 * 
 */
public static String getFullyQualifiedClass(String beanName) {

    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();

    docBuilderFactory.setNamespaceAware(true);

    String nodeValue = "";

    try {
        DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
        Document doc = builder.parse("application-context.xml");

        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        XPathExpression expr = xpath.compile("//bean[@name='" + beanName + "']/@class");

        Object result = expr.evaluate(doc, XPathConstants.NODESET);

        NodeList nodes = (NodeList) result;
        if (nodes.getLength() > 0) {
            nodeValue = nodes.item(0).getNodeValue();
        }
    } catch (ParserConfigurationException parserConfigurationException) {
        parserConfigurationException.printStackTrace();
    } catch (IOException ioException) {
        ioException.printStackTrace();
    } catch (SAXException saxException) {
        saxException.printStackTrace();
    } catch (XPathExpressionException xPathExpressionException) {
        xPathExpressionException.printStackTrace();
    }

    return nodeValue;
}

From source file:uk.ac.ebi.intact.dataexchange.psimi.solr.util.IntactSolrUtils.java

public static SchemaInfo retrieveSchemaInfo(SolrServer solrServer) throws IOException {
    SchemaInfo schemaInfo = new SchemaInfo();

    if (solrServer instanceof CommonsHttpSolrServer) {
        final CommonsHttpSolrServer solr = (CommonsHttpSolrServer) solrServer;

        final String url = solr.getBaseURL() + "/admin/file/?file=schema.xml";
        final GetMethod method = new GetMethod(url);
        final int code = solr.getHttpClient().executeMethod(method);

        XPath xpath = XPathFactory.newInstance().newXPath();
        String expression = "/schema/fields/field";
        InputStream stream = method.getResponseBodyAsStream();
        InputSource inputSource = new InputSource(stream);

        try {//ww w.j a va  2  s.c  o  m
            NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);

            for (int i = 0; i < nodes.getLength(); i++) {
                final String fieldName = nodes.item(i).getAttributes().getNamedItem("name").getNodeValue();
                schemaInfo.addFieldName(fieldName);
            }

        } catch (XPathExpressionException e) {
            e.printStackTrace();
        } finally {
            stream.close();
        }

    } else if (solrServer instanceof HttpSolrServer) {
        final HttpSolrServer solr = (HttpSolrServer) solrServer;

        final String url = solr.getBaseURL() + "/admin/file/?file=schema.xml";
        final HttpUriRequest method = new HttpGet(url);
        final HttpResponse response = solr.getHttpClient().execute(method);

        XPath xpath = XPathFactory.newInstance().newXPath();
        String expression = "/schema/fields/field";
        InputStream stream = response.getEntity().getContent();
        InputSource inputSource = new InputSource(stream);

        try {
            NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);

            for (int i = 0; i < nodes.getLength(); i++) {
                final String fieldName = nodes.item(i).getAttributes().getNamedItem("name").getNodeValue();
                schemaInfo.addFieldName(fieldName);
            }

        } catch (XPathExpressionException e) {
            e.printStackTrace();
        } finally {
            stream.close();
        }

    } else {
        throw new IllegalArgumentException(
                "Cannot get schema for SolrServer with class: " + solrServer.getClass().getName());
    }

    return schemaInfo;
}

From source file:gov.niem.ws.util.SecurityUtil.java

public static X509Certificate getCertificateFromKeyInfo(Node keyInfoNode)
        throws ParserConfigurationException, SAXException, IOException {
    X509Certificate cert = null;//w w w .  ja v  a  2  s  .  com

    try {
        String s = x509Path.evaluate(keyInfoNode);
        if (s == null || s.length() == 0)
            return null;
        byte[] decoded = Base64.decodeBase64(s);
        cert = (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(decoded));
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (CertificateException e) {
        e.printStackTrace();
    }
    return cert;
}

From source file:gov.niem.ws.util.SecurityUtil.java

public static PublicKey getSignaturePublicKey(Document assertion)
        throws ParserConfigurationException, SAXException, IOException {
    Node keyInfoNode = null;//from  w ww .j  av  a2s  .com
    try {
        keyInfoNode = (Node) signatureKeyInfoPath.evaluate(assertion, XPathConstants.NODE);
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
    if (keyInfoNode == null) {
        return null;
    }

    X509Certificate signatureCert = getCertificateFromKeyInfo(keyInfoNode);
    if (signatureCert != null) {
        return signatureCert.getPublicKey();
    }

    return getPublicKeyFromKeyInfo(keyInfoNode);
}

From source file:gov.niem.ws.util.SecurityUtil.java

public static PublicKey getPublicKeyFromKeyInfo(Node keyInfoNode)
        throws ParserConfigurationException, SAXException, IOException {
    PublicKey publicKey = null;/*w  w w .  ja v a  2 s  .com*/

    try {
        String modulusString = keyModulusPath.evaluate(keyInfoNode);
        String exponentString = keyExponentPath.evaluate(keyInfoNode);
        if (modulusString == null || exponentString == null) {
            return null;
        }
        byte[] modulusBytes = Base64.decodeBase64(modulusString);
        BigInteger modulus = new BigInteger(1, modulusBytes);
        byte[] exponentBytes = Base64.decodeBase64(exponentString);
        BigInteger exponent = new BigInteger(1, exponentBytes);
        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(modulus, exponent);
        publicKey = rsaKeyFactory.generatePublic(keySpec);
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidKeySpecException e) {
        e.printStackTrace();
    }
    return publicKey;
}

From source file:gov.niem.ws.util.SecurityUtil.java

/**
 * Check that the certificate in the holder of key assertion matches
 * the passed certificate, sent via another channel (e.g. SSL client auth).
 * The certificate must be validated separately, before making this call.
 * @param assertion SAML holder of key assertion.
 * @param presentedCert certificate claimed to be presented in the HoK.
 * @return/*from   w ww  .  j  a v  a 2 s.c  om*/
 * @throws IOException 
 * @throws SAXException 
 * @throws ParserConfigurationException 
 */
public static boolean confirmHolderOfKey(Document assertion, X509Certificate presentedCert)
        throws ParserConfigurationException, SAXException, IOException {
    Node keyInfoNode = null;
    try {
        keyInfoNode = (Node) subjectConfirmationKeyInfoPath.evaluate(assertion, XPathConstants.NODE);
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }
    if (keyInfoNode == null) {
        System.out.println("key info not found in subject confirmation");
        return false;
    }
    X509Certificate assertionCert = getCertificateFromKeyInfo(keyInfoNode);
    if (assertionCert != null) {
        return assertionCert.equals(presentedCert);
    }

    PublicKey publicKey = getPublicKeyFromKeyInfo(keyInfoNode);
    if (publicKey != null) {
        return publicKey.equals(presentedCert.getPublicKey());
    }

    return false;
}

From source file:au.csiro.casda.sodalint.ValidateAsync.java

/** {@inheritDoc} */

@Override/*  ww w .  j  a v  a  2 s .  c  o m*/
public void run(Reporter reporter, SodaService sodaService, String testDataProductId) {
    Node asyncNode = sodaService.getAsyncServiceNode();

    if (asyncNode == null) {
        reporter.report(SodaCode.I_ASNO, "No async SODA endpoint to test.");
        return;
    }

    try {
        URL asyncUrl = sodaService.getUrlFromCapabilityNode(asyncNode);
        reporter.report(SodaCode.I_VURL, "Validating URL: " + asyncUrl);
        // Check endpoint exists
        getAsyncContent(reporter, asyncUrl);
    } catch (XPathExpressionException e) {
        reporter.report(SodaCode.F_CODE, "Validate async coding error: ", e);

        e.printStackTrace();
    } catch (MalformedURLException e) {
        reporter.report(SodaCode.E_SYUR, "Invalid async interface access URL: ", e);

        e.printStackTrace();
    }
}

From source file:au.csiro.casda.sodalint.ValidateSync.java

/** {@inheritDoc} */

@Override//from w ww  . ja  v  a2 s.  c om
public void run(Reporter reporter, SodaService sodaService, String testDataProductId) {
    Node syncNode = sodaService.getSyncServiceNode();

    if (syncNode == null) {
        reporter.report(SodaCode.I_SYNO, "No sync SODA endpoint to test.");
        return;
    }

    try {
        URL syncUrl = sodaService.getUrlFromCapabilityNode(syncNode);
        reporter.report(SodaCode.I_VURL, "Validating URL: " + syncUrl);

        // Check endpoint exists
        getSyncContent(reporter, syncUrl);
    } catch (XPathExpressionException e) {
        reporter.report(SodaCode.F_CODE, "Validate Sync coding error: ", e);

        e.printStackTrace();
    } catch (MalformedURLException e) {
        reporter.report(SodaCode.E_SYUR, "Invalid sync interface access URL: ", e);

        e.printStackTrace();
    }
}