如何设置javax.xml.ws.Holder的值?

时间:2010-08-24 09:39:18

标签: java web-services jax-ws

我们目前遇到了JAX-WS实现的问题,尤其是获取服务返回的值,在我们的例子中,它总是为null,尽管我们给它一个值。

在对我们的问题进行更多解释之前的一些代码:

这是我们行动的签名:

@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);

以下是我们的网络服务测试用例:

@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");
}

正如您在测试中看到的那样,我们总是变为空。在响应持有者中总是返回一个空对象我们做错了什么?

提前谢谢。

1 个答案:

答案 0 :(得分:6)

它将解决您在响应中获取NULL值的问题。

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