7

In the CXF's documentation it is said that the 2.7.x version requires the Woodstox jars not under the 4.2.0 version to be available in the classpath.

Can somebody, please, suggest Maven dependencies for Woodstox to work with CXF?

The main problem is when I try to use the cxf's client, an exception "Cannot create a secure XMLInputFactory" is raised. According to different forums (for example), it is possible to use the "org.apache.cxf.stax.allowInsecureParser" system property to solve the problem, but it seems not a good way. So that maven dependencies are the way to go...

Thanks in advance.

Dmitry
  • 3,028
  • 6
  • 44
  • 66
  • Why don't you want to update to Woodstox 4.2.0? It has same group and artifact ids as 4.0 and 4.1. – StaxMan Jun 04 '13 at 18:24
  • Yes, I've tried to add the woodstox-core-asl 4.2.0 maven dependency and also the woodstox stax2-api, but the "Cannot create a secure XMLInputFactory" exception is raised anyway – Dmitry Jun 05 '13 at 07:32
  • 2
    Is it possible that somehow multiple Stax implementations might be included as dependencies (like BEA's reference implementation, or Sun SJSXP explicitly added)? – StaxMan Jun 06 '13 at 01:56
  • Well, I think it is possible. Do you know how to exclude these dependencies or maybe how to set the preferred (Woodstox) implementation for cxf in a .pom file? – Dmitry Jun 06 '13 at 13:46
  • 3
    That would be CXF specific actually. But you can explicitly exclude inclusion of others in pom; first need to see if they are getting in (using "mvn dependency:tree"). Problem is that if CXF uses SPI style stax impl detection, order of precedence between choices in unspecified. But it may have specific overrides. – StaxMan Jun 10 '13 at 00:21

3 Answers3

6

Well, finally I've got a solution. First of all I'd like to thank StaxMan for a help.

My environment is: Weblogic 11g, CXF 2.7.5

The problem is WLS already contains implementations for StAX API and xml parsers that is why an application doesn't see the Woodstox parser when using CXF.

Here is the pom.xml:

        <!-- CXF -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
        </dependency>

and the main part -- the weblogic-application.xml located in the resources/META-INF/ :

    <prefer-application-packages>
        <package-name>com.ctc.wstx.*</package-name>
        <package-name>org.apache.*</package-name>
    </prefer-application-packages>

Be aware of the fact that if do so there may occure the "NoClassDefinition" errors. If so, please, add maven dependencies that contain missing classes.

Hope this helps somebody.

Dmitry
  • 3,028
  • 6
  • 44
  • 66
  • My friend, this is beautiful. Thanx a lot:) – Neron Jul 16 '13 at 06:32
  • And I think it is not an option for weblogic 10 – Neron Jul 16 '13 at 07:29
  • @Neron, I think there are still some packages in your WLS that brake the configuration. Please, refer to this http://stackoverflow.com/questions/12716673/override-jax-ws-version-used-by-weblogic-10-dynamic-wsdl-with-inline-schemas post. – Dmitry Jul 16 '13 at 09:32
  • I have added the necessary ones as u gave in your solution but it did not helped. This should not be this much painfull:( – Neron Jul 16 '13 at 10:16
  • It's a pity but with CXF it is always really hard to make something work properly other than basic examples. Some people adviced to exclude the 'javax.xml.*' packages (with the 'prefer-application-packages'). Did you try this? This approach is also given in the post above. – Dmitry Jul 16 '13 at 15:48
  • For a .war only solution in weblogic 10.3.6, I added the same prefer-application-packages element in the container-descriptor element in the the WEB-INF/weblogic.xml file (this means you don't have to create a .ear file unnecessarily). – Peter Hart Nov 07 '13 at 20:23
4

This worked for me without prefer-application-packages impl:

<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.xml.bind</groupId>
                    <artifactId>jaxb-impl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <!-- Jetty is needed if you're using the CXFServlet -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>${cxf.version}</version>
        </dependency>
Neron
  • 1,500
  • 7
  • 30
  • 52
3

The only way for now I can solve the problem is to add such lines in the spring's context:

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject">
        <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
            <property name="targetClass" value="java.lang.System" />
            <property name="targetMethod" value="getProperties" />
        </bean>
    </property>
    <property name="targetMethod" value="putAll" />
    <property name="arguments">
        <util:properties>
            <prop key="org.apache.cxf.stax.allowInsecureParser">true</prop>
        </util:properties>
    </property>
</bean>
Dmitry
  • 3,028
  • 6
  • 44
  • 66