Friday, February 21, 2014

Unable to invoke endpoint URI successfully due to: oracle.fabric.common.PolicyEnforcementException: Non-MTOM message has been received when MTOM message was expected

I followed these steps while attempting to mock an ssl enabled web service using the very cool soapui.
I went here to get rolling http://ejvyas.blogspot.in/2010/12/2-two-way-ssl-using-soapui-as-client.html.


  • Created a mock service in soapui using an existing wsdl file on disk which had a valid xsd imported into into it in the same folder). 
  • Created a composite in Jdeveloper and deployed to Oracle SOA to call the yet to be ssl enabled webservice and I get the unexpected error.
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
   <env:Header/>
   <env:Body>
      <env:Fault>
         <faultcode>env:Server</faultcode>
         <faultstring>Unable to invoke endpoint URI "http://<host>:<port>/xxx/xxxxxx" successfully due to: oracle.fabric.common.PolicyEnforcementException: Non-MTOM message has been received when MTOM message was expected.</faultstring>
         <faultactor/>
         <detail>
            <exception>Unable to invoke endpoint URI "http://<host>:<port>/xxxxx/xxxxx" successfully due to: oracle.fabric.common.PolicyEnforcementException: Non-MTOM message has been received when MTOM message was expected.</exception>
         </detail>
      </env:Fault>
   </env:Body>
</env:Envelope>

So I find out that MTOM according to wikipedia(MTOM) is the W3C Message Transmission Optimization Mechanism, a method of efficiently sending binary data to and from Web services and is usually used with something called XOP. Right then, I didn't care about MTOM optimization. I just wanted to call the mock service and move on to ssl enabling it.

I discovered there are number of ways to fix this:

  1. In the request and mockresponse in soapui, there are some properties forceMTOM and enableMTOM. Set forcemtom to true in the mockresponse properties or.
  2. In jdeveloper, right click on the affected reference service, configure WS Policies and under MTOM add the oracle/no_mtom_policy (ensure the box next to it is checked). Compile and deploy. The WS Policy should be visible in Enterprise Manager Fusion (EM)Middleware Control. The policy can be attached in EM but it will be lost on redeployment if it's not attached in the source code.

    However, I was under the impression that soa suite didn't expect mtom by default as I hadn't got the error before then when calling webservices.
    After digging around a little more I found out that mtom is associated with serializing large binary data being transmitted to/from webservices. I also noticed the wsdl file had some elements I wasn't used to - binding, service and policy. It turns out that the policy element had something in it - a OptimizedMimeSerialization element which, from here -> http://www.w3.org/Submission/WS-MTOMPolicy/ indicates that mtom is to be used for the service. So, the wsdl was to blame!. It had to use mtom. So we fixed that and moved on.
  3. Used the java keytool  to create a keystore and self signed certificate for soapui. (See referenced blog for details). All mocked ssl in soapui services will use the same certificate.
  4. Import the mock server certificate into weblogic's keystore using the command.
    keytool -import -alias <certalias> -file c:\server.cer -keystore $MW_HOME\wlserver_10.3\server\lib\DemoTrust.jks

    I was prompted for a password which is usually DemoTrustKeyStorePassPhrase.
  5. Restart weblogic server and soa and test the composite. 
If like me, you had enabled "require client authentication" in the soapui SSL preferences,  you may get the error below.  Just uncheck the box in ssl preferences.

Unable to invoke endpoint URI "https://<host>:<sslport>/xxx/xxxxxxxxxxx" successfully due to: javax.xml.soap.SOAPException: javax.xml.soap.SOAPException: Message send failed: Software caused connection abort: recv failed



Cheers.

No comments:

Post a Comment