Looking at the code, it looks like Aegis only reads mtom if mtom is enabled on the databinding. JAXB is different. It will always read MTOM, but only write mtom if mtom is enabled.

The simplest thing to do is when you create your AegisDatabinding object, call the setMtomEnabled(true) method or set that via a property in the spring config. That said, Aegis probably should behave like JAXB here and accept the message, but not produce one like it. Feel free to log a bug.

Dan


On Jul 17, 2008, at 3:54 AM, Marcin Gałązka wrote:

Hello

Is it possible to get JAX-WS + Aegis + MTOM working? So far I was unable to achieve such configuration. Example (as a client I used SoapUI 2.0.2):

WEB-INF/web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
        <servlet>
                <servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</ servlet-class>
                <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
                <servlet-name>CXFServlet</servlet-name>
                <url-pattern>/*</url-pattern>
        </servlet-mapping>
</web-app>


test.MtomService:

@WebService
public interface MtomService
{
public int addResource(@WebParam(name="resource") @XmlMimeType("application/octet-stream") DataHandler resource);
}


test.MtomServiceImpl:

@WebService (endpointInterface="test.MtomService")
public class MtomServiceImpl implements MtomService
{
        public int addResource(DataHandler resource)
        {
                try
                {
                        return resource.getInputStream().available();
                }
                catch (IOException e)
                {
                        return -1;
                }
        }
}


cxf.xml:

<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:soap="http://cxf.apache.org/bindings/soap"; xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd";>

        <import resource="classpath:META-INF/cxf/cxf.xml" />
        <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
        
<bean id="aegisDatabinding" class="org.apache.cxf.aegis.databinding.AegisDatabinding" scope="prototype"/>
        
<bean id="serviceFactory" class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean" scope="prototype">
                <property name="dataBinding" ref="aegisDatabinding"/>
        </bean>

        <bean id="testService" class="test.MtomServiceImpl"/>
        
<jaxws:server id="testServiceEndpoint" serviceBean="#testService" serviceClass="test.MtomServiceImpl" address="/TestService">
                <jaxws:serviceFactory>
                        <ref bean="serviceFactory"/>
                </jaxws:serviceFactory>
                <jaxws:binding>
                        <soap:soapBinding version="1.2"/>
                </jaxws:binding>
                <jaxws:properties>
                        <entry key="mtom-enabled" value="true"/>
                </jaxws:properties>
        </jaxws:server>
</beans>


Request:

MIME-Version: 1.0
Host: localhost:8080
Content-Length: 23944
User-Agent: Jakarta Commons-HttpClient/3.0.1
Content-Type: multipart/related; type="application/xop+xml"; start="<[EMAIL PROTECTED] >"; start-info="application/soap+xml; action=\"\""; boundary="---- =_Part_2_1187418.1216278505717"

------=_Part_2_1187418.1216278505717
Content-Type: application/xop+xml; charset=UTF-8; type="application/ soap+xml; action=\"addResource\""
Content-Transfer-Encoding: 8bit
Content-ID: <[EMAIL PROTECTED]>

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"; xmlns:test="http://test/";>
  <soap:Header/>
  <soap:Body>
     <test:addResource>
        <!--Optional:-->
<resource><inc:Include href="cid:870601276765" xmlns:inc="http://www.w3.org/2004/08/xop/include "/></resource>
     </test:addResource>
  </soap:Body>
</soap:Envelope>
------=_Part_2_1187418.1216278505717
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <870601276765>

<binary data here>

------=_Part_2_1187418.1216278505717--


Response:

HTTP/1.1 500 Internal Server Error
Date: Thu, 17 Jul 2008 07:08:26 GMT
Content-Length: 322
Connection: close
Content-Type: application/soap+xml;charset=UTF-8
X-Powered-By: Servlet 2.4; JBoss-4.0.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)/Tomcat-5.5
Server: Apache-Coyote/1.1

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap- envelope"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Sender</ soap:Value></soap:Code><soap:Reason><soap:Text xml:lang ="en">Unexpected element: {http://www.w3.org/2004/08/xop/ include}Include</soap:Text></soap:Reason></soap:Fault></soap:Body></ soap:Envelope>


An exception thrown on a server:

Caused by: org.apache.cxf.aegis.DatabindingException: Unexpected element: {http://www.w3.org/2004/08/xop/include}Include at org .apache.cxf.aegis.type.basic.Base64Type.readObject(Base64Type.java:74) at org .apache .cxf.aegis.type.mtom.AbstractXOPType.readObject(AbstractXOPType.java: 127) at org .apache .cxf .aegis.AegisXMLStreamDataReader.read(AegisXMLStreamDataReader.java:82) at org .apache .cxf .aegis.databinding.XMLStreamDataReader.read(XMLStreamDataReader.java: 47)
        ... 30 more


So it looks like CXF (Aegis) for some reason isn't prepared to handle MTOM (XOP) request. If I switch to the (default) JAXB binding everything works:

cxf.xml:

<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:soap="http://cxf.apache.org/bindings/soap";
        xsi:schemaLocation="
                http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
                http://cxf.apache.org/jaxws 
http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd ">

        <import resource="classpath:META-INF/cxf/cxf.xml" />
        <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
        
        <bean id="testService" class="test.MtomServiceImpl"/>
        
<jaxws:server id="testServiceEndpoint" serviceBean="#testService" serviceClass="test.MtomServiceImpl" address="/TestService">
                <jaxws:binding>
                        <soap:soapBinding version="1.2"/>
                </jaxws:binding>
                <jaxws:properties>
                        <entry key="mtom-enabled" value="true"/>
                </jaxws:properties>
        </jaxws:server>
</beans>


Request:

The same as above, just different id in _Part.


Response:

HTTP/1.1 200 OK
Date: Thu, 17 Jul 2008 07:12:33 GMT
Content-Length: 447
Content-Type: multipart/related; type="application/xop+xml"; boundary="----=_Part_0_16585987.1216278753892"; start="<[EMAIL PROTECTED] >"; start-info="application/soap+xml" X-Powered-By: Servlet 2.4; JBoss-4.0.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)/Tomcat-5.5
Server: Apache-Coyote/1.1

------=_Part_0_16585987.1216278753892
Content-Type: application/xop+xml; charset=UTF-8; type="application/ soap+xml";
Content-Transfer-Encoding: binary
Content-ID: <[EMAIL PROTECTED]>

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap- envelope"><soap:Body><ns2:addResourceResponse xmlns:ns2="http:// test/"><return>23188</return></ns2:addResourceResponse></soap:Body></ soap:Envelope>
------=_Part_0_16585987.1216278753892--


Do I need an additional configuration to use MTOM with Aegis?

CXF 2.1.1.

---
Daniel Kulp
[EMAIL PROTECTED]
http://www.dankulp.com/blog




Reply via email to