Example usage for javax.xml.stream XMLStreamException getMessage

List of usage examples for javax.xml.stream XMLStreamException getMessage

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(new File("test.xml")));

    int eventTypeID = reader.nextTag();
    reader.require(XMLStreamConstants.START_ELEMENT, null, "person");

    eventTypeID = reader.nextTag();/*from   w w w .j a  va  2 s  . c o m*/
    try {
        reader.require(XMLStreamConstants.START_ELEMENT, null, "first_name");
    } catch (XMLStreamException e) {
        System.out.println("Assertion failed. " + e.getMessage() + " at " + reader.getLocation().getLineNumber()
                + ":" + reader.getLocation().getColumnNumber());
    }
    System.out.println(reader.getElementText());

}

From source file:StaxCursorTest.java

public static void main(String[] args) throws Exception {

    String filename = "yourXML.xml";

    XMLInputFactory xmlif = null;

    xmlif = XMLInputFactory.newInstance();
    xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
    xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
    xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);

    try {//from   w ww .j av  a  2s  .c o  m
        XMLStreamReader xmlr = xmlif.createXMLStreamReader(filename, new FileInputStream(filename));
        int eventType = xmlr.getEventType();
        printStartDocument(xmlr);
        while (xmlr.hasNext()) {
            eventType = xmlr.next();
            printStartElement(xmlr);
            printEndElement(xmlr);
            printText(xmlr);
            printPIData(xmlr);
            printComment(xmlr);
        }
    } catch (XMLStreamException ex) {
        System.out.println(ex.getMessage());
        if (ex.getNestedException() != null) {
            ex.getNestedException().printStackTrace();
        }
    }
}

From source file:com.piketec.jenkins.plugins.tpt.Publish.java

/**
 * Publish the Junits results, it creates an XML file and write the results on it.
 * /*from  ww  w.  jav  a 2  s.  c o m*/
 * @param jenkinsConfig
 *          The configuration to which the TPT test resuklt should be tranformed to JUnit
 * @param testDataDir
 *          The directory where TPT test data should be searched
 * @param jUnitOutputDir
 *          The directory where the transformed results should be written to.
 * @param logger
 *          to display the information
 * @param logLevel
 *          the threshold for the severity of the log messages
 * @return the number of testcases .
 * @throws IOException
 *           if an error occured while parsing TPT test data or writing the JUnit xml files
 * @throws InterruptedException
 *           If the job was interrupted
 */
public static int publishJUnitResults(JenkinsConfiguration jenkinsConfig, FilePath testDataDir,
        FilePath jUnitOutputDir, TptLogger logger, LogLevel logLevel) throws IOException, InterruptedException {
    XmlStreamWriter xmlPub = null;

    try {
        String classname = FilenameUtils.getBaseName(jenkinsConfig.getTptFile());
        FilePath jUnitXMLFile = new FilePath(jUnitOutputDir,
                classname + "." + jenkinsConfig.getConfigurationWithUnderscore() + ".xml");
        xmlPub = new XmlStreamWriter();
        xmlPub.initalize(jUnitXMLFile);
        xmlPub.writeTestsuite(classname);
        List<Testcase> testdata = getTestcases(testDataDir, logger);
        logger.info("Found " + testdata.size() + " test results.");
        for (Testcase tc : testdata) {
            if (tc.getLogEntries(LogLevel.ERROR).isEmpty() && "SUCCESS".equals(tc.getResult())) {
                xmlPub.writeTestcase(classname, tc.getQualifiedName(), tc.getExecDuration());
            } else {
                StringBuilder log = new StringBuilder();
                for (LogEntry entry : tc.getLogEntries(logLevel)) {
                    if (log.length() > 0) {
                        log.append('\n');
                    }
                    log.append('[').append(entry.level.name()).append("] ").append(entry.message);
                }
                xmlPub.writeTestcaseError(classname, tc.getQualifiedName(), tc.getExecDuration(),
                        log.toString());
            }
        }
        return testdata.size();
    } catch (XMLStreamException e) {
        throw new IOException("XML stream error: " + e.getMessage());
    } catch (FactoryConfigurationError e) {
        throw new IOException("XML configuration error: " + e.getMessage());
    } finally {
        if (xmlPub != null) {
            xmlPub.close();
        }
    }
}

From source file:edu.stanford.cfuller.colocalization3d.correction.Correction.java

/**
 * Reads a stored correction from disk./*from  w  w w  .j  a  v  a  2  s.  co  m*/
 * 
 * @param filename                  The name of the file containing the Correction that was previously written to disk.
 * @return                          The Correction contained in the file.
 * @throws java.io.IOException      if the Correction cannot be successfully read.
 * @throws ClassNotFoundException   if the file does not contain a Correction.
 */
