You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jim Talbut <jt...@spudsoft.co.uk> on 2012/06/11 06:52:29 UTC

Does optional MTOM really work?

Hi,

I'm trying to get optional MTOM working with CXF 2.6.0, but when I send 
in a plain XML request I always get an MTOM response.

I have a test that has two client endpoints (one MTOM enabled and one 
not) and two server endpoints (one MTOM enabled and one not).
The server MTOM endpoint has a policy specified in the Spring file:
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:jaxws="http://cxf.apache.org/jaxws"
        xmlns:wsp="http://www.w3.org/2006/07/ws-policy"
xmlns:mtom="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" 

        xmlns:p="http://cxf.apache.org/policy"
...
   <jaxws:endpoint id="targetRealMtom" implementor="#realImplementation" 
address="http://0.0.0.0:10010/TestMtom" bus="testTracking" >
     <jaxws:properties>
       <entry key="mtom-enabled" value="true"/>
     </jaxws:properties>
     <jaxws:features>
       <p:policies>
         <wsp:Policy>
           <mtom:OptimizedMimeSerialization wsp:Optional="true" />
         </wsp:Policy>
       </p:policies>
     </jaxws:features>
   </jaxws:endpoint>

All four endpoints use the same WSDL file, so the only one that knows 
anything about the policy is the server MTOM endpoint.

What I need to happen is:
Client no MTOM = Server no MTOM => XML Request, XML Response
Client MTOM = Server no MTOM => MTOM Request, XML Response
Client MTOM = Server MTOM => MTOM Request, MTOM Response
Client no MTOM = Server MTOM => XML Request, XML Response
But in the last case I am always getting an MTOM respnose.

Is there a way to make this work?
It's important that the client without MTOM do nothing clever at all (in 
production it'll have clients using the old Microsoft SOAP Toolkit from 
ASP (not .Net).

Thanks.

Jim

Re: Does optional MTOM really work?

Posted by James Talbut <jt...@spudsoft.co.uk>.
Thanks Dan, I take your point, and having a separate endpoint is easy enough, but I'm confused.
Isn't the code you present what the MTOMPolicyInterceptor does?

This code path is called in my request:

                } else {
                    // set mtom enabled and assert the policy if we find an mtom request
                    String contentType = (String)message.getExchange().getInMessage()
                        .get(Message.CONTENT_TYPE);
                    if (contentType != null && contentType.contains("type=\"application/xop+xml\"")) {
                        ai.setAsserted(true);
                        message.put(Message.MTOM_ENABLED, Boolean.TRUE);
                    }
                }

But it doesn't seem to achieve anything - the only thing that affects whether an MTOM response is generated is the mtom-enabled property on the endpoint.

Jim

On Mon, Jun 11, 2012 at 03:22:23PM -0400, Daniel Kulp wrote:
> 
> It's more or less working as designed.   The "optional" flag really is to 
> allow the framework to decide whether it's best for it to do MTOM or not.  
> With CXF, since we steam everything, it is much better for us to just turn 
> on MTOM if its marked optional.   There are a lot of use cases where an 
> incoming message wouldn't use MTOM (nothing binary there), but the response 
> message should be MTOM.   
> 
> You can easily write a simple interceptor that could turn it off in various 
> cases though.  If it runs before the AttachementOutInterceptor, you can do 
> something like:
> 
> Message m = message.getExchange().getInMessage();
> boolean useMtom = ... //detect mtom from in
> message.put("mtom-enabled", "false");
> 
> and the should do it.
> 
> 
> Dan
> 
> 
> 
> 
> 
> 
> On Monday, June 11, 2012 05:52:29 AM Jim Talbut wrote:
> > Hi,
> > 
> > I'm trying to get optional MTOM working with CXF 2.6.0, but when I send
> > in a plain XML request I always get an MTOM response.
> > 
> > I have a test that has two client endpoints (one MTOM enabled and one
> > not) and two server endpoints (one MTOM enabled and one not).
> > The server MTOM endpoint has a policy specified in the Spring file:
> > <beans xmlns="http://www.springframework.org/schema/beans"
> >         xmlns:jaxws="http://cxf.apache.org/jaxws"
> >         xmlns:wsp="http://www.w3.org/2006/07/ws-policy"
> > xmlns:mtom="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeseri
> > alization"
> > 
> >         xmlns:p="http://cxf.apache.org/policy"
> > ...
> >    <jaxws:endpoint id="targetRealMtom" implementor="#realImplementation"
> > address="http://0.0.0.0:10010/TestMtom" bus="testTracking" >
> >      <jaxws:properties>
> >        <entry key="mtom-enabled" value="true"/>
> >      </jaxws:properties>
> >      <jaxws:features>
> >        <p:policies>
> >          <wsp:Policy>
> >            <mtom:OptimizedMimeSerialization wsp:Optional="true" />
> >          </wsp:Policy>
> >        </p:policies>
> >      </jaxws:features>
> >    </jaxws:endpoint>
> > 
> > All four endpoints use the same WSDL file, so the only one that knows
> > anything about the policy is the server MTOM endpoint.
> > 
> > What I need to happen is:
> > Client no MTOM = Server no MTOM => XML Request, XML Response
> > Client MTOM = Server no MTOM => MTOM Request, XML Response
> > Client MTOM = Server MTOM => MTOM Request, MTOM Response
> > Client no MTOM = Server MTOM => XML Request, XML Response
> > But in the last case I am always getting an MTOM respnose.
> > 
> > Is there a way to make this work?
> > It's important that the client without MTOM do nothing clever at all (in
> > production it'll have clients using the old Microsoft SOAP Toolkit from
> > ASP (not .Net).
> > 
> > Thanks.
> > 
> > Jim

