Hello everyone, I have found a potential interoperability issue with the CXF working with the WCF (Windows Communication Foundation).
In order to create the CXF MTOM enabled Web-service, that is going to be automatically recognized by the Microsoft Visual Studio IDE (2008,2010..) and .NET/WCF clients, one would need to define and use the WS-MTOMPolicy (see http://www.w3.org/Submission/WS-MTOMPolicy/). I was very pleased to find out that most of the stuff worked right "out of the box" with the CXF framework: one can start with the WSDL, include the wsoma:OptimizedMimeSerialization policy, reference it with the binding (similar like the WCF-service would have done), implement the server-side -- and voilĂ : we have a CXF/MTOM web-service that works quite nice with the windows .NET clients. On top of that, the exactly same service would also be "consumable" by the METRO clients. However, to my disappointment, the same CXF/METRO service would not work with the CXF-clients!! Instead, the following pops up on the client-side: [ CXF CodeBase 2.2.5 ] > java.lang.NullPointerException > at org.apache.cxf.ws.policy.mtom.MTOMPolicyInterceptor.handleMessage(MTOMPolicyInterceptor.java:45) > at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243) > at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:484) > at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:310) ... Looking deeper into the code, I discovered that the following lines are creating problems: [ from MTOMPolicyInterceptor.java ] 45 String contentType = (String)message.getExchange().getInMessage() 46 .get(Message.CONTENT_TYPE); 47 if (contentType != null && contentType.contains("type=\"application/xop+xml\"")) { .. more to the point, the problem is that the *.getInMessage() will return NULL on the client-side, which in turn is the reason for the NullPointerException. To fix this, I have attempted a very naive fix, by pre-checking if the inMessage is actually NULL, in which case we would just clear the assertion: > --- apache-cxf-2.2.6-src.orig/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java 2010-01-19 13:50:25.000000000 -0800 > +++ apache-cxf-2.2.6-src/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/mtom/MTOMPolicyInterceptor.java 2010-05-19 21:36:28.616942937 -0700 > @@ -42,12 +42,16 @@ > for (AssertionInfo ai : ais) { > > // set mtom enabled and assert the policy if we find an mtom request > - String contentType = (String)message.getExchange().getInMessage() > - .get(Message.CONTENT_TYPE); > + Message inMsg = message.getExchange().getInMessage(); > + if (inMsg != null) { > + String contentType = (String)inMsg.get(Message.CONTENT_TYPE); > if (contentType != null && contentType.contains("type=\"application/xop+xml\"")) { > ai.setAsserted(true); > message.put(Message.MTOM_ENABLED, Boolean.TRUE); > } > + } else { > + ai.setAsserted(true); > + } > } > } > } .. and the things started working for me! I leave this to the consideration to the CXF team- if you guys think this is a proper fix, I would appreciate it if you would include it into your release. I am also attaching the Client/Server code implementation that will demonstrate the breakage (and this potential fix). Best regards, Zoran
CxfWcfInterop.tar.gz
Description: GNU Zip compressed data
