[Asterisk-java-users] Re: AGI scripts from *.jar. (Artem V. Luzhnov)
Brought to you by:
srt
From: Peter H. <pe...@ra...> - 2006-05-06 11:40:48
|
Hello Artem, yes, you can run agi scripts from .jar files. As you pointed out, you got an exception. I recommend that you make two root classes for all of your exceptions and then inherit your exceptions from those root classes. The root classes should contain code that performs certain actions (e.g. logging) at the moment when they are thrown. I said two root classes - 1. one root class inheriting from java.lang.Exception This will be your base exception for all exceptions which need a throws clause in the method where they are thrown. 2. one root class inheriting from java.lang.RuntimeException This will be your base exception for all exceptions which should not require any throws clause in the method where they are thrown. See java documentation on Exception and RuntimeException, esp. concerning the need of a throws clause. You then create a small framework containing your own exception(s) that inherit either from root class (1) if you think they need a throws clause or from root class (2) if you think they are just exceptions that happen to be thrown during run time, like an illegal array index. This approach has got the disadvantage that you are duplicating code (such as having your own IndexOutOfBoundsException) which is bad practice, normally. However, it has a great advantage that the appropriate action is automatically performed when the exception is thrown. You can now use catch clauses such as this one: // inherits from TRuntimException ( root class (2) ) catch (TIllegalArrayIndexException e) { // no action required - will be logged automatically } With this you achieve consitent exception handling. You can even write your own log formatting, such as creating the resp. logging information as xml code for further automated analysis! As I said - this is a bit unconventional and cuts across some principles of good programming, but then, life's not straight forward, and sometimes you need to be a bit more pragmatic. Hope this helps! God bless Peter Example code: 1. Your base class inheriting from java.lang.Exception. import net.sf.asterisk.util.Log; import net.sf.asterisk.util.LogFactory; class TDeclaredException extends java.lang.Exception { private static Log gLog = null; public TDeclaredException (String message) { super (); Log (message); } public void Log (String message) { String stackTraceXML = null; if (gLog == null) { gLog = LogFactory.getLog(getClass()); } gLog.warn (message); } } 2. Your base class inheriting from java.lang.RuntimeException. import net.sf.asterisk.util.Log; import net.sf.asterisk.util.LogFactory; public class TRuntimeException extends RuntimeException { private static Log gLog = null; public TRuntimeException (String message) { super (); Log (message); } public void Log (String message) { String stackTraceXML = null; if (gLog == null) { gLog = LogFactory.getLog(getClass()); } gLog.warn (message); } } >>Can I use the AGI scripts from *.jar files ? > > > Sorry, its my fault. > The constructor of my AGI script throws an exception but I dont see it > in server's log files. > Log messages of the DefaultAGIServer are not so descriptive, right ? > > Anyway thanks for no answers. > > Best regards, Artem. > [scjp5.0] -- dyslexics of the world - untie ! |