on 03-10-2008 1:03 PM
Hey!
I am developing an adapter module to transform a coded password back to clear text. I have access to the XML element where the password is and I get to transform it, but I have 2 problems as also stated in the code:
1) I cannot set the new value back to the node. I try with
firstNode.getFirstChild().setNodeValue(decodedPwd);
but this does not seem to work. How can I achieve this?
2) Between the first issue and the code
msg.setDocument(xmlpayload);
I am not sure how to get my new values for the node back in the XMLPayload. How can I achieve this?
Here is the code:
msg = (Message) inputModuleData.getPrincipalData();
XMLPayload xmlpayload = msg.getDocument();
factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse((InputStream)xmlpayload.getInputStream());
password = (Element)document.getElementsByTagName("ns1:passord").item(0);
firstNode = password.getFirstChild();
pwd = firstNode.getNodeValue();
if(pwd != null){
decodedPwd = Decoder.decodeString(pwd);
}
// THIS FAILS!
firstNode.getFirstChild().setNodeValue(decodedPwd);
//HOW TO SET NEW NODE VALUE TO XMLPAYLOAD HERE?
msg.setDocument(xmlpayload);
inputModuleData.setPrincipalData(msg);
return inputModuleData;
Help is much appreciated!
Thanks!
regards Ole
Hey,
This might sound funny but can you check your code twice? is it really "ns1:passord"??? or "ns1:password"??
Did you have a look at the trace files? I think you will find the problem in that...
Cheers,
Sarath.
Award if helpful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey!
The problem was solved. The code snipped I found was:
DOMSource DOMSource = new DOMSource(document);
ByteArrayOutputStream myBytes = new ByteArrayOutputStream();
Result dest = new StreamResult(myBytes);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
serializer.transform(DOMSource, dest);
byte[] docContent = myBytes.toByteArray();
xmlpayload.setContent(docContent);
msg.getDocument().setContent(xmlpayload.getContent());
Ole
Edited by: Ole Mugaas on Mar 27, 2008 8:43 PM
User | Count |
---|---|
92 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.