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


Groups > comp.lang.java.programmer > #33915 > unrolled thread

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

Started byeli.milanova@gmail.com
First post2016-03-03 06:37 -0800
Last post2016-03-05 23:55 -0500
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

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

Fromeli.milanova@gmail.com
Date2016-03-03 06:37 -0800
SubjectRe: JAXP throws "javax.net.ssl.SSLHandshakeException" accessing local file???
Message-ID<1bb4fc78-76b2-421f-9b57-225543d43fed@googlegroups.com>
On Friday, 6 June 2014 00:58:44 UTC+3, Robert Smith  wrote:
> Ach!!!! Yes, it is using a dtd via https. Okay that explains it. Sanity restored. 
> 
> 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.
> 
> Many thanks!!!!!!
> 
> 
> > 
> > 
> > Does the XML file refer to a DTD that is to be fetched via HTTPS?
> > 
> > 
> > 
> > Arne

You are perfect!!! 3 days struggling and finally saw your answer... Saved my life!!! THANK YOU!

[toc] | [next] | [standalone]


#33937

FromArne Vajhøj <arne@vajhoej.dk>
Date2016-03-05 23:55 -0500
Message-ID<nbgd7d$1t9k$1@gioia.aioe.org>
In reply to#33915
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





[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web