Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33937

Re: JAXP throws "javax.net.ssl.SSLHandshakeException" accessing local file???

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: JAXP throws "javax.net.ssl.SSLHandshakeException" accessing local file???
Date 2016-03-05 23:55 -0500
Organization Aioe.org NNTP Server
Message-ID <nbgd7d$1t9k$1@gioia.aioe.org> (permalink)
References <55d4756d-d28d-4e11-9196-b751f3f92fda@googlegroups.com> <5390e348$0$295$14726298@news.sunsite.dk> <d6b16c31-aba0-46eb-a89c-ac9bc0c36142@googlegroups.com> <1bb4fc78-76b2-421f-9b57-225543d43fed@googlegroups.com>

Show all headers | View raw


On 3/3/2016 9:37 AM, eli.milanova@gmail.com wrote:
> On Friday, 6 June 2014 00:58:44 UTC+3, Robert Smith  wrote:
>> As it turns out:
>>
>> factory.setValidating(false);
>>
>> does not prevent using the DTD, but:
>> 		factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
>>
>> does.
>
> You are perfect!!! 3 days struggling and finally saw your answer... Saved my life!!! THANK YOU!

I think:

factory.setValidating(false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", 
false);
DocumentBuilder builder = dbf.newDocumentBuilder();

should be coded as:

factory.setValidating(false);
if(factory.getClass().getName().startsWith("org.apache.xerces")) {
 
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", 
false);
} else {
     throw new RuntimeException("This code only works with Xerces 
(default JAXP implementation in newer Java SE)");
}
DocumentBuilder builder = dbf.newDocumentBuilder();

or:

factory.setValidating(false);
DocumentBuilder builder = dbf.newDocumentBuilder();
builder.setEntityResolver(new DTDIgnoreURLPrefix("https://")); // or 
whatever suitable

...

	public static class DTDIgnoreURLPrefix implements EntityResolver {
		private String prefix;
		public DTDIgnoreURLPrefix(String prefix) {
			this.prefix = prefix;
		}
	    @Override
	    public InputSource resolveEntity(String publicId, String systemId) 
throws SAXException, IOException {
	    	if(systemId.startsWith(prefix)) {
	            return new InputSource(new StringReader(""));
	        } else {
	            return null;
	        }
	    }
	}

Arne





Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: JAXP throws "javax.net.ssl.SSLHandshakeException" accessing local file??? eli.milanova@gmail.com - 2016-03-03 06:37 -0800
  Re: JAXP throws "javax.net.ssl.SSLHandshakeException" accessing local file??? Arne Vajhøj <arne@vajhoej.dk> - 2016-03-05 23:55 -0500

csiph-web