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