• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Sax parser and SSLHandshakeException

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
solved

what i needed to do was...

parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd" ,false);
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the XML and Related Technologies forum...
 
This tiny ad is wafer thin:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic