Building a custom interceptor with SOAP Web Service MULE -


i'am using mule community edition 3.4. have problem untilsuccessful component. scenario exposed: have flow composed untilsuccessful component in there's soap component makes request web service. in flow there excpetionstrategy, too. problem have when exception occurs inside untilsuccessful (i.e in soap component) excpetionstrategy not able handle because (the exception thrown) handled mechanism inside untilsuccessful component. because need handle exception in excpetionstrategy, thought build custom outbound interceptor (inside soap component) intercept soap response (an exception if it's thrown) , able throw exception in order trigger excpetionstrategy. me problem? tried read documentation sparse , not explain how build custom outbound exception. save somewhere name of exception thrown (i.e if server thrown numberformatexception, save name somewhere in order use in exceptionstrategy)

below can see snippet of mule configuration file:

<flow name="provaclient" doc:name="provaclient">         <quartz:inbound-endpoint jobname="talendjob" repeatinterval="5000" repeatcount="0" responsetimeout="10000" doc:name="quartz">             <quartz:event-generator-job>                 <quartz:payload>error</quartz:payload>             </quartz:event-generator-job>         </quartz:inbound-endpoint>         <object-to-string-transformer doc:name="object string"/>         <until-successful objectstore-ref="os_bean" maxretries="2" secondsbetweenretries="2" doc:name="until successful" deadletterqueue-ref="myqueue">             <processor-chain doc:name="processor chain: wait web service response">                 <processor-chain doc:name="processor chain: web service">                     <cxf:jaxws-client operation="getcode" clientclass="it.aizoon.prova.client.provaservice" port="provaport" enablemulesoapheaders="true" doc:name="soap">                     </cxf:jaxws-client>                       <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="service/prova" method="post" doc:name="http"/>                 </processor-chain>                 <logger message="payload: #[payload]" level="info" doc:name="logger"/>             </processor-chain>         </until-successful>         <catch-exception-strategy doc:name="catch exception strategy">            <!--   <processor ref="myexceptionhandler_id"/>  -->             <logger message="exception strategy" level="info" doc:name="logger"/>         </catch-exception-strategy> </flow> 

here can see server exposes web service:

<flow name="provaserver" doc:name="provaserver">         <http:inbound-endpoint exchange-pattern="request-response" doc:name="http" host="localhost" path="service/prova" port="8081"/>         <logger message="server" level="info" doc:name="logger"/>         <cxf:jaxws-service serviceclass="it.aizoon.prova.prova" doc:name="process soap request" />         <component class="it.aizoon.prova.provaimpl" doc:name="java"/> </flow> 

and here there provaimpl.java, implementation of web service. how can see, if string passed argument in getcode() function error, exception in thrown , managed exception strategy defined in client

@webservice(endpointinterface = "it.aizoon.prova.prova",                   servicename = "prova") public class provaimpl implements prova{        @override       public string getcode(string code) throws numberformatexception{             // todo auto-generated method stub             if(code.equals("error"))    throw new numberformatexception();              string str = "andato buon fine!";             return str;       } } 

i change approach rather using interceptor. if need invoke exception strategy wihout triggering until-succesful router first, move cxf:jaxws-client etc. private flow. quote mule in action 2nd edition on private flows:

this decoupling allows defining processing , error handling strategies local private flow.

<flow name="provaclient" doc:name="provaclient">     ...     <until-successful objectstore-ref="os_bean"         maxretries="2" secondsbetweenretries="2" doc:name="until successful"         deadletterqueue-ref="myqueue">         <processor-chain doc:name="processor chain: wait web service response">             <processor-chain doc:name="processor chain: web service">                 <flow-ref name="externalcallflow" />             </processor-chain>             <logger message="payload: #[payload]" level="info" doc:name="logger" />         </processor-chain>     </until-successful>      ... </flow> <flow name="externalcallflow">     <cxf:jaxws-client operation="getcode"         clientclass="it.aizoon.prova.client.provaservice" port="provaport"         enablemulesoapheaders="true" doc:name="soap">     </cxf:jaxws-client>     <http:outbound-endpoint exchange-pattern="request-response"         host="localhost" port="8081" path="service/prova" method="post"         doc:name="http" />     <catch-exception-strategy doc:name="catch exception strategy">         <!-- handle exception here locally , return custom exception or error              message unil-successful router -->     </catch-exception-strategy> </flow> 

you can handle exceptions locally , return custom exception or error message until-successful router catch using following attribute: failureexpression="exception-type:java.lang.numberformatexception"

here's dummy example knocked throw numberformatexception, log exception in exception strategy , retry:

<flow name="test" doc:name="test">         <http:inbound-endpoint address="http://localhost:8081/test"             doc:name="http" />          <until-successful objectstore-ref="os_bean"             maxretries="2" secondsbetweenretries="2" doc:name="until successful">             <processor-chain doc:name="processor chain: wait web service response">                 <processor-chain doc:name="processor chain: web service">                     <flow-ref name="externalcallflow" doc:name="flow reference" />                 </processor-chain>             </processor-chain>         </until-successful>      </flow>     <flow name="externalcallflow" doc:name="externalcallflow">         <scripting:component>             <scripting:script engine="groovy">                 throw new java.lang.numberformatexception();                 </scripting:script>         </scripting:component>         <default-exception-strategy>             <processor-chain>                 <logger level="error"                     message="numberformatexception occurred : #[message.payload.getexception().getcause()]" />                 <scripting:component>                     <scripting:script engine="groovy">                         throw message.payload.getexception().getcause();                 </scripting:script>                 </scripting:component>             </processor-chain>         </default-exception-strategy>     </flow> 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -