-
1. Throwing Custom exception .
tcunning May 4, 2011 4:50 PM (in response to madhucm)Can you post your jboss-esb.xml? I'm a little confused by what you're asking here and want to see your action chain.
-
2. Re: Throwing Custom exception .
madhucm May 5, 2011 12:58 AM (in response to tcunning)Tom Cunningham wrote:
Can you post your jboss-esb.xml? I'm a little confused by what you're asking here and want to see your action chain.
Tom,
I have attached ESB project. Please see my comments in processException() method.
I want response as :
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<ProducerInScopeResponse>
<Exception>
Gone something bad!
</Exception>
</ProducerInScopeResponse>
</env:Body>
</env:Envelope>
instead of :
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<env:Fault>
<faultcode>env:Server</faultcode>
<faultstring>Gone something bad!</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>
-
TestException.zip 21.3 KB
-
-
3. Throwing Custom exception .
h.wolffenbuttel May 5, 2011 5:26 AM (in response to madhucm)Hi Madhu,
What your getting is a standard SOAPFault, which can be replaced by your message by replacing the default message body after catching the fault.
Regards,
Hans
-
4. Re: Throwing Custom exception .
madhucm May 6, 2011 1:23 AM (in response to h.wolffenbuttel)Hi hans,
I tried the way you explained . It is not working.
If you have any example on this i would be pleased .
Thanks,
Madhu CM
-
5. Re: Throwing Custom exception .
h.wolffenbuttel May 6, 2011 4:59 AM (in response to madhucm)Can you post the setup you have used? You might also want to look into you ESB-message properties, especially the fault. If it still is filled you might want to try to empty it. And see how that works. Another possibility is to throw a new ActionProcessingException(String message) with your message as a parameter (after catching it ofcourse).
regards,
Hans
-
6. Re: Throwing Custom exception .
madhucm May 6, 2011 5:40 AM (in response to h.wolffenbuttel)Hi Hans,
Please find the attached ESB project.I have used processException() method. But still i am not able to
-
TestException.zip 21.3 KB
-
-
7. Re: Throwing Custom exception .
h.wolffenbuttel May 6, 2011 5:58 AM (in response to madhucm)did you try something like this:
public void processException(Message message, Throwable t)
{
System.out.println("Inside Exception");
//Here how to build user defined xml that shows exception. I dont want exception coming as SOAPFault.
/**
* User defined xml will include elements that we define
*/
String message = ""
+ "<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">"
+ " <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">"
+ " <ProducerInScopeResponse>"
+ " <Exception>"
+ " Gone something bad!"
+ " </Exception>"
+ " </ProducerInScopeResponse>"
+ " </s:Body>"
+ "</s:Envelope>
"throw new ActionProcessingException(message);
}because your testcase does not contain any code to do this.
Regards,
Hans
-
8. Re: Throwing Custom exception .
madhucm May 6, 2011 6:25 AM (in response to h.wolffenbuttel)Yes i tried it ..... its not working either !
-
9. Re: Throwing Custom exception .
h.wolffenbuttel May 6, 2011 7:10 AM (in response to madhucm)Sorry, I think you might want to Use ActionProcessingFaultException instead. It takes a message as a variable which should be used for the fault message:
public Message throwException(Message message) throws ActionProcessingException
{
String errorMessage = ""
+ "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ " <s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"
+ " <ProducerInScopeResponse>"
+ " <Exception>"
+ " Gone something bad!"
+ " </Exception>"
+ " </ProducerInScopeResponse>"
+ " </s:Body>"
+ "</s:Envelope>
if(message != null)
{
message.getBody().add(org.jboss.soa.esb.message.Body.DEFAULT_LOCATION,errorMessage);
throw new ActionProcessingFaultException(message, "Error in action" );
}
return message;
}
regards,
Hans
-
10. Re: Throwing Custom exception .
madhucm May 6, 2011 7:49 AM (in response to h.wolffenbuttel)It worked Hans,
Thanks a lot
-
11. Re: Throwing Custom exception .
joe_boy12 Jul 25, 2011 1:48 AM (in response to madhucm)Madhu and Hans - this was really helpful - thnx
I have a situation where I need to catch the exception lets say java.net.UnknownHostException which gets thrown when my wise.SOAPClient action cannot download .wsdl while calling a SOAP service on other server. I have an action which has processException method implemented before it starts the action chain indeed gets called after that above exception is thrown and I want to return a custom message to consumer and not HTTP 500 (as this is a synch call with http gateway listener), in this processException method I tried editing the message body with custom XML message and throwing ActionProcessingFaultException from that - doesnt work. It simply returns http 500 to user instead of custom message. The moment I force an action to throw ActionProcessingFaultException before my SOAPClient is called - it works perfect. do u know whats the problem? or how do we do it in such situations
-
12. Re: Throwing Custom exception .
h.wolffenbuttel Jul 25, 2011 3:27 AM (in response to joe_boy12)Joe_boy12,
Perhaps you should make a new thread because this one is already labelled solved. On what to do with exceptions, it depends. If you can't replace the original message in the exception, you will have to catch the exception yourself. This means writing somekind of wrapper around your SOAPClient which catches your exception. I have for example wrapped the process method of my httprouter to check the returned message. If its anything other than the expected format, I know something went wrong an can act on it. So you might want to try using httprouter instead of the SOAPClient if all fails.
Regards,
Hans
-
13. Re: Throwing Custom exception .
joe_boy12 Jul 25, 2011 12:05 PM (in response to h.wolffenbuttel)Thanks Hans - will start a new thread.