protected ServiceException parseException(InputStream inputStream) throws IOException { try { return ServiceExceptionParser.parse(inputStream); } catch (JDOMException e) { throw (IOException) new IOException().initCause(e); } finally { inputStream.close(); } } }
for (int i = 0; i < serviceExceptions.size(); i++) { Element element = (Element) serviceExceptions.get(i); ServiceException exception = parseSE(element); if (exception.getCode() != null && exception.getCode().length() != 0 ) { codes.add(exception);
for (int i = 0; i < serviceExceptions.size(); i++) { Element element = (Element) serviceExceptions.get(i); ServiceException exception = parseSE(element); if (exception.getCode() != null && exception.getCode().length() != 0 ) { codes.add(exception);
@Test public void testXXE() throws Exception { URL resource = ServiceExceptionParserTest.class.getResource("secret.txt"); ServiceException exception = ServiceExceptionParser.parse( mockStream( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<!DOCTYPE foo [ <!ELEMENT ServiceExceptionReport ANY ><!ENTITY xxe SYSTEM \"" + resource + "\" >]>" + "<ServiceExceptionReport>\n" + " <ServiceException code=\"42\">&xxe;</ServiceException>\n" + "</ServiceExceptionReport>")); Assert.assertThat( exception, hasProperty( "message", not( containsString( "Top secret information that shouldn't appear in an error message.")))); Assert.assertThat(exception.getNext(), nullValue()); }
@Test public void testSimple() throws Exception { ServiceException exception = ServiceExceptionParser.parse( mockStream( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<ServiceExceptionReport>\n" + " <ServiceException code=\"42\">test</ServiceException>\n" + "</ServiceExceptionReport>")); Assert.assertThat( exception, both(hasProperty("message", equalTo("test"))) .and(hasProperty("code", equalTo("42")))); Assert.assertThat(exception.getNext(), nullValue()); }
protected ServiceException parseException(InputStream inputStream) throws IOException { try { return ServiceExceptionParser.parse(inputStream); } catch (JDOMException e) { throw (IOException) new IOException().initCause(e); } finally { inputStream.close(); } } }
protected ServiceException parseException(InputStream inputStream) throws IOException { try { return ServiceExceptionParser.parse(inputStream); } catch (JDOMException e) { throw (IOException) new IOException().initCause(e); } finally { inputStream.close(); } } }
@Test public void testSequence() throws Exception { ServiceException exception = ServiceExceptionParser.parse( mockStream( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<ServiceExceptionReport>\n" + " <ServiceException code=\"42\">test</ServiceException>\n" + " <ServiceException code=\"20\">another test</ServiceException>\n" + " <ServiceException code=\"60\">yet another test</ServiceException>\n" + "</ServiceExceptionReport>")); Assert.assertThat( exception, both(hasProperty("message", equalTo("test"))) .and(hasProperty("code", equalTo("42")))); Assert.assertThat( exception.getNext(), both(hasProperty("message", equalTo("another test"))) .and(hasProperty("code", equalTo("20")))); Assert.assertThat( exception.getNext().getNext(), both(hasProperty("message", equalTo("yet another test"))) .and(hasProperty("code", equalTo("60")))); Assert.assertThat(exception.getNext().getNext().getNext(), nullValue()); }
@Test public void testSequenceWithEmptyCodes() throws Exception { ServiceException exception = ServiceExceptionParser.parse( mockStream( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<ServiceExceptionReport>\n" + " <ServiceException>test</ServiceException>\n" + " <ServiceException code=\"\">another test</ServiceException>\n" + " <ServiceException code=\"60\">yet another test</ServiceException>\n" + " <ServiceException code=\"20\">still another test</ServiceException>\n" + "</ServiceExceptionReport>")); Assert.assertThat( exception, both(hasProperty("message", equalTo("yet another test"))) .and(hasProperty("code", equalTo("60")))); Assert.assertThat( exception.getNext(), both(hasProperty("message", equalTo("still another test"))) .and(hasProperty("code", equalTo("20")))); Assert.assertThat( exception.getNext().getNext(), both(hasProperty("message", equalTo("test"))) .and(hasProperty("code", nullValue()))); Assert.assertThat( exception.getNext().getNext().getNext(), both(hasProperty("message", equalTo("another test"))) .and(hasProperty("code", equalTo("")))); Assert.assertThat(exception.getNext().getNext().getNext().getNext(), nullValue()); }