ws.js
ws.js copied to clipboard
Source code out of document root
Hi, im trying to retrive an attachment from a webservice but im getting "Source code out of document root"
This is the response from SOAP:
------=_Part_108_10085489.1476204609337 Content-Type: text/xml; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-ID: [email protected]
soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> soap:Body> ns2:generarXmlResponse"> return> xop:Include href="cid:dddbf7e4-1076-1968-1174-5fd0a597f7f8-2@http%3A%2F%2Fcxf.apache.org%2F" xmlns:xop="http://www.w3.org/2004/08/xop/include"/> /return> /ns2:generarXmlResponse> /soap:Body> /soap:Envelope>
------=_Part_108_10085489.1476204609337 Content-Type: text/xml; charset=us-ascii Content-Transfer-Encoding: 7bit Content-ID: <file.xml> Content-Disposition: attachment; name="file.xml"
?xml version="1.0" encoding="UTF-8"?> SOAP-ENV:Envelope xmlns:SOAP-ENV="http://sch//emas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:m0="http://iop.crimsonlogic.com/Cabecera" xmlns:m1="http://www.w3.org/2001/12/soap-envelope" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> SOAP-ENV:Body> ... /SOAP-ENV:Body> /SOAP-ENV:Envelope>
This is how am trying to get the xml from the attachment:
var ws = require('ws.js')
, Http = ws.Http
, Addr = ws.Addr
, Mtom = ws.Mtom
, Security = ws.Security
, UsernameToken = ws.UsernameToken
, ctx = { request: "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'>" +
"<Header />" +
"<Body>" +
"<ent:generarXml>" +
"<token>"+ token +"</token>" +
"</ent:generarXml>" +
"</Body>" +
"</Envelope>"
, url: service_url
, contentType: "text/xml"
};
var handlers = [ new Security({}, [new UsernameToken({username: 'user', password: 'pass'})])
, new Http()
, new Mtom()];
ws.send(handlers, ctx, function(ctx) {
console.log(ctx.response);
var file = ws.getAttachment(ctx, "response", "//*[local-name(.)='return']");
fs.writeFileSync("C:\\Users\\Usuario\\Desktop\\result.xml", file);
});
Also, if change handler Mtom up from Http i cant see my xml file on console.
Im using wss security, Any idea? :(