Faces Servlet threw exception java.lang.StackOverflowError - configuration

Ok, I've run across my first StackOverflowError since joining this site, I figured this is a must post :-). My environment is Seam 2.0.1.GA, JBoss 4.2.2.GA and I'm using JSF. I am in the process of converting from a facelets view to JSP to take advantage of some existing JSP tags used on our existing site. I changed the faces-config.xml and the web.xml configuration files and started to receive the following error when trying to render a jsp page. Anyone have any thoughts?
2008-09-17 09:45:17,537 DEBUG
[org.jboss.seam.contexts.FacesLifecycle]
Begin JSF request for /form_home.jsp
2008-09-17 09:45:17,587 ERROR
[org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/].[Faces
Servlet]] Servlet.service() for
servlet Faces Servlet threw exception
java.lang.StackOverflowError
at org.apache.catalina.core.ApplicationHttpRequest.getAttribute(ApplicationHttpRequest.java:210)
at org.apache.catalina.core.ApplicationHttpRequest.getAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.getAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.getAttribute(ApplicationHttpRequest.java:222)
...
My faces-config.xml file is now empty with no FaceletsViewHandler:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
</faces-config>
And my Web.xml file:
<?xml version="1.0"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Ajax4jsf -->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<!-- Seam -->
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<!-- Seam end -->
<!-- JSF -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jsp</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>

I was able to figure out this problem. Apparently you can not configure web.xml to have the same param-value of .jsp for Javax.faces.DEFAULT_SUFFIX as the Faces Servlet url-pattern (*.jsp). If you change your url-pattern to .jspx or to /whateverdirnameyouwant/ the application starts up with no stack overflow errors. (note: the key is that DEFAULT_SUFFIX and Faces Servlet url-pattern cannot be the same regardless of what they are.) Hope this helps anyone else that experiences this specific problem.

Stack overflows in java are almost always caused by infinite recursion / method calls. In your case given the stack trace, it appears 'getAttribute()' is being called repeatedly until crash. While I'm not intimately familiar with the particular environments you are using, I would suggest checking your .jsp code for any of this type of behaviour (for example two methods that call each other)

So, I had a similar error. For me, it was that I had a JSF project and I was messing around with the file extensions. To start with, I had all my web files with extension .jsp. This was working, but then I wanted them to be all .jsf, then after that I went all in on using .xhtml. In the process, my web.xml file changed to accomodate xhtml and jsf. Changing the web.xml file was fine. What got me the StackOverflowError was that I had index.xhtml with a ui.include tag pointing to header.jsf. So I had a xhtml file pointing to a jsf file. I had thought that web.xml would be able to handle this, but it did not, I got the StackOverflowError. So, to fix this, now all my JSF files have extension .xhtml, and nested ui:include tags point to .xhtml files.
On the flip side, though, the browser url can handle the index.jsp, index.jsf, index.xhtml just fine. So the web.xml (with servlet mappings for jsp, jsf and xhtml) handles the browser url just fine, but not for what my problem above highlighted.

Related

Custom error pages not showing up?

I have Tomcat installed and whenever the user hits a 404 pages or 500 page it shows the Tomcats error page. But, then I have created a custom 404 and 500 error pages and put it inside my web.xml file. But, I can't see my custom error page displayed. Please check my code and see what is going on. Thank you for the help.
Here is my code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>report.url</param-name>
<param-value>https://MY_URL_LINK.net/jasperserver-pro/rest_v5/reports/organizations/organization_2</param-value>
</context-param>
<context-param>
<param-name>report.path.mode</param-name>
<param-value>report.path</param-value>
</context-param>
<context-param>
<param-name>report.path.test</param-name>
<param-value>C:\\Program Files\\glassfish-4.1\\glassfish\\domains\\domain1\\applications\\PayApp-5.0-SNAPSHOT\\reports\\</param-value>
</context-param>
<context-param>
<param-name>report.path</param-name>
<param-value>/usr/share/glassfish3/glassfish/domains/domain1/applications/PayApp/reports/</param-value>
</context-param>
<!-- THIS IS MY ERROR PAGES SHOWN BELOW -->
<error-page>
<!-- Missing resource -->
<error-code>404</error-code>
<location>/Error404.xhtml</location>
</error-page>
<error-page>
<!-- Uncaught exception -->
<error-code>500</error-code>
<location>/Error500.xhtml</location>
</error-page>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
25
</session-timeout>
</session-config>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>org.pay.filters.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/secure/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<resource-ref>
<res-ref-name>/oracleInstance</res-ref-name>
<res-type>javax.sql.ConnectionPoolDataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<res-ref-name>jdbc/w2Instance</res-ref-name>
<res-type>javax.sql.ConnectionPoolDataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>

Unable to download file using CORS

I want to make a Cross-Domain request to download a file from my java web application. I am using the CORS filter and have included the configuration in my deployment descriptor(web.xml):
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
I have the cross domain URL in the href attribute:
download
Now when I click the link, the whole page is redirected and the file is downloaded. Can I know what how can I achive this.
Thanks
I faced a similar problem sometime ago. You will not be able to download the file using a GET request using href attribute as u mentioned in the question.
Instead you can submit a form embedded in an iframe as suggested here and submit the form with your file id as a hidden element and it should trigger the download. So your anchor tag shall be:
download
Now pass your fileId as parameter to the onclick JS function and define it like this:
function downloadFile(fileId) {
let $iframe, iframeDoc, iframeHtml;
if(($iframe = $('#download_frame')).length === 0) {
$iframe = $('<iframe id="download_frame" +
' style="display: none;" src="about:blank"></iframe>'
).appendTo('body');
}
iframeDoc= $iframe[0].contentWindow;
if (iframeDoc.document) {
iframeDoc= iframeDoc.document;
}
iframeHtml= '<html><head></head><body><form method="POST" action="http:localhost:8080/MyProject/downloadAction.action"><input type="hidden" name="fileId" value="'+fileId+'"></form></body></html>';
iframeDoc.open();
iframeDoc.write(iframeHtml);
$(iframeDoc).find('form').submit();
}
You can follow similar approach for single or multiple files.
Also to add you can include this in ur web.xml in the filter configuration:
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,X-Test-Header,Cache-Control
</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials
</param-value>
</init-param>

