开发者

Problems parsing webservice response (Metro/JAXB)

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 = We开发者_开发技巧bParam.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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