解析 Web 服务响应时出现问题 (Metro/JAXB)

发布于 2024-10-22 02:28:46 字数 2787 浏览 1 评论 0原文

我之前已经从 WSDL 生成了 Metro/JAXB 客户端,并且 Java 类与 SOAP/XML 之间的编组/解组工作没有任何问题。我生成了一个新客户端,似乎存在解组问题,我不确定为什么。 WSDL 非常大(> 27,000 行),我不得不使用 -B-XautoNameResolution,因为某些元素名称除了大小写外都是相同的。

我正在尝试执行此方法/操作:

@WebService(name = "servicePortType", targetNamespace = "urn:service")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface ServicePortType {


    /**
     * Service definition of function unsp__GetSubscriberList
     * 
     * @param result
     * @param totalSubsFound
     * @param getSubListReq
     * @param paginatedInfo
     * @param getSubscriberListData
     */
    @WebMethod(operationName = "GetSubscriberList")
    @RequestWrapper(localName = "GetSubscriberList", targetNamespace = "urn:service", className = "service.GetSubscriberList")
    @ResponseWrapper(localName = "GetSubscriberListResult", targetNamespace = "urn:service", className = "service.GetSubscriberListResult")
    public void getSubscriberList(
        @WebParam(name = "GetSubListReq", targetNamespace = "")
        GetSubscriberListRequest getSubListReq,
        @WebParam(name = "Result", targetNamespace = "", mode = WebParam.Mode.OUT)
        Holder<ResultCodeStruct> result,
        @WebParam(name = "PaginatedInfo", targetNamespace = "", mode = WebParam.Mode.OUT)
        Holder<PaginatedInfo> paginatedInfo,
        @WebParam(name = "TotalSubsFound", targetNamespace = "", mode = WebParam.Mode.OUT)
        Holder<Integer> totalSubsFound,
        @WebParam(name = "GetSubscriberListData", targetNamespace = "", mode = WebParam.Mode.OUT)
        Holder<GetSubscriberListData> getSubscriberListData);

}

此方法将返回订阅者数据以及订阅者总数。我的调用如下所示:

public int getTotalSubscriptions()
        throws Exception
{
    GetSubscriberListRequest subscriberListRequest = factory.createGetSubscriberListRequest();
    Holder<ResultCodeStruct> result = null;
    Holder<PaginatedInfo> paginatedInfo = null;
    Holder<Integer> totalSubsFound = null;
    Holder<GetSubscriberListData> subscriberListData = null;

    subscriberListRequest.setMaxSubscribers(factory.createGetSubscriberListRequestMaxSubscribers(1));

    port.getSubscriberList(subscriberListRequest,
            result,
            paginatedInfo,
            totalSubsFound,
            subscriberListData);

    if (result.value.getResultCode() != CODE_SUCCESS)
    {
        throw new Exception("Failed call");
    }

    return totalSubsFound.value.intValue();
}

我在结果对象上收到 NullPointerException。我已经跟踪了 SOAP 调用,并且返回的 XML 符合预期,包括 Result 元素。

我以前从未遇到过WebParam.Mode.OUT。持有者是否应该?在调用之前初始化实例吗?为了什么?

这些元素包装在 SOAP 中的 GetSubscriberListResult 元素中,但由于接口方法在 @ResponseWrapper 中定义了该元素,因此我希望将它们解组到传入的对象中。也许我需要做其他事情?

非常感谢任何建议/帮助!

I have generated a Metro/JAXB client from a WSDL before and the marshalling/unmarshalling of the Java classes to/from SOAP/XML worked without any issues. I have generated a new client and there seems to be unmarshalling issues and I'm not sure why. The WSDL is very large (> 27,000 lines) and I had to use -B-XautoNameResolution because of some element names being the same except for case.

I am trying to execute this method/operation:

@WebService(name = "servicePortType", targetNamespace = "urn:service")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface ServicePortType {


    /**
     * Service definition of function unsp__GetSubscriberList
     * 
     * @param result
     * @param totalSubsFound
     * @param getSubListReq
     * @param paginatedInfo
     * @param getSubscriberListData
     */
    @WebMethod(operationName = "GetSubscriberList")
    @RequestWrapper(localName = "GetSubscriberList", targetNamespace = "urn:service", className = "service.GetSubscriberList")
    @ResponseWrapper(localName = "GetSubscriberListResult", targetNamespace = "urn:service", className = "service.GetSubscriberListResult")
    public void getSubscriberList(
        @WebParam(name = "GetSubListReq", targetNamespace = "")
        GetSubscriberListRequest getSubListReq,
        @WebParam(name = "Result", targetNamespace = "", mode = WebParam.Mode.OUT)
        Holder<ResultCodeStruct> result,
        @WebParam(name = "PaginatedInfo", targetNamespace = "", mode = WebParam.Mode.OUT)
        Holder<PaginatedInfo> paginatedInfo,
        @WebParam(name = "TotalSubsFound", targetNamespace = "", mode = WebParam.Mode.OUT)
        Holder<Integer> totalSubsFound,
        @WebParam(name = "GetSubscriberListData", targetNamespace = "", mode = WebParam.Mode.OUT)
        Holder<GetSubscriberListData> getSubscriberListData);

}

