• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calling java inside a servlet

 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I am working in asterisk java.i want to pass the value like callerid from the asterisk java program to servlet.but when i tried to call the java in servlet,it shows the following error.i am pasting here,how i tried to call java inside a servlet

the error message follows:


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.lang.NoClassDefFoundError: org/asteriskjava/fastagi/AgiScript
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:620)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1853)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:875)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1330)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1209)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:169)
InServlet.doGet(InServlet.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.ClassNotFoundException: org.asteriskjava.fastagi.AgiScript
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1363)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1209)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:620)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1853)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:875)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1330)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1209)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:169)
InServlet.doGet(InServlet.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.


thanks in advance.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This class is not there in the classpath - org.asteriskjava.fastagi.AgiScript. make sure that class is there in the path before running the server.

Cheers,
Bala
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

culprit:
-------------------------------
Class c=Class.forName("Inbound");
--------------------------------

give fullyqualified name for an argument of forName

note: use all variable inside doGet/doPost.this is better practise..please avoid the class variable declarations
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
give fullyqualified name for an argument of forName

I am having the calss named Inbound.java.I dont understand what ia the fully qualified name.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
something like

forName("package1.package2.ClassName");
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok.As you said,I put the inbound class in com.example.servlets package and changed the code like this

but now the following is displayed:


HTTP Status 405 - HTTP method GET is not supported by this URL

--------------------------------------------------------------------------------

type Status report

message HTTP method GET is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).



 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
---------------------------------
h.service( request, channel);
---------------------------------
you may require to change the method name sevice

[i am not sure try this and let me know ]
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two things here.
Your original code is implementing doGet where as this code is implementing doPost. How are you invoking it? by GET or POST? Make changes accordingly.

Also, your original error was

java.lang.NoClassDefFoundError: org/asteriskjava/fastagi/AgiScript

WHat is this AgiScript class? Is it one of your classes? Are you sure this class is in the classpath?
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you may require to change the method name sevice
In my java code i am using the service method only.thats why i am calling the service method here.

WHat is this AgiScript class? Is it one of your classes? Are you sure this class is in the classpath?
I am using doGet method only.I just tried in doPost and pasted that code.that also showing the same eror.
AgiScript class is predefined class in the jar file asteriskjava.0.3.1.jar.In my eclipse ide it is placed under Referenced Libraries-->asterisk-java-0.3.1.jar-->AgiScript.class.

I am placing here my java class Inbound.java

[ August 08, 2008: Message edited by: preethi Ayyappan ]
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

AgiScript class is predefined class in the jar file asteriskjava.0.3.1.jar.In my eclipse ide it is placed under Referenced Libraries-->asterisk-java-0.3.1.jar-->AgiScript.class.



I cant find where this is. I usually place my external jars under
Project->Properties->Java Build Path->Libraries

Are you running Tomcat from eclipse?
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes,i am ruunning tomcat from eclipse only.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by preethi Ayyappan:
yes,i am ruunning tomcat from eclipse only.


Can you move the jar to where I said (Project->Properties->Java Build Path->Libraries) and see what happens?
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did the same what you told.i am getting the same error.but i can able to run the program without error when i placed the code in another project.I think the calss is in perfect classpath there.

Thanks
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i need to get the parameter callerid from the class file inbound.java to the servlet.i have done like this

This is printing null and shows the following error in console


inbound
java.lang.IllegalStateException: Trying to send command from an invalid thread
at org.asteriskjava.fastagi.AgiOperations.getChannel(AgiOperations.java:791)
at org.asteriskjava.fastagi.AgiOperations.streamFile(AgiOperations.java:296)
at com.example.servlets.Inbound.service(Inbound.java:47)
at com.example.servlets.JavaServlet.doGet(JavaServlet.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)



(Inbound.java:47) is streamFile("plase hold th line your call is being trfd to officer");

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you ironed out the classpath issues and have a working connection between the servlet and your java class. Unfortunately you came upon another problem:
"java.lang.IllegalStateException: Trying to send command from an invalid thread"

This message is being sent by the asteriskjava code, and should be documented by them to identify why this exception may occur, and what you can do to fix it. It is, however, API specific so unless someone here knows AsteriskJava it will be hard to get an answer.

Try looking at the Asterisk-Java FAQ or asking in their mailing list to see what they say.
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply.I am having another doubt here.I need to pass a parameter ,say callerid from my asteriskjava application to a servlet.In java code I tried to pass the parameter using open url connection like the following:-

Is this correct way?If yes, how can i retrieve this parameter in servlet code.please anyone help me in code.
Thanks.
[ August 08, 2008: Message edited by: preethi Ayyappan ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it's possible to do it that way. You can get at the parameter by calling request.getParameter("parameter1") in the doGet method of the servlet that handles this request.
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.I have tried that.but i am getting output null.
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by preethi Ayyappan:
Thanks.I have tried that.but i am getting output null.



Is the callerid returned by request.getCallerIdNumber() in your previous example null?
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes.In the previous code,I have used request.getCallerId().but eclipse shows that is deprecated method.so i have changed it to request.getCallerIdNumber().Is there any issues due to this?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In the previous code,I have used request.getCallerId().but eclipse shows that is deprecated method.so i have changed it to request.getCallerIdNumber().Is there any issues due to this?


That's hard to say, since those methods are 3rd party extensions. The javadocs of those methods should tell you about them, or if not, you can always have a look at the source code.
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.can i display(open) the page http://192.168.1.174:8080/NewWebProject, if i run the stand alone application which uses the openurlconnection?
[ August 11, 2008: Message edited by: preethi Ayyappan ]
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by preethi Ayyappan:
Thanks.can i display(open) the page http://192.168.1.174:8080/NewWebProject, if i run the stand alone application which uses the openurlconnection?

[ August 11, 2008: Message edited by: preethi Ayyappan ]



Why don't you try it and tell us?
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.I will try.But i just want to know is there any possibility to open a webpage using url open connection.Because i need to do is,If i run my java code it should open a webpage and the value of parameters in my java code should be displayed in servlet page.
 
And inside of my fortune cookie was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic