Java Code Examples for javax.xml.bind.UnmarshalException#getLinkedException()

The following examples show how to use javax.xml.bind.UnmarshalException#getLinkedException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLResultHandlerTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test
public void testDTDInResults() throws Exception {
    URL resultsUrl = XMLConfigParserTest.class.getResource("/malicious_results_with_dtd.xml");
    assertNotNull(resultsUrl);
    File resultsFile = new File(resultsUrl.getFile());
    XMLResultHandler handler = new XMLResultHandler();
    try {
      handler.readFromResultFile(resultsFile);
      fail("Expected to see an exception parsing the results with a DTD");
    } catch (UnmarshalException e) {
      // If we don't parse the DTD, the variable 'name' won't be defined in the XML
      LOGGER.debug("Caught expected exception", e);
      Throwable cause = e.getLinkedException();
      assertTrue("Cause was a " + cause.getClass(), cause instanceof XMLStreamException);
    }
}
 
Example 2
Source File: XMLConfigParserTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testDTDInScenario() throws Exception {
    URL scenarioUrl = XMLConfigParserTest.class.getResource("/scenario/malicious_scenario_with_dtd.xml");
    assertNotNull(scenarioUrl);
    Path p = Paths.get(scenarioUrl.toURI());
    try {
        XMLConfigParser.readDataModel(p);
        fail("The scenario should have failed to parse because it contains a DTD");
    } catch (UnmarshalException e) {
        // If we don't parse the DTD, the variable 'name' won't be defined in the XML
        LOGGER.warn("Caught expected exception", e);
        Throwable cause = e.getLinkedException();
        assertTrue("Cause was a " + cause.getClass(), cause instanceof XMLStreamException);
    }
}
 
Example 3
Source File: DataReaderImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void onCompleteUnmarshalling() {
    if (setEventHandler && veventHandler instanceof UnmarshallerEventHandler) {
        try {
            ((UnmarshallerEventHandler) veventHandler).onUnmarshalComplete();
        } catch (UnmarshalException e) {
            if (e.getLinkedException() != null) {
                throw new Fault(new Message("UNMARSHAL_ERROR", LOG,
                        e.getLinkedException().getMessage()), e);
            }
            throw new Fault(new Message("UNMARSHAL_ERROR", LOG, e.getMessage()), e);
        }
    }
}