我必须在Java 4中编写一个JAX-RPC SOAP消息处理程序,我需要在消息中添加一个安全标头。
目前,当我尝试发送消息时,我收到java.lang.AbstractMethodError: org.apache.axis.message.SOAPHeader.addHeaderElement(Ljavax/xml/namespace/QName;)Ljavax/xml/soap/SOAPHeaderElement;
错误。
我在网上找不到这个错误,所以任何帮助都将不胜感激!
我的代码如下:
public final boolean handleRequest(MessageContext context) {
SOAPMessageContext soapContext = (SOAPMessageContext) context;
String authId = "test";
try {
SOAPMessage soapMsg = soapContext.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnv.getHeader();
/* If no header, add one */
if (soapHeader == null) {
soapHeader = soapEnv.addHeader();
}
/* Add a soap header, name as AUTH_ID_KEY */
QName qname = new QName(TARGET_NAMESPACE, AUTH_ID_KEY);
SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(qname);
soapHeaderElement.addTextNode(authId);
soapMsg.saveChanges();
} catch (SOAPException e) {
throw new ProtocolException(e);
}
return true;
}
感谢您的帮助!
答案 0 :(得分:2)
因此org.apache.axis.message.SOAPHeader
实现了javax.xml.soap.SOAPHeader
,但保留了addHeaderElement(QName)
方法的摘要。
当使用此实现时,我不得不使用addHeaderElement(javax.xml.soap.Name)
方法。
最终的工作代码如下:
SOAPMessage soapMessage = soapContext.getMessage();
SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnvelope.getHeader();
/* If no header, add one */
if (soapHeader == null) {
soapHeader = soapEnvelope.addHeader();
}
/* Add a soap header, name as AUTH_ID_KEY */
Name name = soapEnvelope.createName(AUTH_ID_KEY);
SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(name);
soapHeaderElement.addTextNode(authId);
soapMessage.saveChanges();