No mapping found for resource files in DispatcherServlet

I've got the following problem on every single page I am trying to access
WARNING [http-nio-8080-exec-7]
org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping
found for HTTP request with URI
[/cart/%3Cc:url%20value='/resources/css/bootstrap.css'%20/%3E] in
DispatcherServlet with name 'springmvc-dispatcher
There are warnings, but those resources are visible (both css and scripts are working, still gives errors), and I have nothing underlined in jsp files.
<link href="<c:url value='/resources/css/bootstrap.css' />" rel="stylesheet"/>
<script src="<c:url value="/resources/js/controllers.js"/>"></script>
I have above paths to css and js in every jsp file.
Project-Structure
And my filter mapping:
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
You haven't used DispatcherServlet in your mapping. Just try this.
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>

Fileupload of PrimeFaces is not working in my liferay portlet?

I am using primefaces 3.3.1 and liferay 6.
In my portlet I want to add fileUpload for primefaces. But each time whenever my page loads this primefaces component is not visible through firebug. I need to make its display to block.
Also, any components below the fileUpload which consists of javascript method or ajax is not working.
I have noticed that in firebug whenever my page loads it shows me one error such as
this.form.fileUpload is not a function
I guess due to this error my fileUpload is not working. But I am not able to to fix it.
<p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}" mode="advanced" fileLimit="3"/>
Upgrade your primefaces to version 3.5 and add commons-fileupload to your project
I think it caused by you didn't add the commons-fileupload and commons-io in your project lib. Also, don't forget do define FileUploadFilter in your web.xml.
Let me show you how i did file upload in my primefaces before, hope this example can solve your problem.
My xhtml page :
<p:fileUpload allowTypes="/(\.|\/)(csv)$/" fileUploadListener="#{fileBean.handleFileUpload}"/>
My FileBean.java :
public class FileBean {
private UploadedFile file;
public void handleFileUpload(FileUploadEvent event) throws Exception {
file = event.getFile();
InputStream input = file.getInputstream();
OutputStream output = new FileOutputStream(new File("D:/UploadedFile/", file.getFileName()));
IOUtils.copy(input, output);
}
Add this to your web.xml :
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
</filter>
And as I said before, add commons-fileupload and commons-io to your project lib.
Fixed this issue in Liferay Portal 6.0.x.
Can you add this code to web.xml and try it?
<!-- Workaround for PrimeFaces 3.2: -->
<context-param>
<param-name>com.liferay.faces.bridge.primeFileUploadForceResourceURL</param-name>
<param-value>true</param-value>
</context-param>
Here is link for more information.
After trying everything else concerning web.xml,pom.xml,... I came back to the obvious things :-)
Maybe you are just forgetting to wrap an form around your upload elements:
<h:form enctype="multipart/form-data">
<p:fileUpload mode="simple" value="#{mgr.file}"/>
<p:commandButton value="Hochladen" ajax="false" onclick="start();"
action="#{mgr.uploadBescheid(bescheidTyp)}" update="growl"/>
</h:form>
Without that point it won't work...

JSTL tag not translate in HTML

My imports :
xmlns:c="http://java.sun.com/jstl/core"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
My JSTL Code :
<h:outputLabel value="YESS" >
<fmt:formatNumber value="0.25" type="percent"></fmt:formatNumber>
HTML generated code:
<label>YESS</label>
<fmt:formatNumber value="0.25" type="percent"></fmt:formatNumber>
The generated code show that the JSTL core is translate in HTML.
But the JSTL "fmt" is not translate in HTML.
More information:
<fmt:ErrorInThisFunctionName value="0.25" type="percent" /> ===> generate an error
I work on Tomcat 6
What Pierre said, and also,
Try xmlns:fmt="http://java.sun.com/jstl/fmt"
Check web.xml for
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
suggestion:
check your TLD file.
check your header (DTD, attributes) in your web.xml
If you are using the normal JSP syntax and not the XML-based syntax try using
<%# taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
xmlns:c="http://java.sun.com/jstl/core"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
The URI for core taglib is invalid. It should be http://java.sun.com/jsp/jstl/core as per its TLD, with /jsp. The URI for format taglib is perfectly fine as per its TLD.
Does the core taglib work in any way? If it doesn't work as well, then it simply means that JSTL is not installed at all. Tomcat does not ship with JSTL by default. You need to download jstl-1.2.jar and put it in /WEB-INF/lib of your webapp. That's all. Do not extract the JAR file and put its loose contents (TLD files and so on) in the classpath as some poor tutorials suggests. It will only get worse. If you already did so, you should cleanup. Only putting the JSTL JAR in classpath is enough.
I had the exact same problem where I would basically declare and it wouldn't get translated into HTML (basically, instead of printing the variable, the entire c:out was printed in the html source). I had forgotten to add this dependency to maven:
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
(If the xml doesn't print, the groupId is taglibs, the artifactId is standard, and the version is 1.1.2