Need help on FastAGI-asterisk java

Hi All,

I need help on asterisk java AGI integration. I am taking the reference from: [color=blue]http://asterisk-java.org/development/tutorial.html[/color] for FastAGI.

Scenario is:

  1. calling from 2000 to 3000 on asterisk.
  2. from the dial plan call a AGI script.
  3. in the script using java code i am printing something and using external jar for the some purpose.
    like mail.jar

Working:

I am [color=red]able to call [/color]the java code from asterisk using FastAGI
Normal Script is running fine and printing whatever is directed in the streamfile() method.

Problem:

in the java code i am taking the reference of some externam APIs, say [color=red]mail.jar [/color]i am using.
on the UNIX system when i am setting the classpath, compiling and running is fine for the
java code.
But when the same script is been run from the Asterisk, it gives error as follows:

[color=red]Sep 9, 2008 12:00:47 PM org.asteriskjava.fastagi.DefaultAgiServer startup
INFO: Received connection from /127.0.0.1
Exception in thread “Asterisk-Java DaemonPool-1-thread-1” java.lang.NoClassDefFoundError: javax/mail/Service
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.asteriskjava.fastagi.AbstractMappingStrategy.createAgiScriptInstance(AbstractMappingStrategy.java:60)[/color]
I know this error is only that FastAGI server is not getting the reference to the mail.jar
I have included this jar into the same folder where the java code is running as well as in the library folder too. I have set the CLASSPATH on the unix end, and if i run the code only from unix things works fine for me.
But gives problem when run by Asterisk - FastAGI.

Please give me any helping pointer, if someone had already done something on this.

Regards,
vishal bhardwaj.

This is definitely a class path issue. It has nothing to do with asterisk, as FastAGI is simply a TCP protocol. How are you firing up your JVM? Can you do a ps - ax | grep java and post the output?

Hi,

Thanks for the reply.

Please find below the datails of my system:

for “[color=red]ps -ax | grep java[/color]” output is:
ps -ax | grep java
[color=blue]Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.3/FAQ
3549 pts/2 S+ 0:00 grep java[/color]

and for “[color=red]ps -ef | grep java[/color]” output is:
[color=blue]root 3551 3421 0 19:10 pts/2 00:00:00 grep java[/color]
below is my directory structure:

[color=blue]/home/vishal/java_workspace/asterisk_java/src/com>ls
activation.jar HelloAGI.class MailEx.class
asterisk-java-0.3.jar HelloAGI.java MailEx.java
fastagi-mapping.properties MailEx$1.class mail.jar[/color]
and

[color=blue]/home/vishal/java_workspace/asterisk_java/src/com>echo $CLASSPATH
:.:/home/vishal/java_workspace/asterisk_java/lib/asterisk-java-0.3.jar:/home/vishal/java_workspace/asterisk_java/src/com/:/home/vishal/java_workspace/asterisk_java/lib/activation.jar:/home/vishal/java_workspace/asterisk_java/lib/mail.jar[/color]

means mail.jar is in the CLASSPATH

need any helping pointer.

Best Regards,
Vishal Bhardwaj.

why don’t you start the JVM with the classpath properly set right in the command line. I am not sure how you are starting your java app, but just add the -classpath argument.

java -classpath home/vishal/java_workspace/asterisk_java/lib/asterisk-java-0.3.jar:/home/vishal/java_workspace/asterisk_java/src/com/:/home/vishal/java_workspace/asterisk_java/lib/activation.jar:/home/vishal/java_workspace/asterisk_java/lib/mail.jar HelloAGI

I am guessing that should work for you.

One other thing I just noticed… your $CLASSPATH is referring to a /lib directory under your asterisk_java workspace, yet your “ls” is an output of the src/com directory.

Are you sure the files exist in the /lib as specified in your environment var?

Thanks a lot g2010, for all your help.

[why don’t you start the JVM with the classpath properly set right in the
command line]

Ya things are working fine at my end as you have directed. But the thing
is i am already able to call the program from the UNIX successfully and it
sends the mail successfully (as i am able to receive the mail as well)

[color=green]Means code is working fine when run from UNIX.[/color]

But the problem that i am facing is, calling that java program through the
AGI script. Means “java-asterisk server” fails to load the library(mail.jar),
as at the runtime it shows error like this:

[color=red]Sep 9, 2008 12:00:47 PM org.asteriskjava.fastagi.DefaultAgiServer startup
INFO: Received connection from /127.0.0.1
Exception in thread “Asterisk-Java DaemonPool-1-thread-1” java.lang.NoClassDefFoundError:
javax/mail/Service at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.asteriskjava.fastagi.AbstractMappingStrategy.createAgiScriptInstance
(AbstractMappingStrategy.java:60) [/color]
Are you sure the files exist in the /lib as specified in your environment
var?

[color=green]Yes i have mail.jar both in /lib as well as src/com directories.[/color]

So what is guess “[color=red]java-asterisk server” it not able to get the correct
CLASSPATH. [/color]Now what i am trying in the java code is to set the
CLASSPATH programatically and then call the java email script.

Please update me if you have any other answer.

Best Regards,
Vishal Bhardwaj.

I guess I am a little confused as to how you are running the AGI server. Can you please clarify.

I use asterisk-java extensively. When my server starts I fire up the JVM as a background daemon process.

What are you doing?

EDIT: I just looked at the example, and I am guessing you are doing this:

$ java -cp asterisk-java.jar:. org.asteriskjava.fastagi.DefaultAgiServer

have you tried adding the full classpath here when you fire up the DefaultAgiServer?

Hi,
on my side, i am only starting the “asterisk-java server” by giving the
following command:
[color=red]/home/vishal/java_workspace/asterisk_java/src/com>java -cp asterisk-java-0.3.jar:. org.asteriskjava.fastagi.DefaultAgiServer[/color]

Then in the dialplan i have written like this:(in extension.conf file)
[color=red]exten => 1300,1,Agi(agi://10.77.143.5/hello.agi)[/color]

and at the location:
/home/vishal/java_workspace/asterisk_java/src/com
the contents of the [color=red]“fastagi-mapping.properties”[/color] file are:
[color=red]hello.agi = MailEx[/color]

So when i make a call from xlite at 1300, then the AGI server calls the
script and gives the error. My sample Hellow AGI script is working fine.
Problem is only with the mail sending program as the server fails to get
the mail.jar file.

Best Regards,
Vishal Bhardwaj.

/home/vishal/java_workspace/asterisk_java/src/com>java -cp asterisk-java-0.3.jar:. org.asteriskjava.fastagi.DefaultAgiServer

you need to add all your class-path information here. this line should look like:

java -classpath /home/vishal/java_workspace/asterisk_java/lib/asterisk-java-0.3.jar:/home/vishal/java_workspace/asterisk_java/src/com/:/home/vishal/java_workspace/asterisk_java/lib/activation.jar:/home/vishal/java_workspace/asterisk_java/lib/mail.jar org.asteriskjava.fastagi.DefaultAgiServer

that should work for you

[size=117][color=green]Thanks a lot g2010,
Thanks a ton.

It solved my problem, the problem was only that i was not starting the
AGI server by giving path of all the jars used. I assumed it should pick the jars from the current location by itself.

Thanks a lot again.
Now i am looking forward with more examples of asterisk-java.
and will ping you when i will be in need of your help.

Best Regards,
Vishal Bhardwaj.[/color][/size]