简体   繁体   English

Axis2命名空间/类路径问题

[英]Axis2 Namespace/Classpath Issue

I work on a web application that calls multiple web service clients from within its code. 我在一个Web应用程序上工作,从其代码中调用多个Web服务客户端。

Each web service has some common namespaces, however I am currently mapping these namespaces to different packages when I generate each client 每个Web服务都有一些常见的命名空间,但是当我生成每个客户端时,我正在将这些命名空间映射到不同的包

eg 例如

Web Service 1's namespace1 -> com.company.webservice.client1.service Web Service 1的namespace1 - > com.company.webservice.client1.service

Web Service 2's namespace1 -> com.company.webservice.client2.service Web Service 2的namespace1 - > com.company.webservice.client2.service

Where namespace1 refers to the same namespace URL. 其中namespace1引用相同的命名空间URL。

Using Wsdl2Java's namespace2package option: 使用Wsdl2Java的namespace2package选项:

// Web Service Client 1's namespace parameter
--namespace2package http://www.multispeak.org/Version_3.0=com.company.webservice.client1.service

// Web Service Client 2's namespace parameter
--namespace2package http://www.multispeak.org/Version_3.0=com.company.webservice.client2.service

I can generate web service client code for these services without issue and I can call each client fine on their own, so long as only one of the generated client jars is on the classpath for the given web service call. 我可以毫无问题地为这些服务生成Web服务客户端代码,只要生成的客户端jar中只有一个在给定Web服务调用的类路径上,我就可以自己调用每个客户端。 However, if I place both web service client jars on the classpath, only one of the web service clients will work (the one where its respective client jar is first on the class path). 但是,如果我将两个Web服务客户端jar放在类路径上,则只有一个Web服务客户端可以工作(其各自的客户端jar首先在类路径上)。

The other web service client fails when trying to call it, with the following exception: 尝试调用时,其他Web服务客户端失败,但以下情况除外:

java.lang.ClassCastException: com.company.webservice.client1.service.impl.GetAllMetersResponseDocumentImpl cannot be cast to com.company.webservice.client2.service.GetAllMetersResponseDocument java.lang.ClassCastException:com.company.webservice.client1.service.impl.GetAllMetersResponseDocumentImpl无法强制转换为com.company.webservice.client2.service.GetAllMetersResponseDocument

I've obfuscated some of the actual values above. 我已经混淆了上面的一些实际值。

So, the issue seems to be regarding how Axis2/XMLBeans looks up the appropriate class to match the given XML to parse from. 因此,问题似乎是关于Axis2 / XMLBeans如何查找适当的类以匹配给定的XML来解析。

I can change the namespace mappings so that they match each other and it works fine after that. 我可以更改命名空间映射,以便它们相互匹配,之后它可以正常工作。 However, the downside to that is that I have multiple web service client jars containing the same generated code in the same package structure, whereby these classes will only be instantiated from the models from the first client jar it finds on the classpath. 但是,缺点是我在同一个包结构中有多个包含相同生成代码的Web服务客户端jar,这些类只能从它在类路径中找到的第一个客户端jar中的模型中实例化。

Is there a way of doing this so that I can keep the different namespaces for each web service client jar? 有没有办法这样做,以便我可以为每个Web服务客户端jar保留不同的命名空间?

Or am I simply going to be forced to have each namespace mapped to the same package for every client that uses that namespace? 或者我只是被迫将每个命名空间映射到使用该命名空间的每个客户端的同一个包?

Hopefully the issue makes sense, but if I need to provide anything else that would assist, please let me know and I will expand this question with further details, but hopefully someone with knowledge of Axis2/XMLBeans/web service client generation using Wsdl2Java should be able to answer this without much further info. 希望这个问题有意义,但是如果我需要提供其他任何有用的东西,请告诉我,我将进一步详细说明这个问题,但希望有使用Wsdl2Java的Axis2 / XMLBeans / web服务客户端生成知识的人应该是能够在没有更多信息的情况下回答这个

UPDATE 1: I finally gave in and just made all of the namespace mappings point to the same package rather than bespoke per web service client and took the hit of having multiple copies of the same class in various JARs on the classpath. 更新1:我终于放弃了,只是使所有的命名空间映射指向同一个包而不是每个Web服务客户端的定制,并且在类路径上的各个JAR中获得了同一个类的多个副本。 Not as elegant as I would have liked, but at least it works. 不像我希望的那样优雅,但至少它有效。

If anyone can come up with a better solution that allows me to use bespoke copies in each client instead, please do let me know. 如果有人能想出一个更好的解决方案,允许我在每个客户端使用定制副本,请告诉我。

UPDATE 2: This approach equally does not work as the two web services, despite using the same namespace, produce different versions of the namespace's models which now causes compile time errors dependent on classpath order. 更新2:这种方法同样不起作用,因为尽管使用相同的命名空间,两个Web服务产生不同版本的命名空间模型,现在导致编译时错误依赖于类路径顺序。 So... Back to square one... 那么......回到原点......

I have the feeling you have two versions of the GetAllMetersResponseDocument in each jar. 我觉得你在每个jar中都有两个版本的GetAllMetersResponseDocument。 What is happening is that it is loading the interface from the opposite jar file which ends up in Class cast exception. 发生的事情是它从相反的jar文件加载接口,最终出现在类转换异常中。 I may be wrong. 我可能错了。

This is the reason why it works when you have one of the jars loaded. 这就是为什么当你加载了一个罐子时它可以工作的原因。

There is also this option where you can have Classloader isolation, resulting in two different classloaders for the two jars you can again end up with two objects of the same type that can not be casted to each other. 还有这个选项,你可以让Classloader隔离,导致两个不同的类加载器,你可以再次使用两个相同类型的对象,这两个对象无法相互转换。

UDATE I actualy just checked if axis2 has classloader isolation defined by default and it does. UDATE我实际上只检查了axis2是否默认定义了类加载器隔离,它确实如此。 https://axis.apache.org/axis2/java/core/faq.html read Class Loading Issues https://axis.apache.org/axis2/java/core/faq.html阅读课程加载问题

I believe also reading service and module isolation from this article will help you. 我相信本文中的阅读服务和模块隔离也会对您有所帮助。 https://www.developer.com/open/article.php/10930_3589126_2/Avoiding-Mistakes-Made-Using-Axis2.htm https://www.developer.com/open/article.php/10930_3589126_2/Avoiding-Mistakes-Made-Using-Axis2.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM