I did my homework but still unable to find a solution to my problem. I created a WAR file through NetBeans which uses soap with attachments - saaj technology. As suggested, I include: saaj-impl.jar, saaj-ri.jar, saaj-api.jar in my project. However, when I "hot deploy" or place my WAR file into webapps directory I get the following exception:
java.lang.NoClassDefFoundError: com/sun/xml/messaging/saaj/soap/MessageFactoryImpl
source.pkg.SoapClient.sendSoapMessage(SoapClient.java:120)
source.pkg.Air.<init>(Air.java:233)
source.flightops.AirController.<init>(AirController.java:15)
servlets.ResultsDisplay.processRequest(ResultsDisplay.java:40)
servlets.ResultsDisplay.doGet(ResultsDisplay.java:91)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.ClassNotFoundException: com.sun.xml.messaging.saaj.soap.MessageFactoryImpl
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
source.pkg.SoapClient.sendSoapMessage(SoapClient.java:120)
source.pkg.Air.<init>(Air.java:233)
source.flightops.AirController.<init>(AirController.java:15)
servlets.ResultsDisplay.processRequest(ResultsDisplay.java:40)
servlets.ResultsDisplay.doGet(ResultsDisplay.java:91)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621
I tried to explicitly indicate classpath like so:
System.setProperty("java.class.path", wjp.getDataDir() + "/webapps/" + wjp.getAppContext() + "/WEB-INF/lib");
I did more research and tried to call a class loader:
try
{
Class.forName("com.sun.xml.messaging.saaj.soap.MessageFactoryImpl").getClassLoader();
}
catch (ClassNotFoundException ex)
{
Logger.getLogger(AirDriver.class.getName()).log(Level.SEVERE, null, ex);
}
But still the same exception as above. This is strange because when I restart the server, sometimes the app works fine - SOAP response received and results are shown, but only after I restart the server. This hints to the fact that saaj classes are somehow found when server is restarted? But, the problem is it must work when I "hot deploy" or place updated WAR into webapps directory without restarting. We cannot afford restarting production server each time WAR is updated.
Another weird issue, is after I restart server, launch this WAR app it works fine. However, other apps which use the same saaj class library throw this same exception! So it's either using this WAR app and others not working, or use other apps and this WAR app throws this exception. Is there some kind of limited saaj library sharing? I have never seen something like this before.
Please, could somebody help me with this very strange (and nasty) problem?
Thank you,
Victor.
The problem has been solved by re-implementing the app in the main web container i.e. ROOT/WEB-INF as opposed to as a separate portlet.
Related
I'm writing a web application which uses JAXB and JAX-RS. The content-type used for getting/sending data to the server is XML. The web application runs in a GlassFish server(4.1.2/ 5), the JDK used is 1.8.
The problem is that the internal SAXParser allows doctype declarations which makes XEE-Attacks possible. I'm not able to inject the specific feature into the SAXParserFactory, so i built a wrapper for the SAXParserFactory, which sets the feature. The SAXParserFactory is registered using the system properties.
System.setProperty("javax.xml.parsers.SAXParserFactory","de.mycompany.sdk.parser.SAXParserFactoryWrapper");
Unfortunately, the server throws a ClassNotFoundException on every second startup, otherwise the application behaves normal.
Has anyone ideas how to fix it?
I've also tried to include the jar into the class path or specify it using the manifest, but did not work neither.
I get the following error:
javax.xml.parsers.FactoryConfigurationError: Provider de.mycompany.sdk.parser.SAXParserFactoryWrapper not found
at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:200)
at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:152)
at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:232)
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:127)
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.getSAXParser(DeploymentDescriptorFile.java:125)
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:305)
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:245)
Caused by: java.lang.ClassNotFoundException: de/mycompany/sdk/parser/SAXParserFactoryWrapper
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at javax.xml.parsers.FactoryFinder.getProviderClass(FactoryFinder.java:124)
at javax.xml.parsers.FactoryFinder.newInstance(FactoryFinder.java:188)
... 56 more```
ClassNotFoundException
can occur if you have multiple versions of a class (de.mycompany.sdk.parser.SAXParserFactoryWrapper in this case) in your class path. This generally happens when you have multiple versions of the same library in your classpath.
Thanks for your help! I found a solution for my problem. I deployed the application using the GlassFish CLI and it works! The previous tries were done using NetBeans. It seems that NetBeans does anything different during the startup or shutdown process of the GlassFish server wich involves the exception.
The projet work fine in tomcat localhost but when I upload it in a remote tomcat I get this bug :/ , I have the jar that contain the ImageReaderFactory class in classpath, I didn't understand what can be the problem,
I cleared the /tomcat/work/Catalina/localhost folder but always the same bug : java.lang.NoClassDefFoundError
07-Oct-2019 23:06:25.584 SEVERE [http-apr-8080-exec-267] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [UploadServlet] in context with path [/MyServer] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoClassDefFoundError: org/dcm4che3/imageio/codec/ImageReaderFactory
at org.dcm4che3.imageio.plugins.dcm.DicomImageReader.setMetadata(DicomImageReader.java:794)
at org.dcm4che3.imageio.plugins.dcm.DicomImageReader.readMetadata(DicomImageReader.java:713)
at org.dcm4che3.imageio.plugins.dcm.DicomImageReader.read(DicomImageReader.java:452)
at com.project.dicomserver.UploadServlet.getFrameIcon(UploadServlet.java:86)
....
Does anyone have any ideas?
image
There is a bunch of things that could be go wrong in your specific case. So answering with the best of my knowledge. Make amendments, by adding as much details as possible, to the question and we can help you further.
Every application in tomcat needs to have a specific folder structure. The folder structure is documented here. In short, war files must be deployed into $CATALINA_BASE/webapps/ directory.
So if your application is "myapp", then there must be a $CATALINA_BASE/webapps/myapp directory.
Inside $CATALINA_BASE/webapps/myapp directory, we need to have WEB-INF. Not $CATALINA_BASE/webapps/myapp/WebContent/WEB-INF, but $CATALINA_BASE/webapps/myapp/WEB-INF ! And the case matters.
If this is not how your application is deployed into a vanilla tomcat, it will not work properly. Read the official documentation
Now about your development environment, see whether your eclipse configurations have been modified. The Export As War options can be modified at multiple locations and all of them can have impact on the war file you have generated. When in doubt, I look at this link
Use a build tool like maven or gradle. These tools bring standards for compiling, archiving, testing and deploying applications and makes you worry less on environment related issues.
I am using axis2 on Apache Tomcat. I am writing client side to consumer SOAP WS. I configured Eclipse to use Tomcat as a server and while executing that line
stub._getServiceClient().engageModule("addressing");
I was getting that error "unable to engage module addressing". To fix that issue I add following line in the VM arguments of run configuration
-Daxis2.repo="E:\axis2\repository"
Now I export my project as a war file and deploy it on the real server. But Now I am again getting the same error(I checked the log file). I don't know how to fix, can every one help me. Thanks
It got resolved on my side in the following way:
I had an outdated WEB-INF/modules/axis2-jaxws-mar*.mar or rather 2 versions of it and the classloader got the older one of it and AxisServlet didn't start altogether
java.lang.NoSuchMethodError: org.apache.axis2.engine.AxisConfiguration.getGlobalModules()Ljava/util/List;
at org.apache.axis2.jaxws.module.JAXWSModule.registerGlobalModule(JAXWSModule.java:51)
Error 500: java.lang.NoSuchMethodError: org/apache/commons/fileupload/FileUploadBase.isMultipartContent(Lorg/apache/commons/fileupload/RequestContext;)
This is the error that I found in Websphere but I don't get any error in Apache tomcat. If anybody having solution. please reply me fast.
I am using following jar:
1.) commons-fileupload-1.3.jar
2.) commons-io-2.4.jar
See 500 means simple there is some problem in servlet code.
you might done something wrong in your servlet code.
try with putting upgraded jar files.
and also put your code so that you have written.
A comment on this post helped me, so I'm writing it as an answer.
It may help to set the classloader policy on the server to "Multiple". To do this in Websphere, navigate as follows:
Log in to the Websphere console (typically http://localhost:9060/ibm/console/login.do)
Servers -> Server Types -> WebSphere application servers.
Select the server that your application is deployed on ("server1" by default)
In the section "Server-specific Application Settings", change the Classloader policy to "Multiple"
Click "OK", then "Save to the master configuration"
You may then need to restart the server before the changes take effect.
I have created a jersey web service with neatbeans using glassfish as my server, everything works fine but i have issues trying to install the same app on websphere 7.
i get this error "Error 500 An error occurred while processing request: /ibm/console/upload.do Message: java.lang.NoClassDefFoundError: javax.servlet.ServletInputStream".
I even tried creating a simple web app and tried to deploy on websphere, again, i have the same error.
Anybody with ideas? I need your help so badly ya'll. Thanks in advance
Make sure you don't have servlet-api.jar in your WEB-INF/lib. If its there it may interfere with the one already present in websphere a trick the classloader
I did below steps which worked for me :
Go to the server in console(which was stand - alone in my case i.e no DMGR)
Change the class loader policy to "multiple".
I suppose I am not too late to reply to this question. The HttpServlet class can be found in the j2ee.jar. WAS does not bundle it in servlet-api.jar, the way Tomcat does it.
You need to bundle servlet-api.jar file in your application.