【问题标题】:how to extract wsse BinarySecurityToken using PL/SQL如何使用 PL/SQL 提取 wsse BinarySecurityToken
【发布时间】:2016-11-29 04:28:25
【问题描述】:
如何使用 PL/SQL 从以下 SOAP 负载中提取 BinarySecurityToken?
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">expectedToken</wsse:BinarySecurityToken>
</wsse:Security>
我希望提取“expectedToken”作为结果
谢谢
【问题讨论】:
标签:
xml
oracle
soap
plsql
【解决方案1】:
您不需要 PL/SQL;您可以在纯 SQL 中使用 XQuery:
select XMLQuery('declare namespace wsse = "http://schemas.xmlsoap.org/ws/2002/12/secext"; (::)
/wsse:Security/wsse:BinarySecurityToken/text()'
passing XMLType('<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">expectedToken</wsse:BinarySecurityToken>
</wsse:Security>')
returning content)
from dual;
XMLQUERY('DECLARENAMESPACEWSSE="HTTP://SCHEMAS.XMLSOAP.ORG/WS/2002/12/SECEXT";(:
--------------------------------------------------------------------------------
expectedToken
如果您已经在 PL/SQL 中获得响应并希望继续使用它,那么如果 SOAP 值在字符串变量中,您可以这样做:
set serveroutput on
declare
soap varchar2(500);
token varchar2(200);
begin
soap := '<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">expectedToken</wsse:BinarySecurityToken>
</wsse:Security>';
select XMLQuery('declare namespace wsse = "http://schemas.xmlsoap.org/ws/2002/12/secext"; (::)
/wsse:Security/wsse:BinarySecurityToken/text()'
passing XMLType(soap)
returning content).getStringVal()
into token
from dual;
dbms_output.put_line(token);
end;
/
PL/SQL procedure successfully completed.
expectedToken