4

Exact problem: I had an application which was running in Windows 2003 (jre 1.5) Now it has been migrated to Windows 2012 (jre 1.8) server. While doing that below exception occurs,

Caller.main: com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl cannot be cast to com.sun.xml.messaging.saaj.soap.MessageImpl

Old server use jre 1.5 and the new server use the newer 1.8. In jre 1.5 we have the saaj jars separately.

From java 6 the saaj implementation is provided in jre itself and we don’t need a separate jar for this. Because of this I get classcast exception. I want to fix this by forcing the classpath to take the saaj jars from outside instead of the one in the jre itself.

anacron
  • 6,443
  • 2
  • 26
  • 31
  • first, can you compile your own `java.lang.String`? – holi-java Jun 27 '17 at 07:21
  • 1
    @Eugene I don't want to make any code level changes like changing the import. I want to override it via the command line call using options. – Aravinthsamy Sekar Jun 27 '17 at 07:26
  • @holi-java I've mentioned String library as an example only. – Aravinthsamy Sekar Jun 27 '17 at 07:26
  • @IdioticAravinth you can't declare class which its package starts with `java`. they can't be compiled. – holi-java Jun 27 '17 at 07:27
  • 1
    @IdioticAravinth, now that you have mentioned the exact problem, you can probably remove the Example of `java.lang.String` from the question. – anacron Jun 27 '17 at 07:55
  • Basically you want to replace a class defined on java.lang. There's a question about this: https://stackoverflow.com/questions/18285454/replacing-java-class – Danilo M. Oliveira Jun 27 '17 at 07:56
  • As said by @anacron, you should replace `String` example by your concrete case, as it is a very bad introduction to your question (it makes it look like you are trying to do something much more dirty than it actually is). It would be worth mentioning what is the application server you are trying to use to deploy your app (some JEE server, I assume), as there might be specific solutions for it. – Didier L Jun 27 '17 at 08:27
  • @anacron removed the `java.lang.String` example from question – Aravinthsamy Sekar Jun 27 '17 at 08:53

2 Answers2

3

Well... I had a problem in weblogic and had to change the default implementation of SAAJ (the default implementation was broken!)

To achieve that in weblogic I added this to the command line that launches weblogic:

-Djavax.xml.soap.MessageFactory=com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl

So, to you, it should be something like:

-Djavax.xml.soap.MessageFactory=com.sun.xml.messaging.saaj.soap.MessageFactoryImpl

It should work. This way you tell the JVM which will be the default Factory for SAAJ messages.

PS: Well, to be honest, they're more ways to change this in weblogic withouth touching the launch script and I ended changing the code and instanciating manually the MessageFactoryImpl version which wasn't broken. I found that -Djavax.xml.soap.MessageFactory fixed my problem but I was not allowed change production server's launch script.

inigoD
  • 1,681
  • 14
  • 26
0

Finally I've found a solution and its working. Using the java option -Xbootclasspath we can make this happen.

Solution:

java -Xbootclasspath/p:.\jaxrpc16\saaj-api.jar;.\jaxrpc16\saaj-impl.jar -classpath <myClasses> <myMainClass>

Refer: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html

P.S: Need to do more research on this to make sure whether this option is safe and secure to use.