java.lang.AbstractMethod将标头添加到 Java 4 JAX-RPC SOAP Handler 时



我必须在Java 4中编写一个JAX-RPC肥皂消息处理程序,并且我需要为消息添加安全标头。

目前,当我尝试发送消息时,出现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;
}

感谢您的任何帮助!

>所以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();

相关内容

  • 没有找到相关文章

最新更新