1

我必须在 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;
}

感谢您的任何帮助!

4

1 回答 1

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();
于 2013-02-01T09:39:12.930 回答