I am trying to parse a xml file and get enveloped transform. However when I run the following code , I get the exception : org.apache.xml.security.transforms.TransformationException: No message with ID "envelopedSignatureTransformNotInSignatureElement" found in resource bundle "org/apache/xml/security/resource/xmlsecurity" I debugged the code and realised that its thrown at this line in the code :
transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
Jar used: xml-security-1.0.4.jar
Code:
public class try2 {
public static void main(String[] args) {
byte[] canonXmlBytes, yourXmlBytes;
try{
org.apache.xml.security.Init.init();
File file = new File("D:\\Apurva_Backup\\Apurva\\self study\\C14N\\C14N\\XML\\AppHdrFromSC.xml");
InputStream inputStream = new FileInputStream(file);
long length = file.length();
yourXmlBytes = new byte[(int)length];
inputStream.read(yourXmlBytes);
String xml = yourXmlBytes.toString();
XMLSignatureInput xmlSingnatureInput=new XMLSignatureInput(yourXmlBytes);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
Transforms transforms = new Transforms(doc);
transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
XMLSignatureInput result = transforms.performTransforms(xmlSingnatureInput);
OutputStream os = new FileOutputStream("D:\\Apurva_Backup\\Apurva\\self study\\C14N\\XML\\yapurva.xml");
os.write(result.getBytes());
}catch(Exception e){
System.out.println(e);
}
}
}
Can someone please help me with this prob, as i have been unable to find the solution for 2 days now! Also any suggestions for alternative ways of performing enveloped transform are welcome.
No comments:
Post a Comment