I have made the WSDL from java code using the Xfire framework,
Here is my java code..
public class Test implements TestException {
public void testException(String check) {
List<String> list = new ArrayList<String>();
list.add("ABC");
list.add("XYZ");
list.add("PQR");
list.add("LMNOP");
list.add("EFGH");
list.add("Pqrst");
try
{
if(check(list,check))
System.out.println(check);
}
catch (MyException e)
{
e.printStackTrace();
}
}
public boolean check(List<String> list,String check) throws MyException {
if(list.contains(check))
return true;
else
throw new MyException();
}
}
The exception class is :
public class MyException extends Exception {
public MyException()
{
}
public String toString()
{
return "Exception by My Exception.....";
}
}
*The flex code : *
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:WebService id="testService" wsdl="http://localhost:9090/ExceptionTest/xfire/Test?wsdl" showBusyCursor="true">
<mx:operation name="testException" result="testExceptionRH(event)" fault="testExceptionFH(event)"/>
</mx:WebService>
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
protected function click_clickHandler(event:MouseEvent):void
{
testService.testException(showText.text).send;
}
protected function testExceptionRH(event : ResultEvent) : void
{
messageLbl.text = "No Exception.....!!!!";
}
protected function testExceptionFH(event : FaultEvent) : void
{
trace(event.fault.faultDetail);
messageLbl.text = "Exception.....!!!!";
}
]]>
</mx:Script>
<mx:Button x="163" y="70" label="Click" id="click" click="click_clickHandler(event)"/>
<mx:TextInput x="114" y="27" id="showText"/>
<mx:Label id="messageLbl" fontWeight="bold" x="183" y="99"/>
Now the problem is whenever i am send the object other than object in list say "Amit" then it throw exception right, & so the fault message has to displayed but i am getting 开发者_StackOverflow社区always the result handler message, I have check the logs of tomcat it shows exception (MyException) stack trace,
What wrong i am doing ..???
Please help, Thanks in Advance
you already caught the exception in your testException method so it was not propagated to your flex front end.
you should handle the exception (e.g. do your logging) in your catch block then throw it again.
try {
// do work...
} catch (Exception e) {
// handle exception
e.printStackTrace();
// include the root cause and propagate the exception to flex
// using RuntimeException as an example)
throw new RuntimeException("error msg here", e);
}
精彩评论