public static Correction readFromDisk(String filename) throws java.io.IOException, ClassNotFoundException {

    File f = new File(filename);

    FileReader fr = new FileReader(f);

    XMLStreamReader xsr = null;
    String encBinData = null;

    try {
        xsr = XMLInputFactory.newFactory().createXMLStreamReader(fr);

        while (xsr.hasNext()) {

            int event = xsr.next();

            if (event != XMLStreamReader.START_ELEMENT)
                continue;

            if (xsr.hasName() && xsr.getLocalName() == BINARY_DATA_ELEMENT) {

                encBinData = xsr.getElementText();

                break;

            }

        }
    } catch (XMLStreamException e) {
        java.util.logging.Logger.getLogger(LOG_NAME)
                .severe("Exception encountered while reading XML correction: " + e.getMessage());
    }
    byte[] binData = (new HexBinaryAdapter()).unmarshal(encBinData);

    ObjectInputStream oi = new ObjectInputStream(new ByteArrayInputStream(binData));

    Object o = oi.readObject();

    return (Correction) o;

}

From source file:org.javelin.sws.ext.bind.SoapEncodingMarshaller.java

@Override
public Object unmarshal(Source source) throws IOException, XmlMappingException {
    try {//w w  w  .  j  a va 2 s  .c o  m
        XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(source);
        streamReader.next();
        return streamReader.getElementText();
    } catch (XMLStreamException e) {
        throw new UnmarshallingFailureException(e.getMessage(), e);
    }
}

From source file:eu.arthepsy.sonar.plugins.scapegoat.rule.ScapegoatQualityProfile.java

private void loadProfile(RulesProfile profile, ValidationMessages messages) {
    SMInputFactory factory = XmlUtils.createFactory();
    InputStream stream = getClass().getResourceAsStream(SCAPEGOAT_RULES_FILE);
    try {//from ww w  .  j a va 2s.c om
        SMHierarchicCursor rootC = factory.rootElementCursor(stream);
        rootC.advance();
        SMInputCursor ruleC = rootC.childElementCursor("rule");
        while (ruleC.getNext() != null) {
            this.processRule(profile, ruleC, messages);
        }
    } catch (XMLStreamException e) {
        LOG.error(LOG_PREFIX + "rules file is not valid", e.getMessage());
        messages.addErrorText("Scapegoat rules file is not valid: " + e.getMessage());
    } finally {
        IOUtils.closeQuietly(stream);
    }
}

From source file:org.javelin.sws.ext.bind.internal.model.AnalyzeSimpleTypesTest.java

/**
 * //w ww . j  a v  a2 s .  c om
 */
private void flush() {
    try {
        this.writer.add(this.eventFactory.createEndElement(new QName("", "v"), null));
        this.writer.close();
    } catch (XMLStreamException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:de.shadowhunt.subversion.internal.ProbeServerOperation.java

@Override
protected HttpUriRequest createRequest() {
    final Writer body = new StringBuilderWriter();
    try {// w  ww  . ja  va  2s.  com
        final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(body);
        writer.writeStartDocument(XmlConstants.ENCODING, XmlConstants.VERSION_1_0);
        writer.writeStartElement("options");
        writer.writeDefaultNamespace(XmlConstants.DAV_NAMESPACE);
        writer.writeEmptyElement("activity-collection-set");
        writer.writeEndElement(); //options
        writer.writeEndDocument();
        writer.close();
    } catch (final XMLStreamException e) {
        throw new SubversionException("could not create request body: " + e.getMessage(), e);
    }

    final DavTemplateRequest request = new DavTemplateRequest("OPTIONS", repository);
    request.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_XML));
    return request;
}

From source file:com.mpobjects.rtcalltree.report.xml.XmlReporter.java

/**
 * @param aWriter// ww w .  j a  v  a 2  s . c o  m
 * @param aCreationDate
 * @param aThreadName
 * @param aCallTree
 */
protected void createNewReport(XMLStreamWriter aWriter, Date aCreationDate, String aThreadName,
        List<? extends CalltreeEntry> aCallTree) {
    XmlGenerator gen = new XmlGenerator(aWriter);
    try {
        gen.startReport(aCreationDate);
        gen.writeCallTree(aThreadName, aCallTree);
        gen.endReport();
    } catch (XMLStreamException e) {
        LOG.error("Fatal error generating report. " + e.getMessage(), e);
    }
}

From source file:com.mpobjects.rtcalltree.report.xml.XmlReporter.java

protected XMLStreamWriter createStreamWriter(Writer aWriter) {
    XMLOutputFactory factory = XMLOutputFactory.newFactory();
    XMLStreamWriter writer;//w  w  w.  j  a  v a2 s  .  co  m
    try {
        writer = factory.createXMLStreamWriter(aWriter);
    } catch (XMLStreamException e) {
        LOG.error("Failed to create XMLStreamWriter. " + e.getMessage(), e);
        return null;
    }
    return writer;
}