【问题标题】:Soap service works locally but on another server is raising ClassCast ExceptionSoap 服务在本地工作,但在另一台服务器上引发 ClassCastException
【发布时间】:2016-12-15 10:19:17
【问题描述】:

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

我有一个服务:

@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>

【问题讨论】:

  • 没有人吗?什么都没有?:(
  • 某事试图将请求对象分配给响应变量,反之亦然。异常的调用堆栈应显示查找位置。
  • 执行错误 java.lang.ClassCastException: it.usi.xframe.ub1.batch.services.esb.customerCommunication2.SendCustomerCommunicationRequest 与 it.usi.xframe.ub1.batch.services.esb 不兼容。 customerCommunication2.SendCustomerCommunicationResponseQ ZQat com.sun.proxy.$Proxy84.sendCustomerCommunication(Unknown Source)QZQat it.usi.xframe.ub1.batch.steps.close.ST002CLO.callEsbForPo 位置(ST002CLO.java:241)QZQat it.usi.xframe .ub1.batch.steps.close.ST002CLO.managePositionList(ST002CLO.java:367)QZQat it.usi.xfram e.ub1.batch.steps.close.ST002CLO.run(ST002CLO.java:1
  • 这似乎与代理有关,但我不明白出了什么问题。代理可能期望 SendCustomerCommunicationResponse 而不是 SendCustomerCommunicationRequest 作为输入,但我不明白为什么
  • 我也尝试使用 wsimport -target 2.0 重新生成客户端,但结果是一样的

标签: java web-services soap websphere


【解决方案1】:

可能是 WebSphere JAXB 问题,与您使用的版本有关,或者您的服务器可能缺少一些修复。看看what the docs say

JAXB Unmarshaller 在运行时生成存根类以协助 解组文档。这些生成的类被缓存并且可以 被应用程序中的其他 JAXBContext 重用。

JAXBContext 包含具有元素通配符的类时 (即@XmlAnyElement)Unmarshaller 可能会使用 来自另一个 JAXBContext 的不兼容生成的存根类 可能导致ClassCastException 在期间被抛出 解组。通过改进碰撞解决了问题 检查以前生成的存根类,以便新的存根 类是从当前的JAXBContext 生成的,如果之前 在缓存中发现生成的存根类不兼容。

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

【讨论】:

  • 感谢您的回答?你能告诉我应该如何检查创建新存根而不是使用缓存的存根吗?
【解决方案2】:

问:

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

【讨论】:

    【解决方案3】:

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

    开发人员创建 Web 服务存根并使用较新版本在他们的项目中构建它们的场景之一,而服务器类路径具有某些依赖 jar 文件的旧版本。我会推荐以下步骤来排除依赖版本不匹配的选项。

    1. 获取依赖关系树和失败的文件。你应该得到一个依赖 jar 文件的列表。 (具体检查负责在本地机器中创建 Request 和 Response 对象的 jar 文件)
    2. 比较 WebSphere 服务器的类路径并添加任何缺失的 jar。
    3. 如果 WebSphere 类路径中的所有依赖 jar 文件属于旧版本,请替换它们。

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

    【讨论】:

      【解决方案4】:

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

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

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

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

      【讨论】:

        猜你喜欢
        • 2015-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多