Soap 服务在本地工作,但在另一台服务器上引发 ClassCast 异常



有人可以帮我解决一个奇怪的问题吗?

我有一项服务:

@WebMethod
@WebResult(name = "sendCustomerCommunicationResponse", targetNamespace = "......something/Underwriting/Correspondance/V1", partName = "Body")
public SendCustomerCommunicationResponse sendCustomerCommunication(
@WebParam(name = "sendCustomerCommunicationRequest", targetNamespace = "........something/Underwriting/Correspondance/V1", partName = "Body")
SendCustomerCommunicationRequest body)
throws ServiceException_Exception, SystemException_Exception
;

在本地,我用

SendCustomerCommunicationResponse response = correspondanceServicePort.sendCustomerCommunication(sendCustomerCommunicationRequest);

这很有效。 但是,当我在另一台服务器上部署应用程序时,我会收到:

"java.lang.ClassCastException: 
it.usi.xframe.ub1.batch.services.esb.SendCustomerCommunicationRequest incompatible with 
it.usi.xframe.ub1.batch.services.esb.SendCustomerCommunicationResponse"

附言应用程序在 WebSphere 服务器上运行

请求是:

<soapenv:Envelope ...someSchema...>
<soapenv:Header>
<v1:TechnicalHeader>
<v1:correlationId>12742</v1:correlationId>
<v1:sender>userName</v1:sender>
<v1:countryCode/>
<v1:channelId/>
<v1:userID>userName</v1:userID>
<v1:operationId>CHANGE_STATUS</v1:operationId>
</v1:TechnicalHeader>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>someUser</wsse:Username>
<wsse:Password>somePassoword</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<v11:sendCustomerCommunicationRequest>
<v11:eventCode>{"header":{"publishingDate":1474016634749,"eventId":"DEL-NEG","applicationCode":"UB3","correlationId":"9999","language":"IT","channelId":"MOB"},"body":{"ndg":"5106215","additionalInfo":{}}}</v11:eventCode>
</v11:sendCustomerCommunicationRequest>
</soapenv:Body>
</soapenv:Envelope>

也许这可能是 WebSphere JAXB 问题,与您正在使用的版本有关,或者您的服务器可能会错过一些修复。看看文档是怎么说的:

JAXB 解组器在运行时生成存根类,以帮助 取消编组文档。这些生成的类是缓存的,并且可能 被应用程序中的其他 JAXBContext 重用。

JAXBContext包含具有元素通配符的类时 (即@XmlAnyElement)解组者可能会使用 从另一个JAXBContext生成的不兼容的存根类ClassCastException可能导致在 解组。通过改善碰撞解决了问题 检查完成以前生成的存根类,以便新的存根 类是从当前JAXBContext生成的,如果之前 在缓存中找到的生成的存根类不兼容。

这很难猜测,因为无论您使用哪个版本,IBM 的性质都很好。另外,请参阅其他一些修复方法:

  • 在 JAX-WS 应用程序启动期间
  • 启用 servlet 高速缓存时
  • WSDL 位置属性作为 消息上下文存储为字符串
  • 单向 JAX-WS Web 服务使用基于提供程序的 端点
  • 已在本地通信路径中添加了其他代码 检测并拒绝通过过时发送数据的尝试 连接

问:

  • 如何定义SendCustomerCommunicationResponse?它是否包括@Xml..注释?(例如@XmlRoot ..
  • 只是为了测试,您能否将@WebResult返回变量的名称设置为与返回类 (SendCustomerCommunicationResponse的名称不同的名称
  • 什么是ServiceException_ExceptionSystemException_Exception? 你自己的例外?似乎这些是JAX-RS/JAXB生成的异常。

看起来像是类版本不匹配的问题。

开发人员创建 Web 服务存根并使用较新版本在其项目中生成它们,而服务器类路径具有某些依赖 jar 文件的较旧版本的方案之一。我建议执行以下步骤来排除这种不匹配的依赖项版本的选项。

  1. 获取依赖项树和失败的文件。您应该获得依赖 jar 文件的列表。(具体检查负责在本地计算机中创建请求和响应对象的 jar 文件)
  2. 比较 WebSphere 服务器的类路径并添加任何缺少的 jar。
  3. 替换 WebSphere 类路径中的任何依赖 jar 文件(如果它们属于旧版本)。

第二种方法是在 IDE 中启用反编译器后执行远程调试(如果可能)。检查发生异常的类文件,并确保编辑器链接到导航器视图,以确保导航器在正在调试的 jar 中显示文件。您应该能够找到在异常发生时调用的确切 jar 文件。

似乎问题出在服务器上(或请求)。

当服务器处理请求时,它只是回显它。 消息有效负载未更改(出于任何原因),并且未引发异常。

所以当它回来并解组时,它不是SendCustomerCommunicationResponse的实例,而是SendCustomerCommunicationRequest

我可以建议首先在客户端和服务器之间使用 SOAPUI(带有请求示例)或 tcpMon,以查看来自服务器的确切请求和响应。

相关内容

最新更新