我编写了一个带有安全标头的soap请求包络类。我正在使用retrofit2及其simplexml转换器。有些人如何坚持找到问题。我在使用下面的类时得到内部服务器错误500。我已经删除了getter和setter,因此问题将是准确的。
@Root(name = "soapenv")
@NamespaceList({
@Namespace(prefix = "new", reference = "http://www.example.org/ClassViewRQST"),
@Namespace(prefix = "soapenv", reference = "http://schemas.xmlsoap.org/soap/envelope/")
})
public class PeopleSoftRequest {
@Element(name = "soapenv:Header", required = false)
private PeopleSoftHeader header;
@Root(name = "soapenv:Header", strict = false)
public static class PeopleSoftHeader {
@Element(name = "wsse:Security", required = false)
private Security security;
}
@NamespaceList({
@Namespace(prefix = "mustUnderstand", reference = "1"),
@Namespace(prefix = "wsse", reference = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
})
@Root(name = "wsse:Security", strict = false)
public static class Security {
@Element(name = "wsse:UsernameToken", required = false)
private UserNameToken userNameToken;
}
@Root(name = "wsse:UsernameToken", strict = false)
public static class UserNameToken {
@Element(name = "wsse:Username", required = false)
private String username;
@Namespace(prefix = "type", reference = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText")
@Element(name = "wsse:Password", required = false)
private String passWord;
}
@Element(name = "Body", required = false)
private PeopleSoftBody body;
}
以下是原始肥皂请求信封以供参考。
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:new="http://www.example.org/ClassViewRQST">
<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>
<wsse:Username>XXXXXXX</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>\n
<soapenv:Body>
</soapenv:Body>
</soapenv:Envelope>
答案 0 :(得分:2)
解决了这个问题。以下是详细信息...
主要问题是当请求soap生成它时,如果搞乱了soap标签命名空间前缀
请求生成
<type:wsse:Password xmlns:type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXXXXX</type:wsse:Password>
正确的请求标记
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXXXXX</wsse:Password>
如上所述的Genrating soap标签我在创建下面的类时使用属性解决问题
public static class Password{
@Text
private String password;
@Attribute(name = "Type")
String Type = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}