gpt4 book ai didi

javax.xml.soap.SOAPException :unable to find namespace for prefix: wsse HEADER Security

转载 作者:行者123 更新时间:2023-12-02 13:32:52 24 4
gpt4 key购买 nike

当我尝试使用安全性对 header 进行编码时出现以下错误:

javax.xml.soap.SOAPException: unable to find namespace for prefix: wsse at weblogic.xml.saaj.SOAPElementImpl.addChildElement(SOAPElementImpl.java:357) at pr.com.prt.eppaSapInt.ws.SecurityHeader.doWithMessage(SecurityHeader.java:48)

这是我的代码:

public class SecurityHeader implements WebServiceMessageCallback{

@Override
public void doWithMessage(WebServiceMessage wsMessage) throws IOException, TransformerException {
SOAPMessage soapMessage = ((SaajSoapMessage)wsMessage).getSaajMessage();

SOAPHeader header;
SOAPHeaderElement security;
SOAPHeaderElement usertoken;
SOAPElement username;
SOAPElement password;

try {
header = soapMessage.getSOAPHeader();
//header.addNamespaceDeclaration("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
//header.addNamespaceDeclaration("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
security = header.addHeaderElement(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", "wsse"));
usertoken = header.addHeaderElement(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "UsernameToken", "wsu"));

username = usertoken.addChildElement("Username", "wsse");
password = usertoken.addChildElement("Password", "wsse");
password.setAttribute("Type","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");

username.setTextContent("eppa2SAP_app");
password.setTextContent("eppa2SAP_app123");

security.addChildElement(username);
security.addChildElement(password);
security.addChildElement(usertoken);

JAXBContext context = JAXBContext.newInstance();

Marshaller marshaller = context.createMarshaller();
marshaller.marshal(null, ((SoapHeader) soapMessage).getResult());

} catch (JAXBException e) {
throw new IOException("error while marshalling authentication JAXB.");
} catch (MarshallingException e) {
throw new IOException("error while marshalling authentication exception.");
} catch (SOAPException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

最佳答案

我认为问题在于QNames 表现不佳。尝试使用 header.addChildElement(localName, prefix, uri); 来代替 SecurityUsernameToken

关于javax.xml.soap.SOAPException :unable to find namespace for prefix: wsse HEADER Security,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43129565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com