Why JSF throw OutOfMemoryError in Tomcat 7? - jsf-2

I have a fresh and clean Tomcat7 ready in my Windows machine, when I remove the JSF jars (jsf-api-2.0.1.jar and jsp-impl-2.0.1.jar) from WEB-INF/lib, I hit this error:
Caused by: java.lang.ClassNotFoundException: javax.faces.FacesException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
... 10 more
When I put the 2 jars in WEB-INF/lib, I hit error:
java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2818)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1148)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:1956)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1919)
at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1806)
at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1765)
at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1751)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1255)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:882)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:317)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5081)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.startup.Catalina.start(Catalina.java:620)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Any clue on running JSF in Tomcat 7?

You haven't indicated if the error occurs instantly on deploy or after a while. If it occurs after a while, i.e. during your application run, your code will be to blame. Look at this excellent article that will help you use JDK 6 track down the source of the error.
A PermGen error is indicative of classloading issues pertaining to your application container.The Permanent Generation (PermGen for short) is the area where the JVM stores objects such as classes and string literals. Normally, the garbage collector is not supposed to operate frequently here. Classes loaded by the app server should be automatically cleaned up once the classloader for the web application (there is one per deployed webapp) is no longer being used. Tomcat has given me problems in this area in the past (especially when used within Netbeans). It seems to not be able to clean up after itself effectively after repeated redeploys. There are a handful of things you could do apart from increasing the size of the permgen space
1) You could move the common jars for the web applications running in that tomcat instance into the TOMCAT_HOME/lib. This way, you can expect your class libraries to not be loaded multiple times per requiring web application as is the default behaviour for tomcat(see this). Use this option with care however; if you eventually deploy a web application containing newer versions of the jar, you might run into NoClassDefFound errors.
2)You can try this -XX:MaxPermGen instead of (or in addition to) the -XX:MaxPermSize that mkyong suggested in his article.
Also take a look at this question and it's answers for further steps

Related

Grails error-messages if I run the web app with tomcat 9

