-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reading an attachment from soap rsponse #35
Comments
ok a little more information. so in ws.js in function getAttachment() I console logged the var prop.
I'm getting xml from the soap:Envelope. I would thing this is supposed to be the data of the attachment or what was found in parts[1] above. |
Ok it seems like elem is not being set to anything from select(doc, xpath)[0] in this code in mtom.js if (parts.length==0) { var doc = new Dom().parseFromString(parts[0].data.toString()) for (var i in parts) { |
So I added this block of code after ` for (var i in parts) {
}` in mtom.js This seems to work for a single file. I would really like to get the getAttachment working but I don't really understand the third argument in the function. in the example it's set to "//*[local-name(.)='File1']" |
Ok so I think I've got this figured out. My clue was in the following issue I had to also use the work around Then I was able to use the following which the local-name(.)='content' part was because my soap response from the server was like: |
@chrisgh1 same problem here. When the document name is an url, then the encodeURIComponent breaks the xpath find.
with:
Should we create a PR with this? I mean, do anybody have the same issue? |
@jbaris I'm not really fluent in xpath so I wasn't sure if this was an appropriate fix. However now that you have been able to verify that it's working for more than just me maybe it's time for a PR. |
I'm having some trouble reading an attachment from the soap response using.
var file = ws.getAttachment(ctx, "response", "//*[local-name(.)='File1']"); //fs.writeFileSync("result.pdf", file);
after much hacking around I was able to get the file from the soap response by adding
fs.writeFileSync("result.pdf", parts[1].data);
to mtom.js after this block of code
` //use slice() since in http multipart response the first chars are #13#10 which the parser does not expect
var parts = reader.parse_multipart(ctx.response.slice(2), boundary)
if (parts.length==0) {
console.log("warning: no mime parts in response")
callback(ctx)
return
}`
two things that I'm not sure of are:
for (var i in parts) { var p = parts[i] , id = utils.extractContentId(p.headers["content-id"] ) , xpath = "//*[@href='cid:" + encodeURIComponent(id) + "']//parent::*" , elem = select(doc, xpath)[0] console.log(elem); if (!elem) continue elem.removeChild(elem.firstChild) utils.setElementValue(doc, elem, p.data.toString("base64")) }
fyi the console.log(elem) is returning undefined for each part[0] and part[1] when I run it.
the error I'm getting when I try to run is:
c:\node\test\node_modules\ws.js\lib\ws.js:69
return new Buffer(elem.firstChild.data, "base64")
^
TypeError: Cannot read property 'firstChild' of undefined
at Object.getAttachment (c:\node\test\node_modules\ws.js\lib\ws.js:69:25)
The text was updated successfully, but these errors were encountered: