解析webservice响应的问题(Metro / JAXB)

时间:2011-03-16 22:53:57

标签: java jaxb java-metro-framework unmarshalling

之前我已经从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。 Holder&lt;&gt;在我打电话之前初始化实例?要什么?

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

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

1 个答案:

答案 0 :(得分:1)

花了很多时间在互联网上搜索,发现一个较旧的参考文献,说明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();
}

希望这有助于其他可能遇到同样问题的人。