Apache CXF SOAP - handling MTOM attachment: Response was of unexpected text/html ContentType
<p>I've got a SOAP client generated using Apache CXF and there is a problem with handling MTOM attachment:  </p>

<pre><code>WARNING: Interceptor for {http://someaddress.com.au/soap2/}
SomeAddressPortTypeService#{http://someaddress.com.au/soap2/}
SomeFunction has thrown exception, unwinding now 
org.apache.cxf.interceptor.Fault: Response was of unexpected text/html ContentType.    
Incoming portion of HTML stream: &lt;?xml version="1.0" encoding="UTF-8"?&gt;
....etc
</code></pre>

<p>Below is my pom.xml</p>

<pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
    http://maven.apache.org/maven-v4_0_0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;au.com.someid&lt;/groupId&gt;
    &lt;artifactId&gt;SomeSOAPClient&lt;/artifactId&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;name&gt;SomeSOAPClient&lt;/name&gt;
    &lt;url&gt;http://maven.apache.org&lt;/url&gt;
    &lt;properties&gt;
        &lt;junit.version&gt;4.12&lt;/junit.version&gt;
        &lt;cxf.version&gt;3.0.4&lt;/cxf.version&gt;
        &lt;spring.version&gt;4.1.7.RELEASE&lt;/spring.version&gt;
    &lt;/properties&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
            &lt;version&gt;${spring.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
            &lt;version&gt;${spring.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;junit&lt;/groupId&gt;
            &lt;artifactId&gt;junit&lt;/artifactId&gt;
            &lt;version&gt;${junit.version}&lt;/version&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
            &lt;artifactId&gt;cxf-rt-frontend-jaxws&lt;/artifactId&gt;
            &lt;version&gt;${cxf.version}&lt;/version&gt;
         &lt;/dependency&gt;
         &lt;dependency&gt;
            &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
            &lt;artifactId&gt;cxf-rt-transports-http&lt;/artifactId&gt;
            &lt;version&gt;${cxf.version}&lt;/version&gt;
         &lt;/dependency&gt;
     &lt;/dependencies&gt;

     &lt;build&gt;
         &lt;plugins&gt;
             &lt;plugin&gt;
                 &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                 &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                 &lt;configuration&gt;
                    &lt;source&gt;1.8&lt;/source&gt;
                    &lt;target&gt;1.8&lt;/target&gt;
                    &lt;version&gt;3.5.1&lt;/version&gt;
                 &lt;/configuration&gt;
             &lt;/plugin&gt;

             &lt;plugin&gt;
                 &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
                 &lt;configuration&gt;
                     &lt;descriptorRefs&gt;
                         &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
                     &lt;/descriptorRefs&gt;
                 &lt;/configuration&gt;
             &lt;/plugin&gt;

             &lt;plugin&gt;
                 &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
                 &lt;artifactId&gt;cxf-codegen-plugin&lt;/artifactId&gt;
                 &lt;version&gt;${cxf.version}&lt;/version&gt;
                 &lt;executions&gt;
                     &lt;execution&gt;
                     &lt;id&gt;generate-sources&lt;/id&gt;
                     &lt;phase&gt;generate-sources&lt;/phase&gt;
                     &lt;configuration&gt;
                         &lt;sourceRoot&gt;src/main/java-generated&lt;/sourceRoot&gt;
                             &lt;wsdlOptions&gt;
                                 &lt;wsdlOption&gt;
                            &lt;wsdl&gt;http://localhost:4001/someAddress.WSDL&lt;/wsdl&gt;
                                      &lt;extraargs&gt;
                                          &lt;extraarg&gt;-autoNameResolution&lt;/extraarg&gt;
                                     &lt;/extraargs&gt;
                                 &lt;/wsdlOption&gt;
                             &lt;/wsdlOptions&gt;
                        &lt;/configuration&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;wsdl2java&lt;/goal&gt;
                        &lt;/goals&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;

        &lt;/plugins&gt;
    &lt;/build&gt;

&lt;/project&gt;
</code></pre>

<p>Below is my beans.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:jaxws="http://cxf.apache.org/jaxws" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd
    http://cxf.apache.org/jaxws 
    http://cxf.apache.org/schemas/jaxws.xsd
    "&gt;
&lt;import resource="classpath:META-INF/cxf/cxf.xml"/&gt;
&lt;context:property-placeholder/&gt;
&lt;context:annotation-config/&gt;
&lt;bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"/&gt;

&lt;jaxws:client id="soapClientBean"
    address="http://localhost:4001"
    serviceClass="some.package.SomePortType"&gt;
&lt;/jaxws:client&gt;

&lt;context:component-scan base-package="some.package, 
    another.package"/&gt;      
</code></pre>

<p></p>

<p>The client class is defined like: </p>

<pre><code>@Component
public class SOAPClient {

    @Autowired
    private SomePortType soapClientBean;

    public String doStuff(String arg, ...){ ... }
</code></pre>

<p>and finally the test is similar to below:</p>

<pre><code>@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:beans.xml"})
public class SOAPClientTest {

@Autowired
SOAPClient soapClient;

@Test
public void testDoStuff(){
    assertNotNull(soapClient.doStuff("blah"));
}
</code></pre>

<p>My understanding that it should be possible to add an interceptor on the CXF client that would reset the Message.CONTENT_TYPE property but I don't know how to do that.  </p>

<p>Or is there another way?</p>

<p>Could someone please help? Thanks!</p>

<p><strong>UPDATE:</strong></p>

<p>I've also tried enabling MTOM as below but that had not effect:</p>

<pre><code>Binding binding = ((BindingProvider) soapClientBean).getBinding();
((SOAPBinding)binding).setMTOMEnabled(true);
</code></pre>

<p><strong>UPDATE2:</strong></p>

<p>Also, according to <a href="http://cxf.apache.org/docs/simple-frontend-configuration.html" rel="nofollow">http://cxf.apache.org/docs/simple-frontend-configuration.html</a>, below configuration should enable MTOM as well, but it has no effect either (added namespaces &amp; and redefined the client bean as below): </p>

<pre><code>xmlns:simple="http://cxf.apache.org/simple"
xmlns:soap="http://cxf.apache.org/bindings/soap"


 &lt;simple:client id="soapClientBean"
    address="http://localhost:4001"
    serviceClass="some.package.SomePortType"&gt;
    &lt;simple:binding&gt;
        &lt;soap:soapBinding mtomEnabled="true" version="1.2"/&gt;    
    &lt;/simple:binding&gt;
&lt;/simple:client&gt;
</code></pre>