java 如何为 javax.xml.ws.Holder 设置值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3555193/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 02:23:21  来源:igfitidea点击:

How to set a value to a javax.xml.ws.Holder?

javaweb-servicesjax-ws

提问by Erik Clairiot

we are currently having problems with a JAX-WS implementation, particulary in getting a value returned by the service, which in our case is always null, although we give it a value.

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

Some code before more explanations of our problem :

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

Here is the signature of our operation :

这是我们操作的签名:

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

Here is our web service test case :

这是我们的 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());
}

And finally, our WS implementation :

最后,我们的 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");
}

As you can see with the test, we are always getting null. What do we do wrong for always having a null object returned in the reponse Holder ?

正如你在测试中看到的,我们总是得到 null。总是在响应 Holder 中返回空对象,我们做错了什么?

Thank you in advance.

先感谢您。

回答by nilsmart

It will solve your problem of getting NULL values in response.

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

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

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