2010-08-24 93 views
2

我們目前在使用JAX-WS實現方面存在問題,特別是獲取服務返回的值,儘管我們給它一個值,但在我們的例子中總是爲null。如何將值設置爲javax.xml.ws.Holder?

之前,我們的問題更多的解釋某些代碼:

這是我們操作的簽名:

@WebMethod(action = "urn:genererEdition") 
public void genererEdition(
    @WebParam(name = "requeteEdition", targetNamespace = "http://creditcgi.com/serviceeditique", partName = "requete") 
    RequeteEdition requete, 
    @WebParam(name = "reponseEdition", targetNamespace = "http://creditcgi.com/serviceeditique", mode = WebParam.Mode.OUT, partName = "reponse") 
    Holder<ReponseEdition> reponse, 
    @WebParam(name = "documentProduit", targetNamespace = "", mode = WebParam.Mode.OUT, partName = "documentProduit") 
    Holder<byte[]> documentProduit); 

這裏是我們的Web服務測試案例:

@Test 
public void testCallGenererEdition() { 
    RequeteEdition requete = new RequeteEdition(); 

    Holder<ReponseEdition> reponseHolder = new Holder<ReponseEdition>(new ReponseEdition()); 
    Holder<byte[]> documentHolder = new Holder<byte[]>(new byte[512]); 

    editique.genererEdition(requete, reponseHolder, documentHolder); 

    Assert.assertNotNull(reponseHolder.value); 
    Assert.assertNotNull(reponseHolder.value.getCodeRetour()); 
} 

最後,我們的WS實施:

@Override 
public void genererEdition(RequeteEdition requete, 
     Holder<ReponseEdition> reponse, Holder<byte[]> documentProduit) { 

    // if we do no instanciate ReponseEdition, we got a Null Pointer Exception 
    reponse.value = new ReponseEdition(); 

    reponse.value.setCodeRetour("OK"); 
} 

正如您在測試中看到的那樣,我們總是變爲空。我們在迴應Holder中返回一個空對象時會做錯什麼?

預先感謝您。

+1

事實上,這個問題是由於我們使用WSDL和輸出由在mulitpart:<皁:身體部位= 「效應初探」 使用= 「字面」/ > ...我們決定改變WSDL來避免這個問題,但是我們還沒有得到答案... – ipingu 2011-10-26 13:26:30

回答

5

它會解決你的問題,獲得NULL值作爲迴應。

....genererEdition(....){ ReponseEdition re = new ReponseEdition(); reponse.value = re; }