Re: Does optional MTOM really work?

Posted by Daniel Kulp <dk...@apache.org>.
It's more or less working as designed.   The "optional" flag really is to 
allow the framework to decide whether it's best for it to do MTOM or not.  
With CXF, since we steam everything, it is much better for us to just turn 
on MTOM if its marked optional.   There are a lot of use cases where an 
incoming message wouldn't use MTOM (nothing binary there), but the response 
message should be MTOM.   

You can easily write a simple interceptor that could turn it off in various 
cases though.  If it runs before the AttachementOutInterceptor, you can do 
something like:

Message m = message.getExchange().getInMessage();
boolean useMtom = ... //detect mtom from in
message.put("mtom-enabled", "false");

and the should do it.


Dan






On Monday, June 11, 2012 05:52:29 AM Jim Talbut wrote:
> Hi,
> 
> I'm trying to get optional MTOM working with CXF 2.6.0, but when I send
> in a plain XML request I always get an MTOM response.
> 
> I have a test that has two client endpoints (one MTOM enabled and one
> not) and two server endpoints (one MTOM enabled and one not).
> The server MTOM endpoint has a policy specified in the Spring file:
> <beans xmlns="http://www.springframework.org/schema/beans"
>         xmlns:jaxws="http://cxf.apache.org/jaxws"
>         xmlns:wsp="http://www.w3.org/2006/07/ws-policy"
> xmlns:mtom="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeseri
> alization"
> 
>         xmlns:p="http://cxf.apache.org/policy"
> ...
>    <jaxws:endpoint id="targetRealMtom" implementor="#realImplementation"
> address="http://0.0.0.0:10010/TestMtom" bus="testTracking" >
>      <jaxws:properties>
>        <entry key="mtom-enabled" value="true"/>
>      </jaxws:properties>
>      <jaxws:features>
>        <p:policies>
>          <wsp:Policy>
>            <mtom:OptimizedMimeSerialization wsp:Optional="true" />
>          </wsp:Policy>
>        </p:policies>
>      </jaxws:features>
>    </jaxws:endpoint>
> 
> All four endpoints use the same WSDL file, so the only one that knows
> anything about the policy is the server MTOM endpoint.
> 
> What I need to happen is:
> Client no MTOM = Server no MTOM => XML Request, XML Response
> Client MTOM = Server no MTOM => MTOM Request, XML Response
> Client MTOM = Server MTOM => MTOM Request, MTOM Response
> Client no MTOM = Server MTOM => XML Request, XML Response
> But in the last case I am always getting an MTOM respnose.
> 
> Is there a way to make this work?
> It's important that the client without MTOM do nothing clever at all (in
> production it'll have clients using the old Microsoft SOAP Toolkit from
> ASP (not .Net).
> 
> Thanks.
> 
> Jim