This method will return the subscriber data and also the total number of subscribers. My call looks like this:

public int getTotalSubscriptions()
        throws Exception
{
    GetSubscriberListRequest subscriberListRequest = factory.createGetSubscriberListRequest();
    Holder<ResultCodeStruct> result = null;
    Holder<PaginatedInfo> paginatedInfo = null;
    Holder<Integer> totalSubsFound = null;
    Holder<GetSubscriberListData> subscriberListData = null;

    subscriberListRequest.setMaxSubscribers(factory.createGetSubscriberListRequestMaxSubscribers(1));

    port.getSubscriberList(subscriberListRequest,
            result,
            paginatedInfo,
            totalSubsFound,
            subscriberListData);

    if (result.value.getResultCode() != CODE_SUCCESS)
    {
        throw new Exception("Failed call");
    }

    return totalSubsFound.value.intValue();
}

I get a NullPointerException on the result object. I have traced the SOAP call and the XML being returned is as expected including a Result element.

I have never encountered WebParam.Mode.OUT before. Should the Holder<> instances be initialized before I make the call? To what?

Those elements are wrapped in a GetSubscriberListResult element in the SOAP, but since the interface method has that defined in the @ResponseWrapper, I was expecting them to be unmarshalled into the objects passed in. Maybe I need to do something else?

Any advice/help is greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘东忘西忘不掉你 2024-10-29 02:28:46

花了相当多的时间在互联网上搜索,发现一个较旧的参考文献指出 Holder 对象确实需要初始化。因此,更正后的方法调用如下所示:

public int getTotalSubscriptions()
        throws Exception
{
        GetSubscriberListRequest subscriberListRequest = factory.createGetSubscriberListRequest();
        Holder<ResultCodeStruct> result = new Holder<ResultCodeStruct>(factory.createResultCodeStruct());
        Holder<PaginatedInfo> paginatedInfo = new Holder<PaginatedInfo>(factory.createPaginatedInfo());
        Holder<Integer> totalSubsFound = new Holder<Integer>(new Integer(0));
        Holder<GetSubscriberListData> subscriberListData = new Holder<GetSubscriberListData>(factory.createGetSubscriberListData());

    subscriberListRequest.setMaxSubscribers(factory.createGetSubscriberListRequestMaxSubscribers(1));

    port.getSubscriberList(subscriberListRequest,
            result,
            paginatedInfo,
            totalSubsFound,
            subscriberListData);

    if (result.value.getResultCode() != CODE_SUCCESS)
    {
        throw new Exception("Failed call");
    }

    return totalSubsFound.value.intValue();
}

希望这可以帮助可能遇到相同问题的其他人。

Spent quite a bit of time searching on the internet and found an older reference stating that the Holder objects do need to be initialized. So, the corrected method calls looks like this:

public int getTotalSubscriptions()
        throws Exception
{
        GetSubscriberListRequest subscriberListRequest = factory.createGetSubscriberListRequest();
        Holder<ResultCodeStruct> result = new Holder<ResultCodeStruct>(factory.createResultCodeStruct());
        Holder<PaginatedInfo> paginatedInfo = new Holder<PaginatedInfo>(factory.createPaginatedInfo());
        Holder<Integer> totalSubsFound = new Holder<Integer>(new Integer(0));
        Holder<GetSubscriberListData> subscriberListData = new Holder<GetSubscriberListData>(factory.createGetSubscriberListData());

    subscriberListRequest.setMaxSubscribers(factory.createGetSubscriberListRequestMaxSubscribers(1));

    port.getSubscriberList(subscriberListRequest,
            result,
            paginatedInfo,
            totalSubsFound,
            subscriberListData);

    if (result.value.getResultCode() != CODE_SUCCESS)
    {
        throw new Exception("Failed call");
    }

    return totalSubsFound.value.intValue();
}

Hope this helps others who may have encountered the same issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文