在不同环境中投放ElementNSImpl的问题 [英] Issues casting ElementNSImpl in different environments

查看:104
本文介绍了在不同环境中投放ElementNSImpl的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Java + Spring Web客户端,该客户端基于我正在联系的服务提供的模式来接收XML并将其解组为自动生成的类.

I'm building a Java + Spring web client that receives an XML and unmarshalls it into auto-generated classes, based on a schema provided by the service I'm contacting.

自动生成的代码包含一个返回一个 Element 对象的getter.为了处理该对象,我将其强制转换为 ElementNSImpl .

The auto-generated code contains a getter that returns an Element object. To handle this object I cast it as ElementNSImpl.

public Element getThing() {
     return thing;
}


ElementNSImpl element = (ElementNSImpl) obj.getThing();
element.doSomething();

但是,我有两个可用的类 ElementNSImpl 来源:

However, I have two available sources for the class ElementNSImpl:

com.sun.org.apache.xerces.internal.dom.ElementNSImpl

org.apache.xerces.dom.ElementNSImpl

我也有两个环境(测试和生产).测试机器运行CentOS Linux 7和OpenJDK 1.8.0_161.生产机器运行SUSE Linux Enterprise Server 11 SP4和Oracle JDK.

I also have two environments (testing and production). The testing machine runs CentOS Linux 7 and OpenJDK 1.8.0_161. The production machine runs SUSE Linux Enterprise Server 11 SP4 and Oracle JDK.

我遇到的问题是,当我在测试环境中运行代码时,出现以下异常:

The issue I'm having is that when I ran my code in the testing environment I got the following exception:

com.sun.org.apache.xerces.internal.dom.ElementNSImpl cannot be cast to org.apache.xerces.dom.ElementNSImpl

因此,我修改了类以导入 com.sun.org.apache.xerces.internal.dom.ElementNSImpl 而不是 org.apache.xerces.dom.ElementNSImpl >voilà,它开始起作用了!然后,我将相同的JAR上传到生产环境中,但出现以下异常:

Therefore, I modified my class to import com.sun.org.apache.xerces.internal.dom.ElementNSImpl instead of org.apache.xerces.dom.ElementNSImpland voilà, it started working! Then I uploaded the same JAR to the production environment and I got the following exception:

org.apache.xerces.dom.ElementNSImpl cannot be cast to com.sun.org.apache.xerces.internal.dom.ElementNSImpl

似乎每个程序都以不同的方式解组XML,甚至认为这两个代码是完全相同的.

It seems that each program is unmarshalling the XMLs differently, even thought both codes are exactly the same.

我还必须告知正在联系的测试服务器和生产服务器不同.他们应该是相同的,并且行为方式相同(根据他们的支持小组).仅适用于不同的数据库.

I must also inform that both test and production servers that are being contacted are not the same. They are supposed to be identical and behave the same way (according to their support team). Only with different databases.

此问题可能与我的申请有关吗?还是与我从服务器获取的文件有关?使用OpenJDK可以吗?

Could this issue be related to my application? Or maybe it is something related to the file I get from the server? Could it be something with OpenJDK?

推荐答案

正如@lexicore指出的那样,我不需要 ElementNSImpl .只需将目标对象更改为 Element 并删除演员表即可解决此问题.

As @lexicore pointed out, I didn't need ElementNSImpl. Simply changing the target object to Element and removing the cast solved the issue.

我仍然想了解那里发生了什么.

I still would like to understand what happened there.

这篇关于在不同环境中投放ElementNSImpl的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