use of org.xml.sax.SAXParseException in project jPOS by jpos.
the class GenericPackagerTest method testGenericContentHandlerErrorThrowsSAXParseException.
@Test
public void testGenericContentHandlerErrorThrowsSAXParseException() throws Throwable {
SAXParseException ex2 = new SAXParseException("testGenericContentHandlerParam1", "testGenericContentHandlerParam2", "testGenericContentHandlerParam3", 100, 1000);
try {
new GenericSubFieldPackager().new GenericContentHandler().error(ex2);
fail("Expected SAXParseException to be thrown");
} catch (SAXParseException ex) {
assertEquals("ex.getMessage()", "testGenericContentHandlerParam1", ex.getMessage());
assertEquals("ex.getPublicId()", "testGenericContentHandlerParam2", ex.getPublicId());
assertEquals("ex.getSystemId()", "testGenericContentHandlerParam3", ex.getSystemId());
assertEquals("ex.getLineNumber()", 100, ex.getLineNumber());
assertEquals("ex.getColumnNumber()", 1000, ex.getColumnNumber());
assertNull("ex.getException()", ex.getException());
}
}
use of org.xml.sax.SAXParseException in project jPOS by jpos.
the class GenericPackagerTest method testGenericContentHandlerFatalErrorThrowsSAXParseException.
@Test
public void testGenericContentHandlerFatalErrorThrowsSAXParseException() throws Throwable {
SAXParseException ex2 = new SAXParseException("testGenericContentHandlerParam1", new LocatorImpl());
try {
new GenericPackager().new GenericContentHandler().fatalError(ex2);
fail("Expected SAXParseException to be thrown");
} catch (SAXParseException ex) {
assertEquals("ex.getMessage()", "testGenericContentHandlerParam1", ex.getMessage());
assertNull("ex.getPublicId()", ex.getPublicId());
assertNull("ex.getSystemId()", ex.getSystemId());
assertEquals("ex.getLineNumber()", 0, ex.getLineNumber());
assertEquals("ex.getColumnNumber()", 0, ex.getColumnNumber());
assertNull("ex.getException()", ex.getException());
}
}
use of org.xml.sax.SAXParseException in project cxf by apache.
the class XMLTypeCreator method readAegisFile.
private Document readAegisFile(InputStream is, final String path) throws IOException {
DocumentBuilder documentBuilder;
try {
documentBuilder = AEGIS_DOCUMENT_BUILDER_FACTORY.newDocumentBuilder();
} catch (ParserConfigurationException e) {
LOG.log(Level.SEVERE, "Unable to create a document builder, e");
throw new RuntimeException("Unable to create a document builder, e");
}
org.w3c.dom.Document doc;
documentBuilder.setErrorHandler(new ErrorHandler() {
private String errorMessage(SAXParseException exception) {
return MessageFormat.format("{0} at {1} line {2} column {3}.", new Object[] { exception.getMessage(), path, Integer.valueOf(exception.getLineNumber()), Integer.valueOf(exception.getColumnNumber()) });
}
private void throwDatabindingException(String message) {
// DatabindingException is quirky. This dance is required to get the full message
// to where it belongs.
DatabindingException e = new DatabindingException(message);
e.setMessage(message);
throw e;
}
public void error(SAXParseException exception) throws SAXException {
String message = errorMessage(exception);
LOG.log(Level.SEVERE, message, exception);
throwDatabindingException(message);
}
public void fatalError(SAXParseException exception) throws SAXException {
String message = errorMessage(exception);
LOG.log(Level.SEVERE, message, exception);
throwDatabindingException(message);
}
public void warning(SAXParseException exception) throws SAXException {
LOG.log(Level.INFO, errorMessage(exception), exception);
}
});
try {
doc = documentBuilder.parse(is);
} catch (SAXException e) {
// can't happen due to
LOG.log(Level.SEVERE, "Error parsing Aegis file.", e);
// above.
return null;
}
return doc;
}
use of org.xml.sax.SAXParseException in project cxf by apache.
the class ApplicationContextTest method testInvalid.
@Test
public void testInvalid() throws Exception {
String s4 = getClass().getResource("/org/apache/cxf/transport/http_jetty/spring/invalid-beans.xml").toString();
try {
new TestApplicationContext(new String[] { S1, s4 }).close();
fail("Expected XmlBeanDefinitionStoreException not thrown.");
} catch (XmlBeanDefinitionStoreException ex) {
assertTrue(ex.getCause() instanceof SAXParseException);
}
}
use of org.xml.sax.SAXParseException in project cxf by apache.
the class ApplicationContextTest method testInvalid.
@Test
public void testInvalid() throws Exception {
String s4 = getClass().getResource("/org/apache/cxf/transport/http_undertow/spring/invalid-beans.xml").toString();
try {
new TestApplicationContext(new String[] { S1, s4 }).close();
fail("Expected XmlBeanDefinitionStoreException not thrown.");
} catch (XmlBeanDefinitionStoreException ex) {
assertTrue(ex.getCause() instanceof SAXParseException);
}
}
Aggregations