working as servlet but not as java class. why? - java

I am working on SAML SSO Authentication.
I have created a servlet to generate SAML metadata and i deployed it and run it and I got the output.
Same time I have created a java class to generate SAML Metadata with the same code and tried to run it independently. I have added the same Jar files that I have used for that servlet application.
But I got the Exception given below. Can anybody help me to find the difference between running an application independently and by using java servlet??
Thanks in advance.
Exception:

Running as servlet in a web container means all sorts of stuff is on the classpath that is automatically provided by the servlet container.
Running using main() means you have to put all needed stuff on the classpath yourself. The ClassNotFoundException you got should be clear enough in that respect.
(Pls note that although I did say "the" classpath, in a servlet container things are typically not quite that simple. But that's not the point. Also note that running as a servlet, and using features of libraries provided for the container, may even mean your stuff cannot run as an independent java program simply because the library stuff was deliberately intended for servlet container use exclusively.)

Related

Call java application launched from another container

Here's situation. I have one container with php code and php-fpm - this is my application container. Sometimes main application calls java application - jar file. So I decided to split those technologies and make seperate java container with this java application. Now I need a way to call jar file launched inside another container. One way is rebuilding java applicaton to support REST api, but it takes time so is there any other possibility to solve this problem?
You could take a look at Java Remote Method Invocation (Java RMI), but to be honest, I have no idea if it's possible to to this invocation not using java.
https://docs.oracle.com/javase/8/docs/technotes/guides/rmi/hello/hello-world.html

Call from java Main class from servlet Application

I Have two applications.One is Standalone application.Another one is web Application (Servlet App).
Here I want to Call Java Application From Servlet Application.So can You Guys Suggest Me or Can i have one app for this one.So that i will implement in my application.
In this Application I have created Jar file of Stand alone Application After that What to do ?
First, you should make your command line application classes available in your web applcaction environment. To achieve this you should either:
package all in one jar
put classes of stand alone application under WEB-INF/classes in you war
put jar that contains your stand alone application under WEB-INF/lib in you war
Stand alone application starts from main() method. You can just call this method from your servlet and pass parameters, for example: MyApp.main("hello", "stand alone application").
Since you are the author of both applications and are familiar with the internal design of the stand alone application you could (and probably should) call internal layer directly without using main(). For example if you main method starts with new MyApp().start() perform the same call from your servlet.
Just Switch from GlassFish to Tomcat , And then your problem has been solved.

Groovy cast exception occurring in deployed web application after script modification

I asked a similar question previously, but wanted some clarification on the mechanics of the GroovyScriptEngine and how class loading is performed. I have a Vaadin web application that contains groovy classes in WEB-INF. The webapp loads UI logic via a GroovyScriptEngine. Here is a sequence of events that leads to an error:
Deploy war to tomcat & start server, application runs as expected
I make an insignificant change to groovy file located in the exploded WEB-INF folder (for instance, a remark)
Refresh page, GSE apparently reloads classes, and application bombs with GroovyCastException: Cannot cast object 'com.company.myclass#7cde31f8' with class 'com.company.myclass' to class 'com.company.myclass'.
I understand that this may be a class loader issue. Suggestions? I thought the whole point of the GroovyScriptEngine was that it handled hot-edited groovy classes without having to restart the container.
For sure this is ClassLoader issue.
If you need to reload classes (I suppose for faster development), try JRebel. Works well with groovy and tomcat.

Executing web application with tomcat

I have started using tomcat 7 for few days. I have tried executing many JAVA BASED web application with it. I actually want to check the flow of the java based web applications. That means in which sequence the methods of web application get executed. To do this I profile tomcat server with java profiler.
My profiler works like this:
I deploy war file of an application into web Apps dir of tomcat.
I start the server by ./startup.sh
I access the application in browser and execute it.
I stop the server by ./shutdown.sh.
and after I stop the server, the profiler dumps the output in xml format(it shows heirarchy of methods as calling context tree).(MY profiler basically profiles methods of java classes.)
As you know, may be because Tomcat is based on servlet, for 2 exactly same runs of an application(I follow above 4 steps 2 times and have 2 different output for 2 same runs), profiler gives different outputs. Q.1) I dont exactly know why this happens would be very curious to know the reason behind it.
Also the output is very large (around 200 MB) even for simple application. To limit the size of the output and to have same outputs for 2 exactly same runs, I have excluded methods of org.apache.* from profiling. Because I am ultimately interested in knowing the flow of the web application itself.(to know in which sequence methods of web application get executed). For this scenario I have following questions.
Q.2) Running application by deploying war file and running it by fetching it form the directory itself can make difference in the output of the profiler ? or can it affect a sequence of methods in which they execute in both the cases ?
Q.3) I would like to know what happens when I execute jsp page of an application ? I mean how does tomcat execute them? step wise please....
Q.4) when I check the output of the profiler after executing an application, I see large no of methods from org/eclipse/jdt/internal/... get executed. So what do this classes do actually ? Why do I have them in my output ?
Please let me know if I have failed to explain my questions. I kiind of searched a lot but could not find very precise answers to my questions.
I would really appreciate your responses..
Thanks you.
I strongly recommend to read a bit about tomcat works. In short
Q.2 Shouldn't make any difference.
Q.3 JSPs are compiled to servlet classes when they get called. If there is no Servlet class for the JSP tomcat makes one. If there is a corresponding servlet class, tomcat looks which one is younger, the JSP or the servlet. If the JSP is younger it does a new compilation, if not it uses the servlet.
Q.1 Not sure. Could be a multithreading/timing thing, Maybe it's the way your profiler works.
Q.4 Not sure. Could a be classes from the profiler or libraries used by your servlet code?
EDIT: For Q.4 look at Ian Roberts' comment to the question.
What profiler do you use? How about going stepwise through the code by debugging it?

Jar files required to Invoke Webservices

I have ported jamvm to my armel device. I am able to run various swing based and communicate to other systems via socket programming method. But when I try to call a webservice I get many NoClassDefFound exceptions.
I placed jaxws-api.jar file to remove some such exceptions which directed me to other class definition not found exceptions.
Can someone please tell which arfe all the necessary jar files are required to be present during runtime in order to invoke a webservice on a server machine.
Thanks in advance.
If you are using net beans IDE to develop the restful service it is very essay. Just follow these instructions all library (including Jersey) will be added to your project. If you need to get the library separated take the lib folder in project path.
http://netbeans.org/kb/docs/websvc/rest.html
p.s : You don't need to create DB though.

Categories

Resources