• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to parse an xml string using builder.parse

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to take an xml string, convert that into a document type to be used for a function that is expected to verify the validity of the contents of this xml string. However, after converting to a document type, the builder.parse() attribute doesn't seem to return any values at all, due to which the validation function is failing. Given below is a code snippet for this.

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

String xmlResponse = "<?xml version="1.0" encoding="UTF-8" standalone="no"?><AuthRes code="5ee2f1d4-4cd6-4996-abad-9a2bc64847a9" info="01a8e6dc0e0c7eb69fb2897d2065284f578bcdfd6e18000000" ret="y" txn="DefaultTXN"><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><DigestValue>K2NuXDP3eFgzglLeHCD6tpogEvs=</DigestValue></Reference></SignedInfo><SignatureValue>m8XsACzxcFPxHRGqkD8tBzKTLlo9azB2e+4+RJ2c4sVettq6QymcVN1BIx0PYfu/lUDxxNlGHsWjcODcrdWnSlYff/6k8sBaTTAkq8+RTATokAOP9LRMgbszfCJLQx1Or+p8EUaeI5J+jEHe+pGFh6b/lsttX6p69lWeq6bp8oI=</SignatureValue></Signature></AuthRes>"

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document resDocument = builder.parse(new InputSource(new StringReader(responseBody)));

if(verify(resDocument)){
System.out.println("The Signature is certified properly");
}

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surely that is not the real code building that String, with all those quote characters mixed in.

Why are you so sure a Document is being created? Where are the statements to catch ard report exceptions?

Bill
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic