当前位置: 代码迷 >> Web前端 >> liferay axis 外部WebService调用变换ClassCastExcep
  详细解决方案

liferay axis 外部WebService调用变换ClassCastExcep

热度:661   发布时间:2012-08-14 10:39:58.0
liferay axis 外部WebService调用转换ClassCastExcep

When some code within a portlet consumes non-Liferay web services with the help of the AXIS package, an unexpected error happens.
This error is related to the invocation of the com.liferay.util.axis.SimpleHTTPSender.

The same code will not produce this error if it is running outside of the Liferay portlet environment.

The cause of the error is a silent assumption that every call to AXIS is about Liferay services and in this case com.liferay.util.axis.SimpleHTTPSender knows what to do.
But in the situation when the AXIS is used to consume non-Liferay web services, this invocation is wrong.

The workaround:
open a jar file: tomcat/webapps/ROOT/WEB-INF/lib/util-java.jar
delete from this jar: client-config.wsdd
(In this file there is a line that instructs to invoke the SimpleHTTPSender)
save this jar back as: tomcat/webapps/ROOT/WEB-INF/lib/util-java.jar

Check if this util-java.jar file is included in the YourPortlet/WEB-INF/lib
If so, do the same thing. (Be aware that util-java.jar is created in each build)

Although the problem has surfaced many times without good explanation, there is at least one place where it was described: http://issues.liferay.com/browse/LEP-1190, August 26, 2006 by Javier Cámara.

Thank you, Javier!
----------------------------
If you expected that this is it... you are almost right. One more thing: working with web services within the web application causes more than one ClassLoader to work on jars. Duplication of the axis.jar (one is in the portlet/WEB-INF/lib and another is in the tomcat/webapps/ROOT/WEB-INF/lib) tricks the Class Loaders into the Exception:

ClassCastException: org.apache.axis.attachments.AttachmentsImpl cannot be cast to org.apache.axis.attachments.Attachments

Delete this one: tomcat/webapps/ROOT/WEB-INF/lib/axis.jar
-----------------------------
Soon after solving this one I found out the message by Raj K. with the same solution: http://www.liferay.com/community/forums/-/message_boards/message/5677416

Thank you, Raj!

Jeff (Yefim)

?

?

?

?

?

?

?

?

Hi,

After months of trial and error, we were able to fix the issue.

If you are using a webservice in your project and if you are generating the webservice client jar from your eclipse workspace, make sure you are using the axis jar provided by liferay/lib/ and not the default eclipse axis jar. Ideally speaking you will require only the following jars from tomcat/lib and these are the ones that should be available in build path for client generation. Remove all the eclipse jars before exporting the jar.

axis.jar
jbossws-native-jaxrpc.jar
wsdl4j.jar

For deployment,
Delete the axis jar from your portlet as you have already one in lib\ext. Have the client jar either in lib/ext if more than one portlets are using it or have it within the app war accordingly, dont have multiple instances of same jar as it causes class cast.

Tried the above and it worked for me.

Thanks & Regards,
Venkat.S
kennzeichnen

s

?

?

  相关解决方案