Search code examples
javaspringsoapweblogicsaaj

com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl cannot be cast to javax.xml.soap.MessageFactory


I'm using WebLgic have the following saaj soap message factory. I've tried leaving off the messageFactory and just the soapVersion and vice Versa. I've also tried the different messageFactory Impl beans that are commented out. I'm still getting the error in the title. Why is t trying to use version 1.1?

<bean id="saajMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
    <property name="messageFactory">
        <bean class="com.sun.xml.messaging.saaj.soap.MessageFactoryImpl" 
            /> 
        <!-- <bean class="com.sun.xml.messaging.saaj.soap.ver1_2.SOAPMessageFactory1_2Impl" 
            /> -->
        <!-- <bean class="weblogic.xml.saaj.MessageFactoryImpl"/> -->
    </property>
    <property name="soapVersion">
        <util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12" />
    </property>
</bean>

Error:

SAAJ MessageFactory: Unable to create message factory for SOAP: com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl cannot be cast to javax.xml.soap.MessageFactory; nested exception is javax.xml.soap.SOAPException: Unable to create message factory for SOAP: com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl cannot be cast to javax.xml.soap.MessageFactory
            at org.springframework.ws.support.DefaultStrategiesHelper.instantiateBean(DefaultStrategiesHelper.java:188)
            at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategies(DefaultStrategiesHelper.java:134)
            at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategy(DefaultStrategiesHelper.java:219)
            at org.springframework.ws.support.DefaultStrategiesHelper.getDefaultStrategy(DefaultStrategiesHelper.java:203)
            at org.springframework.ws.client.core.WebServiceTemplate.initMessageFactory(WebServiceTemplate.java:310)

pom file:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.messaging.saaj</groupId>
    <artifactId>saaj-impl</artifactId>
    <version>1.3.15</version>
</dependency>
<dependency>
    <groupId>javax.xml.soap</groupId>
    <artifactId>saaj-api</artifactId>
    <version>1.3.5</version>
</dependency>

Weblogic.xml:

<prefer-application-packages>
    <package-name>javax.xml.soap.*</package-name>
    <package-name>javax.xml.ws.*</package-name>
    <package-name>com.sun.xml.messsaging.saaj.*</package-name>
</prefer-application-packages> 

I should also add that I tried setting various this JVM argument with various options: -Djavax.xml.soap.MessageFactory=weblogic.xml.saaj.MessageFactoryImpl such as com.sun.xml.messaging.saaj.soap.ver1_2.SOAPMessageFactory1_2Impl. The error message now reflects the new Impl class, but I still can't get around the error.


Solution

  • I'm not sure exactly what ended up fixing this issue, but I was also getting some other errors as I tried different things, and I finally got everything working as specified in this post: java.lang.NoClassDefFoundError: org/apache/cxf/jaxrs/impl/UriBuilderImpl. I ended up removing those pom file entries above.

    One thing I did have to do was to download a new version of Maven as the one that came in my VM was giving me problems.