Thread: [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 ! |
From: Stefan R. <sr...@re...> - 2006-05-08 23:48:22
Attachments:
signature.asc
|
>> 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. sorry for whatever reason i didnt get your previous mails. i improved the logging for latest trunk so that in case of an instantiation problem the full stacktrace will be logged. hope that helps people with similar problems in the future. thanks for reporting, =Stefan -- reuter network consulting Neusser Str. 110 50760 Koeln Germany Telefon: +49 221 1305699-0 Telefax: +49 221 1305699-90 E-Mail: sr...@re... Jabber: sr...@ja... |
From: Stefan R. <sr...@re...> - 2006-05-09 01:17:02
|
>> 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. sorry for whatever reason i didnt get your previous mails. i improved the logging for latest trunk so that in case of an instantiation problem the full stacktrace will be logged. hope that helps people with similar problems in the future. thanks for reporting, =Stefan -- reuter network consulting Neusser Str. 110 50760 Koeln Germany Telefon: +49 221 1305699-0 Telefax: +49 221 1305699-90 E-Mail: sr...@re... Jabber: sr...@ja... |
From: Stefan R. <sr...@re...> - 2006-05-09 01:03:53
Attachments:
signature.asc
|
>> 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. sorry for whatever reason i didnt get your previous mails. i improved the logging for latest trunk so that in case of an instantiation problem the full stacktrace will be logged. hope that helps people with similar problems in the future. thanks for reporting, =3DStefan --=20 reuter network consulting Neusser Str. 110 50760 Koeln Germany Telefon: +49 221 1305699-0 Telefax: +49 221 1305699-90 E-Mail: sr...@re... Jabber: sr...@ja... |
From: Stefan R. <sr...@re...> - 2006-05-09 01:22:47
|
>> Log messages of the DefaultAGIServer are not so descriptive, right ? >> >> Anyway thanks for no answers. sorry for whatever reason i didnt get your previous mails. i improved the logging for latest trunk so that in case of an instantiation problem the full stacktrace will be logged. hope that helps people with similar problems in the future. thanks for reporting, =Stefan -- reuter network consulting Neusser Str. 110 50760 Koeln Germany Telefon: +49 221 1305699-0 Telefax: +49 221 1305699-90 E-Mail: sr...@re... Jabber: sr...@ja... |
From: Artem V. L. <te...@of...> - 2006-05-10 06:16:36
|
Stefan Reuter wrote: >sorry for whatever reason i didnt get your previous mails. >i improved the logging for latest trunk so that in case of an >instantiation problem the full stacktrace will be logged. hope that >helps people with similar problems in the future. > > > Forgive, if my words have sounded too roughly... I'am a big fan of your work, your project has saved to me a lot of time. :) Best regards, Artem [scjp5.0] |
From: Artem V. L. <te...@of...> - 2006-05-10 06:09:54
|
Peter Hoppe wrote: > > 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 > Peter, many thanks to you, your examles are very helpful ! Best regards, Artem [scjp5.0] |