On Wed, May 13, 2009 at 8:48 PM, Senthil Sona <swsoni@cisco.com> wrote:

Hi Deepal,

   I have added the code in the handler class like

       if(msgContext.getFLOW()==1)
       {
                logger.info("This is inFlow");
                System.out.println("This is inFlow");
                MessageContext faultContext =
                        MessageContextBuilder.createFaultMessageContext(msgContext, new
AxisFault("validation failed error", new QName("validation error", "wsa")));
                        AxisEngine.sendFault(faultContext);

it is bit difficult to answer your question without looking all your code. But try this.


if you want to send a soap fault to client side, throw an AxisFault here. When you throw an AxisFault it is caught at the transport level and it sends the fault message by calling to fault flow.

if you want to send a normal soap message do this,

MessageContext outMsgContext = MessageContextBuilder.createOutMessageContext(msgContext);
AxisEngine.send(outMsgContext);
return InvocationResponse.ABORT

here it is important to return InvocationResponse.ABORT to terminate the inFlow.

thanks,
Amila.


       }

 I am using the same handler class for inflow and outfault flow thats why i
am checking if(msgContext.getFLOW()==1). At client console i am getting
error like

org.apache.axis2.AxisFault: validation failed error
       at
org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
       at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
       at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
       at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
       at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
       at
org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:548)
       at
org.apache.rahas.client.STSClient.requestSecurityToken(STSClient.java:127)
       at org.apache.rampart.util.RampartUtil.getToken(RampartUtil.java:486)
       at
org.apache.rampart.util.RampartUtil.getSecConvToken(RampartUtil.java:396)
       at
org.apache.rampart.builder.SymmetricBindingBuilder.initializeTokens(SymmetricBindingBuilder.java:670)
       at
org.apache.rampart.builder.SymmetricBindingBuilder.build(SymmetricBindingBuilder.java:73)
       at org.apache.rampart.MessageBuilder.build(MessageBuilder.java:128)
       at org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:64)
       at org.apache.axis2.engine.Phase.invoke(Phase.java:317)
       at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:264)
       at org.apache.axis2.engine.AxisEngine.resumeSend(AxisEngine.java:370)
       at org.apache.sandesha2.workers.SenderWorker.run(SenderWorker.java:287)
       at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
       at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
       at java.lang.Thread.run(Thread.java:735)

and its keep on executing the handler, Because i am able to see the log
message i am printing in inflow if condition again and again. I am printing
the message context in OutFaultFlow. i am getting the message like

This is OutFaultFlow
 messagecontext==<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope
xmlns:s
oapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><soapenv:Fault
xm
lns:axis2ns5="validation
error"><soapenv:Code><soapenv:Value>axis2ns5:wsa</soape
nv:Value></soapenv:Code><soapenv:Reason><soapenv:Text
xml:lang="en-US">validatio
n failed error</soapenv:Text></soapenv:Reason><soapenv:Detail
/></soapenv:Fault>
</soapenv:Body></soapenv:Envelope>

Thanks,
Swapna Soni.

Deepal Jayasinghe-2 wrote:
>
> Try this,
>
> MessageContext faultContext =
> MessageContextBuilder.createFaultMessageContext(messageCtx, e);
> AxisEngine.sendFault(faultContext);
>
> - Deepal
>> Hi Deepal,
>>
>>    Thanks for your reply. If we set the AxisEngine.sendFault(msgContext)
>> in
>> inflow handler, it will execute the outFaultFlow but client program wotn
>> get
>> any response and we are getting org.apache.axis2.AxisFault: Read timed
>> out
>> exception. And its again and again executing the inflow handler. For
>> testing
>> purpose i have written
>>      if(msgContext.getFLOW()==1)
>>         {
>>               logger.info("This is inFlow");
>> }
>>  in the inFlowhandler class and its getting execute again and again. But
>> i
>> want it should get execute only once when request comes from client and
>> it
>> should do validation of that request message, if something is wrong then
>> outflow or OutFaultFlow should get execute and send the proper error
>> response to client and should get terminate there only. Once we get any
>> validation error in inFlow handler, it should not process further engaged
>> module and request should terminate in inFlow and from there client
>> should
>> get response via outFlow or outFaultFlow.
>>
>>    We are engaging the sandesha and rampart from in the client program
>> only.
>>
>>                      sender.engageModule("addressing");
>>                      sender.engageModule("sandesha2");
>>                      options.setProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID,
>> "Yash_Seq");
>>                      sender.engageModule("rampart");
>>
>>                      options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
>> loadPolicy("C:/WS-X/misc/20090427/WTPTestRM2Client/WebContent/WEB-INF/conf/policy.xml"));
>>
>> Could you please let us know how to achieve this functionality.
>>
>> Thanks,
>> Swapna Soni.
>>
>> Deepal Jayasinghe-2 wrote:
>>
>>> Behavior will be different based on the dispatch status, but you can
>>> simply call.
>>>
>>> AxisEngine.sendFault(messageContext)
>>>
>>> Then it will send  the fault
>>>
>>> -  Deepal
>>>
>>>> Hi Axis Team,
>>>>
>>>>     I have one very urgent requirement. One client program invokes the
>>>> service in which sandesha, rampart and one custom module is engaged. In
>>>> custom Inflow handler we do some validation. If something is wrong in
>>>> that
>>>> validation, then we want it to start the outFlow and send the custom
>>>> response to client back without executing further engaged modules and
>>>> without invoking service.
>>>>
>>>>    Could anyone please tell me how can i do this using axis2 api. Its
>>>> very
>>>> very urgent requirement for us.
>>>>
>>>> Thanks,
>>>> swapna soni
>>>>
>>>>
>>> --
>>> Thank you!
>>>
>>>
>>> http://blogs.deepal.org
>>> http://deepal.org
>>>
>>>
>>>
>>>
>>
>>
>
>
> --
> Thank you!
>
>
> http://blogs.deepal.org
> http://deepal.org
>
>
>

--
View this message in context: http://www.nabble.com/How-to-terminate-InFlow-and-start-OutFlow-in-the-custom-handler-of-axis2-tp23521710p23523940.html
Sent from the Axis - Dev mailing list archive at Nabble.com.




--
Amila Suriarachchi
WSO2 Inc.
blog: http://amilachinthaka.blogspot.com/