Search code examples
springweb-servicesspring-mvccxfjax-ws

Is there a way to get CXF to ignore maxElementCount when communicating with a web service?


I'm using SPring 3.2.11.RELEASE and CXF 2.7.18. I have htis in my SPring application context file, necessary for communicating with a web service ...

    <jaxws:client id="myWebServiceClient"
            serviceClass="org.mainco.bsorg.MyWebService"
            address="${wsdl.url}"
    />

    <cxf:bus>
            <cxf:properties>
            <entry key="org.apache.cxf.stax.maxElementCount" value="10000000"/>
            </cxf:properties>
    </cxf:bus>

In my Maven pom.xml file, I have this configured for the plugin ...

                    <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>jaxws-maven-plugin</artifactId>
                            <version>2.4.1</version>
                            <executions>
                                    <execution>
                                            <goals>
                                                    <goal>wsimport</goal>
                                            </goals>
                                            <configuration>
                                                    <target>2.1</target>
                                                    <wsdlDirectory>${basedir}/src/wsdl</wsdlDirectory>
                                                    <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
                                                    <packageName>org.mainco.bsorg</packageName>
                                                    <vmArgs>
                                                            <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                                                    </vmArgs>
                                            </configuration>
                                    </execution>
                            </executions>
                    </plugin>

Unfrotunately I get this error when I execute a particular call against my web service ...

07:16:26,088 WARNING [org.apache.cxf.phase.PhaseInterceptorChain] (org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-2) Interceptor for {http://mainco.org/bsorg/}MyWebServiceService#{http://mainco.org/bsorg/}searchOrgs has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault: Unmarshalling Error: Maximum Number of Child Elements limit (50000) Exceeded
        at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:907) [cxf-rt-databinding-jaxb-2.7.15.jar:2.7.15]
        at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:711) [cxf-rt-databinding-jaxb-2.7.15.jar:2.7.15]
        at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:172) [cxf-rt-databinding-jaxb-2.7.15.jar:2.7.15]
        at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:107) [cxf-api-2.7.15.jar:2.7.15]
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) [cxf-api-2.7.15.jar:2.7.15]
        at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:849) [cxf-api-2.7.15.jar:2.7.15]
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1626) [cxf-rt-transports-http-2.7.15.jar:2.7.15]
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1515) [cxf-rt-transports-http-2.7.15.jar:2.7.15]
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1317) [cxf-rt-transports-http-2.7.15.jar:2.7.15]
        at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) [cxf-api-2.7.15.jar:2.7.15]
        at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:632) [cxf-rt-transports-http-2.7.15.jar:2.7.15]
        at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) [cxf-api-2.7.15.jar:2.7.15]
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272) [cxf-api-2.7.15.jar:2.7.15]
        at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:572) [cxf-api-2.7.15.jar:2.7.15]

If I change my maxElementCount value from "10000000" to "1000000", I get the above error with "Maximum Number of Child Elements limit (1000000) Exceeded". Is there a way I can get CXF to ignore the maxElementCount restriction altogether? It is a pain having to fiddle with a max value. I'm open to using natoher technique for configuring a web service in Spring, but if you suggest one, please provide the Maven and Spring configurations I would need.


Solution

  • Have you tried setting the org.apache.cxf.stax.maxChildElements property?

    It seems you are trying to override the wrong property maxElementCount instead of maxChildElements.

    See the docs here.