解析 Web 服务响应时出现问题 (Metro/JAXB)
我之前已经从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
花了相当多的时间在互联网上搜索,发现一个较旧的参考文献指出 Holder 对象确实需要初始化。因此,更正后的方法调用如下所示:
希望这可以帮助可能遇到相同问题的其他人。
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:
Hope this helps others who may have encountered the same issue.