wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Sax parser and SSLHandshakeException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Sax parser and SSLHandshakeException" Watch "Sax parser and SSLHandshakeException" New topic
Author

Sax parser and SSLHandshakeException

JND JND
Greenhorn

Joined: Dec 14, 2004
Posts: 4
Hello,
I am trying to parse some xml that I have in a string using the classes below.
When I call parser.parse(source) a SSLHandshakeException is thrown. Could some one
please tell me what I'm doing wrong.

thanks,
jd


import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.InputSource;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Iterator;
import java.io.IOException;

public class JXMLParser{
public HashMap doParse(String content) throws Exception{
XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
org.xml.sax.ContentHandler handler = new JXMLHandler();
parser.setContentHandler(handler);
InputSource source = new InputSource(new StringReader(content));
try{
parser.parse(source);
}catch (SAXException e){
System.out.println("Cought saxexception");
throw new Exception(e.toString());
}catch(IOException e2){
System.out.println("Cought here");
e2.printStackTrace();
throw new Exception(e2.toString());
}

JXMLHandler jhandler = (JXMLHandler)handler;
return jhandler.getResults();
}
}


// the handler

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.HashMap;

public class JXMLHandler extends DefaultHandler{
private String currentQualifiedName = null;
private String currentQualifiedNameValue = null;
private HashMap parsedValues = new HashMap();

public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException {
this.currentQualifiedName = qualifiedName;
}

public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException{
}

public void characters(char[] ch, int start, int length)throws SAXException {
this.currentQualifiedNameValue = new String(ch,start,length);
this.parsedValues.put(currentQualifiedName , currentQualifiedNameValue);
}

public HashMap getResults(){
return this.parsedValues;
}
}



the code that calls the parser..
private HashMap parseResponse(String response , String batchID){
JXMLParser xmlP = new JXMLParser();
HashMap parsedValues = null;
try{
parsedValues = xmlP.doParse(response);
}catch(Exception e){
String logName = this.logFileDir + batchID;
try{
JLog log = new JLog(logName , 1);
log.writeMessage("Problem with send batch response : parseResponse()" , 3 , e);
}catch(Exception e2){ System.out.println(e2);}
System.exit(1);
}
return parsedValues;
}




the stack trace:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA12275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA12275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA12275)
at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA12275)
at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA12275)
at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA12275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA12275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA12275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(DashoA12275)
at sun.net.www.protocol.https.HttpsClient.afterConnect(DashoA12275)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(DashoA12275)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:626)
at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl.getInputStream(DashoA12275)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at JXMLParser.doParse(JXMLParser.java:17)
at TransUHCS.parseResponse(TransUHCS.java:96)
at TransUHCS.sendBatches(TransUHCS.java:87)
at TransUHCS.<init>(TransUHCS.java:18)
at TransUHCS.main(TransUHCS.java:132)
Caused by: sun.security.validator.ValidatorException: No trusted certificate found
at sun.security.validator.SimpleValidator.buildTrustedChain(SimpleValidator.java:304)
at sun.security.validator.SimpleValidator.engineValidate(SimpleValidator.java:107)
at sun.security.validator.Validator.validate(Validator.java:202)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA12275)
at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA12275)
... 25 more
JND JND
Greenhorn

Joined: Dec 14, 2004
Posts: 4
Sorry about the formatting... here is my question formatted correctly..

Hello,
I am trying to parse some xml that I have in a string using the classes below.
When I call parser.parse(source) a SSLHandshakeException is thrown. Could some one
please tell me what I'm doing wrong.

thanks,
jd

JND JND
Greenhorn

Joined: Dec 14, 2004
Posts: 4
Hello,
I think my string that I am parsing is breaking stuff...maybe. The string
I am passing the xml parser looks like...

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE genresp:uhgTransaction SYSTEM "https://www.blah.com/dtd/genericPayloadResponse.dtd"><genresp:uhgTransac tion><responseHeader><transactionVersion>1.0</transactionVersi on><businessPartnerReferenceNumber>102212</businessPartnerReferenceN umber><routingId>B00559987600</routingId></responseHeader>& lt;genresp ayload>/uhc/EDIPortal/prod/work/batch/837TCA_34904018_12142004125 853.RES</genresp ayload></genresp:uhgTransaction>

if i replace this string with <a_tag>a_val</a_tag> everything works as expected...

any ideas why this would be? Could the un-escaped "s be breaking stuff?

Thanks,
jd
JND JND
Greenhorn

Joined: Dec 14, 2004
Posts: 4
solved

what i needed to do was...

parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd" ,false);
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
JND JND,

Welcome to JavaRanch!

Congratulations at solving your problem. I'm glad we could help out as your Cardboard Analyst.

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the XML and Related Technologies forum...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sax parser and SSLHandshakeException