我在JBoss服务器上用JAVA编写了一个Web服务。激活MTOM功能以传输大型附件文件。
我正在尝试实现NodeJS模块来调用Web服务并流式传输附件的内容,但它不起作用: - 我正在使用ws.js模块 - 我的Web服务正在使用JAVA或SOAP UI
这里是我的示例test.js:
var ws = require('ws.js')
, Http = ws.Http
, Mtom = ws.Mtom
var request = '<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getDocument xmlns:ns2="http://core.streaming/"><versionSeriesId>{8039A45E-0000-C4AE-9C0F-272E6F941A47}</versionSeriesId></ns2:getDocument></S:Body></S:Envelope>';
var ctx = { request: request
, url: "http://myServer/GateWay/Streaming"
, action: ""
, contentType: "application/soap+xml"
}
var handlers = [
new Mtom(),
new Http()
]
console.log("Send");
ws.send(handlers, ctx, function(ctx) {
console.log("Receiving...");
//var file = ws.getAttachment(ctx, "response", "//*[local-name(.)='test']")
//fs.writeFileSync("result.txt", file)
})
//getting error here
调用正在SOAP UI中进行,这里是原始Web服务输出的示例:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:38fb61e1-ab97-46d3-8abb-e904652a2276"; start="<root.message@cxf.apache.org>"; start-info="text/xml"
Transfer-Encoding: chunked
Date: Mon, 16 Oct 2017 06:31:50 GMT
--uuid:38fb61e1-ab97-46d3-8abb-e904652a2276
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/><soap:Body><ns2:getDocument xmlns:ns2="http://core.streaming><return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:dataHandlerContentInfo"><retrievalName>test</retrievalName><contentType>application/pdf</contentType><contentLength>178720</contentLength><content><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:e07148cd-cc96-4162-bb19-2fb832900587-94@cxf.apache.org"/></content><pageCount>0</pageCount></return><return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:contentInfo"><retrievalName>test2.pdf</retrievalName><contentType>application/pdf</contentType><contentLength>77399</contentLength><content><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:e07148cd-cc96-4162-bb19-2fb832900587-95@cxf.apache.org"/></content><pageCount>0</pageCount></return><return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:dataHandlerContentInfo"><retrievalName>test</retrievalName><contentType>application/pdf</contentType><contentLength>178720</contentLength><content><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:e07148cd-cc96-4162-bb19-2fb832900587-96@cxf.apache.org"/></content><pageCount>0</pageCount></return></ns2:getDocument></soap:Body></soap:Envelope>
--uuid:38fb61e1-ab97-46d3-8abb-e904652a2276
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <e07148cd-cc96-4162-bb19-2fb832900587-94@cxf.apache.org>
Content-Disposition: attachment;name="test"
%PDF-1.4
%ÿÿÿÿ
1 0 obj
<< /Pages 2 0 R /Type /Catalog >>
endobj
2 0 obj
....
调用有效,因为我在JBOSS日志中看到了传入的数据。 我从node.js运行test.js时获得的跟踪:
D:\Workspaces\nodejs>node test.js
Send
??Am?y???6!♠?'3TO5aHZ????X???|,?1????iyI?K?9??T?$?????H??W??↓??FY?A??1????(??l)I
u?@:Z???t$▼??+???`@?▲?Y|??R↔?^?6b is not match the current start tagName:sS?
end tag name: ?J?♣?i?3?A?☺???Ct►♫:)\\?↕??V{po?♥g0↑??↕1??¶T?*w♀?
X→☺s?$?;????l§:??_☼??-?3's2's2's2's2???i3l?o?U????9??9????aa?♠?♫?q??????????????
h♀-`☺??- [???W?▬?5a?Fl??6?-b{?♫`??↔?_?◄?◄??N?♥?[x??▲qG??p'p6?♀??3a7??↔\◄?
B?7?P???0??☺??? ?x ♦#♫?Pa►_???▼C∟☺☼ ?D?O?????!∟q♀?X↑d?☻q0↑q<♀A? ◄??B??;↑♠Q??C4?D
?# ?p↓? ♫q2?¶?G<↕↕♀??(↑??A©0∟?hHD<♠F↑.?X?? ?xHF?♠)?o ↔F"?Q?3?A?‼►_????8♂? ?
?`∟?\↑?8??dH7\?)??8▼2◄O%\ ‼♀?►&".?,?? q1?↑?A LB\J?♀r◄?C▲??0?p▬WB is not match
the current start tagName:m?
source code out of document root
Receiving...
有人有提示吗?