I'm updating a fairly large web app from Grails 2 to Grails 5. We are using the Shiro plugin (and others) and Java 11.
If I run the packaged war file under a tomcat-9 installation (currently with FreeBSD as the host os) I get the following errors:
org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static
singleton. This is an invalid application configuration.
at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:626)
at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)
at org.apache.shiro.grails.AccessControl.accessControlMethod(AccessControl.groovy:35)
at org.apache.shiro.grails.AccessControl.accessControlMethod(AccessControl.groovy)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:44)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:89)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:157)
at shiro.ShiroGrailsPlugin$_doWithDynamicMethods_closure3.doCall(ShiroGrailsPlugin.groovy:253)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
etc.
But the app seems to work fine, if I'm not logged in, I'm redirected to the login page and afterwards to the pages of the app. Haven't tested with different permissions, but at first sight, it looks ok.
If I run it with "java -jar myApp.war", I don't have these error-messages.
The java-version for tomcat and the standalone start is the same.
Should be something with dependencies I think...
I cannot speak for the Grails side of things, but from a Shiro perspective:
It looks like you have a request that is being processed outside the scope of Shiro (i.e. either a request that is NOT behind the ShiroFilter), or you have a background or initialization thread calling a protected method (the stacktrace looks trimmed so it's hard to say)
If it's the former, the fix is to make sure all your requests go through the ShiroFilter (or equivalent Grails config), this will make sure a SecurityManager is bound to the request thread.
If it's the latter, take a look at: https://shiro.apache.org/static/1.9.1/apidocs/org/apache/shiro/web/servlet/AbstractShiroFilter.html
(this is often used for background threads running on behalf of a user)

JBoss 6.x throwing java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl

In our application we make WSDL service call(let us say "SomeService"). We use JBoss 6.x and JDK1.8 in our environment(test). Our application also has dependency with CXF for some other services. "SomeService" should be called through standard JAXWS instead of "CXF". By default,c all is being routed through CXF and that's resulting into policy issues. Hence, I followed the solution mentioned below:
JAX-WS = When Apache CXF is installed it "steals" default JDK JAX-WS implementation, how to solve? .
I made the following change in my code:
if (previousDelegate.getClass().getName().contains("cxf")) {
ServiceDelegate serviceDelegate = ((Provider) Class.forName("com.sun.xml.internal.ws.spi.ProviderImpl").newInstance())
.createServiceDelegate(SomeService.WSDL_LOCATION, SomeService.SERVICE_NAME, service.getClass());
delegateField.set(service, serviceDelegate);
}
This change works fine for me in my local environment(I'm using Tomcat 8 +JDK 1.8). I went and deployed the code in test platform (it's JBoss 6.x + JDK 1.8). While testing the functionality, I'm getting the following error:
java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl from [Module "deployment.MyAPP.war:main" from Service Module Loader]
Not sure of the reason for this error. Anybody has clues about it? Do we need to make any additional changes in our JBoss server. Since "com.sun.xml.internal.ws.spi.ProviderImpl" is standard class and that's available in JDK1.8, I don't see any reason why am I getting the above error since our JBoss server is pointing to JDK1.8.
Your help is highly appreciated.
It looks like a classloading issue with your application, or the application server.
The ClassNotFoundException will occur the first time the class is referenced and the classloader tries to load it. The next time the class is referenced, the classloader has cached that is is not found and will throw a NoClassDefFoundError.
Confirm that the ClassNotFoundException is not being caused by the class not being packaged correctly or other classloader settings. Also, ensure the ClassNotFoundException is not occurring the first time the class is referenced.
Check to see if there are any symlinks in the JBoss path.
That will tell us the classes you have deployed to your application, and allow us check if com.sun.xml.internal.ws.spi.ProviderImpl or a related class is deployed to it. That class is shipped with the application server in this directory, and I think this should be the only location it is loaded from.
src/jboss-as/thirdparty/sun-jaxws/lib/jaxws-rt.jar
The only reference I can find to the message "classLoader is not connected to a domain (probably undeployed?) for class "
If you are using a custom JAX-WS implementation and don't want to use JBossWS CXF (the supported JAX-WS library that comes with EAP 6.x), you'll need to first remove JBossWS from your deployment
Once you've done that, you then need to expose the JDK classes that represent the JAX-WS and SAAJ implementation.
Make sure you add modules dependencies for sun.internal.saaj and sun.internal.ws to your deployment.
--
Anup

Java Web start printing job

I posted about the same problem before but got no answer. I am re-posting because I think its a simple problem that someone must have came across recently.
I have a JavaFX application that makes use of the awt.PrinterJob to print some Printable information. while on development everything works fine but when I sign the application and deploy it via Web Start clicking the same button to print the data just throws a Null pointer exception below:
Caused by: java.lang.NullPointerException
at javax.print.PrintServiceLookup.getServicesForContext(Unknown Source)
at javax.print.PrintServiceLookup.getListOfLookupServices(Unknown Source)
at javax.print.PrintServiceLookup.getAllLookupServices(Unknown Source)
at javax.print.PrintServiceLookup.lookupDefaultPrintService(Unknown Source)
at sun.print.Win32PrintServiceLookup.getWin32PrintLUS(Unknown Source)
at sun.awt.windows.WPrinterJob.getPrintService(Unknown Source)
at sun.print.RasterPrinterJob.setPrintable(Unknown Source)
at AdvancedSearchDetailedResultsTableViewController.printToImage(AdvancedSearchDetai..
I have another Java Swing app that I deploy the same way and its using the PrintJob with no issues. I thought that it could be something to do with JavaFX and awt but it works locally which made me think that it must have something to do with WebStart accessing printing services. I looked at JNLP API Printservices with no results.
Previous post link https://stackoverflow.com/questions/17403727/java-web-start-printerjob
Any ideas or workarounds would be much appreciated.
Thanks
Updating from Java 7u21 to 7u25 caused a similar problem in my JavaFX Web Start app, but I do not know the cause of the error yet. May be a permissions issue (see JDK 7u25 and JavaFX 2.2.25 Documentation Updates) or maybe a bug? Test your app with Java 7 update 21!

No content nodes after Umbraco 6 upgrade

I asked this question in the Umbraco forum three days ago and haven't had a single answer. I have a website whose content I can no longer edit and I know the people at SO are the best, so here goes:
I just upgraded a site from Umbraco version 4.6.1 to 6.0.0 and now the only thing that displays in the content tab in the backend is a "Content" node. The whole tree has disappeared but the site actually still works it's just that I can't reach any of the content in the backend--Media, Settings, Developer, etc. tabs all appear to be working as normal.
If I right-click on the only visble node, "Content", I get "Create", "Sort", "Republish Entire Site" and "Reload nodes".
Create gives me the expected create dialog box but I don't want to try creating anything yet until I know what's wrong.
Sort throws the following error:
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
umbraco.cms.businesslogic.CMSNode..ctor(IUmbracoEntity entity) +32
umbraco.cms.businesslogic.Content..ctor(IContentBase contentBase) +18
umbraco.cms.businesslogic.web.Document.<GetRootDocuments>b__1(IContent c) +38
System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +151
System.Linq.Buffer`1..ctor(IEnumerable`1 source) +325
System.Linq.Enumerable.ToArray(IEnumerable`1 source) +78
umbraco.cms.businesslogic.web.Document.GetRootDocuments() +123
umbraco.cms.presentation.sort.OnPreRender(EventArgs e) +813
System.Web.UI.Control.PreRenderRecursiveInternal() +103
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Republish works without error re-creating the umbraco.config file in the App_Data folder.
Reload nodes appears to be trying to, well, reload the nodes, but nothing shows up in the end.
I'm using a MySql database and I'm happy to hack at it with a few sql commands to get things working again as I suspect that a few errant node ids are probably to blame but I don't know what tables to look at.
All help gratefully received.
PS: Umbraco "About" shows the following version information -- "Umbraco v6.0.0 (Assembly version: 1.0.4779.24222)"
I'd suggest that rather than troubleshooting the issue at this point, which is more like chasing a rabbit down a hole, that you take a copy of your backups and attempt the upgrade again. It's possible that you could have missed a step in the upgrade process. Pay special attention to the upgrade notes and the version specific upgrade notes (pretty much every version specific note can apply to you).
If you find that you still have problems after the second attempt, I'd suggest a more granular upgrade path, such as upgrading to highest version of 4.7, then to the highest 4.11, and then finally the highest of 6.0, again paying attention to the upgrade notes and checking after each upgrade that the site still works.
In either case make sure that you are running the installer at the end as this will allow umbraco to make some necessary changes to your database.

Illegal constant pool index error in grails

I have a grails application that i have deployed on my linode box. It was running fine for a few days but now gives this error on all pages:
Caused by: java.lang.VerifyError: (class: org/codehaus/groovy/runtime/InvokerInvocationException, method: getMessage signature: ()Ljava/lang/String;) Illegal constant pool index
Googling indicates that this is a weaving problem, but not how to solve. Has anyone encountered something similar?
I've just worked around this error in gwt... I don't have time to try all the possible values for the variables involved but it appears it was related to using different version of javac for different parts of the process... I was compiling the gwt code using jdk5 and running app code in jre6

Resources