2014-03-25 74 views
1

我在JBOSS EAP 6.2上安裝了一個WebService。當我想要獲取SOAP頭時出現問題。org.apache.cxf.binding.soap.SoapHeader無法轉換爲org.apache.cxf.binding.soap.SoapHeader

代碼,其中引發異常:

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. 
    } 

我知道這是不是真的很漂亮,但在取頭和異常在這種方法percisely提出我很感興趣:

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> 

但它工作得很好,我認爲。

所以我的問題:如何避免它?誰能幫我?謝謝

回答

0

解決方案被發現,只需添加其他圖書館比平時Apache的CXF綁定:

<dependency> 
     <groupId>org.jboss</groupId> 
     <artifactId>jboss-jaxws</artifactId> 
     <version>2.0.1.SP2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.ws.cxf</groupId> 
     <artifactId>jbossws-cxf-server</artifactId> 
     <version>4.2.0.Alpha1</version> 
     <scope>provided</scope> 
    </dependency> 
2

可能有間接依賴。其中一個模塊或庫也可能具有依賴關係org.apache.cxf

試着弄清楚是否有多個版本。最簡單的方法是檢查所有的目標瓶,並找到所有的罐子。然後比較版本並排除不正確的版本

<exclusions> 
    <exclusion> 
     <groupId>org.apache.cxf</groupId> 
     <artifactId>cxf-rt-bindings-soap</artifactId> 
     <version>2.4.2</version> 
    </exclusion> 
    </exclusions> 

此外,JBoss也有可能以某種方式擁有該庫。

+0

我無法找到正確的版本。我查看了https://access.redhat.com/site/articles/112673,但只有指定的JBoss WS_CXF。也許我應該使用它而不是原始的apache庫? –

+0

是的,你是對的,但真正的解決方案是使用其他庫:jboss-cxf-server。謝謝你的提示! –

相關問題