@Test public void parsePurchaseOrder_invalid() throws Exception { Document schemaRefs = parseResourceDocument("/conf/schema-refs-ipo.xml"); URL url = getClass().getResource("/ipo-invalid.xml"); StringWriter strWriter = new StringWriter(); PrintWriter logger = new PrintWriter(strWriter); XMLValidatingParser iut = new XMLValidatingParser(); Document result = iut.parse(url.openConnection(), schemaRefs.getDocumentElement(), logger); assertNull(result); assertFalse("Expected validation error(s) but none reported.", strWriter.toString().isEmpty()); }
public Document parse(URLConnection uc, Element instruction, PrintWriter logger) throws SSLProtocolException { if (null == uc) { throw new NullPointerException( "Unable to parse resource: URLConnection is null."); } jlogger.fine("Received URLConnection object for " + uc.getURL()); Document doc = null; try (InputStream inStream = URLConnectionUtils.getInputStream(uc)) { doc = parse(inStream, instruction, logger); } catch (SSLProtocolException sslep){ throw new SSLProtocolException("[SSL ERROR] Failed to connect with the requested URL due to \"Invalid server_name\" found!! :" + uc.getURL() +":" + sslep.getClass() +" : "+ sslep.getMessage()); } catch (Exception e) { throw new RuntimeException( String.format("Failed to parse resource from %s", uc.getURL()), e); } return doc; }
XMLValidatingParser { public Document parse(URLConnection uc, Element instruction, PrintWriter logger) throws SSLProtocolException { if (null == uc) { throw new NullPointerException( "Unable to parse resource: URLConnection is null."); } jlogger.fine("Received URLConnection object for " + uc.getURL()); Document doc = null; try (InputStream inStream = URLConnectionUtils.getInputStream(uc)) { doc = parse(inStream, instruction, logger); } catch (SSLProtocolException sslep){ throw new SSLProtocolException("[SSL ERROR] Failed to connect with the requested URL due to \"Invalid server_name\" found!! :" + uc.getURL() +":" + sslep.getClass() +" : "+ sslep.getMessage()); } catch (Exception e) { throw new RuntimeException( String.format("Failed to parse resource from %s", uc.getURL()), e); } return doc; } }
XMLValidatingParser { public Document parse(URLConnection uc, Element instruction, PrintWriter logger) throws SSLProtocolException { if (null == uc) { throw new NullPointerException( "Unable to parse resource: URLConnection is null."); } jlogger.fine("Received URLConnection object for " + uc.getURL()); Document doc = null; try (InputStream inStream = URLConnectionUtils.getInputStream(uc)) { doc = parse(inStream, instruction, logger); } catch (SSLProtocolException sslep){ throw new SSLProtocolException("[SSL ERROR] Failed to connect with the requested URL due to \"Invalid server_name\" found!! :" + uc.getURL() +":" + sslep.getClass() +" : "+ sslep.getMessage()); } catch (Exception e) { throw new RuntimeException( String.format("Failed to parse resource from %s", uc.getURL()), e); } return doc; } XMLValidatingParser();  XMLValidatingParser(Document schema_links); }
XMLValidatingParser { public Document parse(URLConnection uc, Element instruction, PrintWriter logger) throws SSLProtocolException { if (null == uc) { throw new NullPointerException( "Unable to parse resource: URLConnection is null."); } jlogger.fine("Received URLConnection object for " + uc.getURL()); Document doc = null; try (InputStream inStream = URLConnectionUtils.getInputStream(uc)) { doc = parse(inStream, instruction, logger); } catch (SSLProtocolException sslep){ throw new SSLProtocolException("[SSL ERROR] Failed to connect with the requested URL due to \"Invalid server_name\" found!! :" + uc.getURL() +":" + sslep.getClass() +" : "+ sslep.getMessage()); } catch (Exception e) { throw new RuntimeException( String.format("Failed to parse resource from %s", uc.getURL()), e); } return doc; } XMLValidatingParser();  XMLValidatingParser(Document schema_links); Document parse(URLConnection uc, Element instruction,
			PrintWriter logger); boolean checkXMLRules(Document doc, Document instruction); NodeList validate(Document doc, Document instruction); Element validateSingleResult(Document doc, Document instruction); }
XMLValidatingParser { public Document parse(URLConnection uc, Element instruction, PrintWriter logger) throws SSLProtocolException { if (null == uc) { throw new NullPointerException( "Unable to parse resource: URLConnection is null."); } jlogger.fine("Received URLConnection object for " + uc.getURL()); Document doc = null; try (InputStream inStream = URLConnectionUtils.getInputStream(uc)) { doc = parse(inStream, instruction, logger); } catch (SSLProtocolException sslep){ throw new SSLProtocolException("[SSL ERROR] Failed to connect with the requested URL due to \"Invalid server_name\" found!! :" + uc.getURL() +":" + sslep.getClass() +" : "+ sslep.getMessage()); } catch (Exception e) { throw new RuntimeException( String.format("Failed to parse resource from %s", uc.getURL()), e); } return doc; } XMLValidatingParser();  XMLValidatingParser(Document schema_links); Document parse(URLConnection uc, Element instruction,
			PrintWriter logger); boolean checkXMLRules(Document doc, Document instruction); NodeList validate(Document doc, Document instruction); Element validateSingleResult(Document doc, Document instruction);  }