我在 JBOSS EAP 6.2 上安装了一个 WebService。当我想获取 SOAP header 时出现问题。
引发异常的代码:
ArrayList<SoapHeader> hl = (ArrayList<SoapHeader>) wsctx.getMessageContext().get("org.apache.cxf.headers.Header.list");
String username = "";
String password = "";
for (int i = 0; i < hl.size(); i++) { //for(SoapHeader header : hl) gives this same exception
SoapHeader header = hl.get(i);
//here is fetching data from this header. Not important to this case.
}
我知道它不太漂亮,但我真的有兴趣获取 header 和在此方法中准确引发的异常:
hl.get(i)
异常消息是:
org.apache.cxf.binding.soap.SoapHeader cannot be cast to org.apache.cxf.binding.soap.SoapHeader
起初我认为我的 Maven 的 POM 文件版本错误,所以:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>2.4.2</version>
</dependency>
但我认为效果很好。
所以我的问题:如何避免它?谁能帮我?谢谢
最佳答案
可能存在间接依赖性。您的模块或库之一也可能具有依赖项 org.apache.cxf
。
尝试弄清楚是否存在多个版本。最简单的方法是检查所有目标目录并找到所有 jar 。然后比较版本并排除不正确的
<exclusions>
<exclusion>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-bindings-soap</artifactId>
<version>2.4.2</version>
</exclusion>
</exclusions>
此外,JBoss 也可能以某种方式拥有该库。
关于java - org.apache.cxf.binding.soap.SoapHeader 无法转换为 org.apache.cxf.binding.soap.SoapHeader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22634730/