1

我生成的代码遇到了一些小问题:

这里是我需要的 XML 结构:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<soapenv:Envelope xmlns:v1="http://openclinica.org/ws/study/v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="soapenc" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-27777511" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>xxxx</wsse:Username>
<wsse:Password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxxxxx</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<v1:listAllRequest/>
</soapenv:Body>
</soapenv:Envelope>

这是我所做的代码:

declarePrefix("v1", NAMESPACE);
getBody().addTextNode(null, METHOD_NAME, "?");
XMLParentNode security = new XMLParentNodeImpl(HEADER_NAMESPACE, "Security");
security.addAttribute(HEADER_NAMESPACE,"mustUnderstand", "1");
XMLParentNode usernameToken = new XMLParentNodeImpl(UNT_NAMESPACE, "UsernameToken");
usernameToken.addTextNode(null, "wsse:Username", "root");
usernameToken.addTextNode(PASSTYPE, "wsse:Password", Constants.OC_PASSWORD);
security.addElement(usernameToken);
getHeader().addElement(security);

但输出看起来像:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<soapenv:Envelope xmlns:v1="http://openclinica.org/ws/study/v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<n0:Security n0:mustUnderstand="1" xmlns:n0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<n1:UsernameToken xmlns:n1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>xxxx</wsse:Username>
<n2:wsse:Password xmlns:n2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxxxxx</n2:wsse:Password>
</n1:UsernameToken>
</n0:Security>
</soapenv:Header>
<soapenv:Body>
<listAllRequest>?</listAllRequest>
</soapenv:Body>
</soapenv:Envelope>

你看我的台词有问题

<n0:Security....
<n1:UsernameToken...
<n2:wsse:Password...

我如何更改 n0、n1 等...不仅仅是在行的开头,特别是像 n0:mustUnderstand="1" 这样的标签

我试图声明前缀等,但没有任何改变 tis 对象。

有人能告诉我用什么方法可以改变这个东西非常感谢你的帮助

基督教

4

1 回答 1

0

对于所有 intrestet 用户,我以这种方式解决了它:

declarePrefix("v1", NAMESPACE);
        declarePrefix("soapenc", "soapenc");
        getBody().addTextNode(null, METHOD_NAME, "?");
        XMLParentNode security = new XMLParentNodeImpl(null, "wsse:Security");
        security.declarePrefix("wsse", HEADER_NAMESPACE);
        security.addAttribute(HEADER_NAMESPACE,"mustUnderstand", "1");
        XMLParentNode usernameToken = new XMLParentNodeImpl(null, "wsse:UsernameToken");
        usernameToken.declarePrefix("wsu", UNT_NAMESPACE);
        usernameToken.addAttribute(null, "wsu:Id", "UsernameToken-27777511");
        usernameToken.addTextNode(null, "wsse:Username", Constants.OC_Username);
        usernameToken.addTextNode(null, "wsse:Password", Constants.OC_PASSWORD);
        security.addElement(usernameToken);
        getHeader().addElement(security);

结果与我的传出代码不是 100% 相似,但请求正在工作:)

于 2013-10-09T13:36:53.310 回答