带附件的ColdFusion SOAP响应

Phi*_*sen 33 coldfusion soap

我正在使用Coldfusion9与第三方SOAP服务进行交互,我需要使用它来发送和接收带附件的SOAP.通过在HTTP内容周围使用ToString()将SOAP Body转换为可用的字符串,我在接收可能有也可能没有二进制附件的SOAP方面没有任何问题,但是服务要求我也使用附件发回我的响应这是我要撤消的地方.我在ColdFusion中从未这样做过,我不确定如何将其呈现给原始服务,以便通过ID引用SOAP主体.

下面是使用附件解析传入的SOAP数据:

<cfset soapData = GetHttpRequestData()>

<!--- Loop over the HTTP headers and dump the SOAP content into a variable --->
<cfsavecontent variable="soapContent">
<cfoutput>      
    <cfloop collection = #soapData.headers# item = "http_item">
    #http_item#: #StructFind(soapData.headers, http_item)# #chr(10)##chr(13)# 
    </cfloop>
    request_method: #soapData.method# #chr(10)##chr(13)# 
    server_protocol: #soapData.protocol# #chr(10)##chr(13)# 
    http_content --- #chr(10)##chr(13)#  
    #toString(soapData.content)#
</cfoutput>
</cfsavecontent>

<!--- Save file to flat file --->
<cffile action = "write" 
    file = "#expandPath('../')#logs/#dateFormat(now(),'dd-mm-yyyy')#_#timeFormat(now(),'HHmmss')#.txt" 
    output = "#soapContent#">
Run Code Online (Sandbox Code Playgroud)

现在,我正在将响应呈现为一个完整的SOAP XML响应,其中包含作为内联XML的主体以及所需的STATUSCODE(参见下文).

<cfsavecontent variable="strResponse">
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAPENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
    <SOAPENV:Body>
        <ns1:processResponse xmlns:ns1="urn:TripFlow" SOAPENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
            <STATUSLVL>00</STATUSLVL>
        </ns1:processResponse>
    </SOAP-ENV:Body>
</SOAPENV:Envelope>
</cfsavecontent>

<!--- Strip all whitespace between tags --->
<cfset strResponse = trim(ReReplaceNoCase(strResponse,'(>[\s]*<)','><','ALL'))>

<!--- Output the XML response to the soap service --->
<cfoutput>#strResponse#</cfoutput>
Run Code Online (Sandbox Code Playgroud)

上面的响应引发了一个错误,因为SOAP服务要求发送响应作为附件引用正文消息,如下文所示:

HTTP/1.1 200 OK
Date: Thu, 01 Apr 2010 09:30:25 GMT
Server: Jetty/5.1.4 (Windows XP/5.1 x86 java/1.5.0_15
Content-Type: multipart/related; boundary=soaptestserver; type="text/xml"; start="<theenvelope>"
SOAPAction: ""
Content-Length: 796
Connection: close

--soaptestserver
Content-ID: <theenvelope>
Content-Transfer-Encoding: 8bit
Content-Type: text/xml; charset=utf-8
Content-Length: 442

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAPENV="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"><SOAPENV:
Body><ns1:processResponse xmlns:ns1="urn:TripFlow" SOAPENV:
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><message
href="cid:thecontentmessage"/></ns1:processResponse></SOAP-ENV:Body></SOAPENV:
Envelope>

--soaptestserver
SOAP Interface
www.travelsolutions.com 123
travel solutions online V14.0 External System Integration
Content-ID: <thecontentmessage>
Content-Transfer-Encoding: 8bit
Content-Type: text/xml; charset=utf-8
Content-Length: 65

<?xml version="1.0" encoding="UTF-8"?><STATUSLVL>00</STATUSLVL>
--soaptestserver--
Run Code Online (Sandbox Code Playgroud)

任何帮助都会非常感激,因为我真的在这个墙上碰到了我的头.谢谢!

小智 1

我已经有一段时间没有使用 ColdFusion 了。我记得的最后一次,它没有提供发送 SOAP 附件的工具。我通过使用 Java 编写自定义 CFX标签解决了这个问题,它为我解决了这个问题。整个 SOAP 调用都需要经过该标记。

如果您选择这样做,您想要查看的 Java 库是javax-ws。您还需要查明服务调用是否必须使用 MTOM。

抱歉,这不是一个直接的解决方案,但这是我在几个版本前对 CF 所做的事情。