The requested URL /application/index.jsf was not found on this server(Apache and Tomcat) - apache

I am a stackoverflow fan. This website has solved most of technical questions without even asking them but by only reading previous similar questions. Indeed I have searched the web and stackoverflow but I could not find any answer and I could not solve this problem by myself. My only resort is to ask for your help. I have worked on a small JSF 2.0 application and everything is working fine on my local tomcat 6.0.35. I have all the JSF lib on my WEB-INF. I am using mojarra version 2.1.14. The url is accessed like this
on my local
http://localhost/application/page.jsf
and this application is deployed to an external hosted tomcat which has apache and Tomcat 6.0.36. The application is deployed under /home/username/public_html. the same url should be accessed by typing
http://website.com/application/page.jsf
but I am getting the error:
Not Found
The requested URL /application/page.jsf was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Additionally, html and JSP pages are working fine. I have a test application which has jsp page and it is loading just fine. xhtml pages on the other hand are not working on this apache box. For the JSP pages to work I added JSP and servlet support
/usr/local/cpanel/scripts/addservlets2 --domain=domain.com
This is the web.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
</web-app>
I strongly believe this web.xml has nothing to do with jsf not working and furthermore these settings are working well on my local. The tomcat log file is showing no error of page not found on the external host.
Here is the faces config file
<?xml version="1.0"?>
<faces-config 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-facesconfig_2_0.xsd"
version="2.0">
</faces-config>
What is happening? Please help me. I am getting desperate. Why JSF request are returning not found on this apache server?
additional the el-impl-2.2.jar and el-api-2.2.jar are in the tomcat libs.
and javax.faces-2.1.14.jar, jstl-api-2.1.jar, jstl-impl-2.1.jar and all the required commons jars are all in the WEB-INF.

I have just fixed this problem. I have spent 6 days doing investigations how to fix this. What a waste of time. Today at work, I talked to my colleague and he suggested I direct my investigations toward apache connector to tomcat since I was claiming that everything is working fine on my local tomcat server. I made some research and I discovered that I needed to edit cp_jkmount.conf connector. JkMount is used to map a context path to a Tomcat worker. I added the following
<IfModule mod_jk.c>
JkMount /*.xhtml ajp13
JkMount /*.jsf ajp13
</IfModule>
at the end of these connectors
/usr/local/apache/conf/userdata/std/2/username/website.com/cp_jkmount.conf
/usr/local/apache/conf/userdata/ssl/2/username/website.com/cp_jkmount.conf
I hope this will help someone else.

Related

Apache-Tomcat Servlet-mapping through url-pattern fails (404-Error)

I have a problem with Apache-Tomcat Servlet-mapping through url-pattern.
It has been working just fine till last year.
Very recently I tried to login and all of sudden 404 Not Found error showed up.
I still see all other pages fine. I don't know what has changed on server-side because I am borrowing a linux-server from vultr.
Since I haven't touched anything in my coding and everything looks fine to me, I have no clue.
It seems easy to solve for experts. Can anyone help me with this?
- Error Message
Not Found
The requested URL /login.do was not found on this server.
Apache/2.4.12 (Ubuntu) Server at xx.xx.xx.xx Port 80
Here xx is the ip address of my server
- tomcat/conf/server.xml
...
<Context path="" docBase="/.../tomcat/webapps/.../WebContent" reloadable="true"></Context>
...
- tomcat/conf/web.xml
...
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
...
- myapp/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>myapp</display-name>
...
<servlet>
<servlet-name>URIController</servlet-name>
<servlet-class>myapp.mvc.control.URIController</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>
/WEB-INF/commandHandler.properties
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>URIController</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
...
- myapp/WEB-INF/commandHandler.properties
/login.do=myapp.mvc.command.Login
When I try to login, it says "The requested URL /login.do was not found on this server."
It has been working fine like this: when hitting "login" button, it passes the content in commandHandler.properties to the control class (myapp.mvc.control.URIController) and this class get the name of the login class (myapp.mvc.command.Login) in order to dispatch the request to the login class.
If this problem has something to do with Apache, I have no idea (no idea even what to show here) because it was done by a paid expert like 5 years ago.
Thanks a lot in advance !!
That is an httpd error message, not an Apache Tomcat one. It looks like something (can't tell what from the information provided) has broken the reverse proxy from httpd to Tomcat. You need to talk to whoever set up the reverse proxy for you.

Apache and Tomcat Integration

I'm fairly new with Apache and Tomcat, so try to explain me the better you know :P I'm only working in local.
I have one application that needs Tomcat to execute Servlets, so I can type:
http://localhost:8080/rrcapp/xservlet?consult=list01
That works. I also have my webpage running with Apache 2.4, so I can type:
http://localhost:80/websrv/index.htm
That works too. The problem comes when in my index.htm serving in Apache, make a call in an Iframe with Chrome, to that Servlet, getting the error:
Refused to display ...in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
I've read about setting in my httpd.conf to unset x-frame-options or setting with ALLOW-FROM but it seems just doesn't work with Chrome.
Then, I've read about CSP policies, but I cannot figure out how to set this kind of policy in mi httpd.conf so I can run servlets inside the iframe, inside my Apache server.
Can anyone help me with this?
Regards :)
EDIT 1:
Thanks Eddie James Carswell II I understood the error came from the Tomcat. I've read the document he showed me, and tried to configure my web.xml inside my /conf dir in Tomcat, this is the result:
<filter>
<filter-name>httpHeaderSecurity</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>antiClickJackingEnabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>antiClickJackingOption</param-name>
<param-value>ALLOW-FROM</param-value>
</init-param>
<init-param>
<param-name>antiClickJackingUri</param-name>
<param-value>http://localhost:80/*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>httpHeaderSecurity</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
I restarted the Tomcat server and tried again to load the Iframe and got another error:
Invalid 'X-Frame-Options' header encountered when loading 'http://localhost:8080/rrcapp/xservlet?consult=list01': 'ALLOW-FROM http://localhost:80/*' is not a recognized directive. The header will be ignored.
EDIT 2:
It seems it works on the most recent version of Firefox (57.0 Quantum) as well in IE 10 and EDGE. Still, it doesnt work with Chrome :P
Maybe ALLOW-FROM has some problems with Chrome, but if I'm not wrong, I cannot establish CSP directives in Tomcat. How can I resolve this on Chrome?
Any help here? :)
Thanks in advance
Firstly, I want to thanks to Eddie James Carswell II, who assisted me with this issue all the time, giving me very valuable tips.
Finally, I got it with Proxys via httpd. As stated in the article linked, uncommenting this lines:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
And then configuring my app directory in Apache:
ProxyRequests Off
ProxyPass /rrcapp http://localhost:8080
ProxyPassReverse /rrcapp http://localhost:8080
<Location "/rrcapp">
Order allow,deny
Allow from all
</Location>
Now, I can write in a JS call,. Example:
document.location = '/rrcapp/xservlet?consult=list01';
And access to my apps resources, located in Tomcat.
Why this solution? Its universal in every browser, and easy to configure.
Why not the other one? It worked on the most recent version of Firefox (57.0 Quantum) as well in IE 10 and EDGE. Still, it didn't work with Chromem, wich is the browser I use. The configuration anyways set up, was this in the web.xml in Tomcat directory.
<filter>
<filter-name>httpHeaderSecurity</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>antiClickJackingEnabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>antiClickJackingOption</param-name>
<param-value>ALLOW-FROM</param-value>
</init-param>
<init-param>
<param-name>antiClickJackingUri</param-name>
<param-value>http://localhost:80/*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>httpHeaderSecurity</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
Hope this helps in the future :)
Thanks Eddie!

Custom Error Page when servlet is not reachable (tomcat8)

I'm running Tomcat 8.0.21 with java 1.8.0_40
I'm trying to create a costum error page, which should be displayed when I redeploy my application and the servlet is not reachable.
The obvious solution adding:
<error-page>
<error-code>404</error-code>
<location>/ErrorHandler/404.html</location>
</error-page>
to the <tomcatDir>/conf/web.xml won't work here since tomcat always seems to look for the error page in the same servlet. (so e.g. if calling <url>/idonotexist he uses the 404.html located in ROOT/ErrorHandler/404.html and not in ErrorHandler/404.html as I would have expected) If the webapp is down (stopped via the manager app, or due to maintenance) the error page is blank.
If I remove the lines from the <tomcatDir>/conf/web.xml the default tomcat 404 error message is shown though. Is there any possibility to change the default error handling of tomcat?
edit:
ErrorHandler is a deployed webapp with the following web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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"
version="2.4">
<display-name>Error Application</display-name>
<description>
A webapp for error handling
</description>
<!-- servlet definition -->
<servlet>
<servlet-name>ErrorHandler</servlet-name>
<servlet-class>ErrorHandler</servlet-class>
</servlet>
<!-- servlet mappings -->
<servlet-mapping>
<servlet-name>ErrorHandler</servlet-name>
<url-pattern>/ErrorHandler</url-pattern>
</servlet-mapping>
</web-app>
If I call <tomcatUrl>/ErrorHandler/404.html in my browser I can view the error page just fine.

JSESSIONID added to URL when Weblogic redirects to Apache?

Our application is running on WebLogic.
At some point the WebLogic is redirecting to Apache to allow the user to access PDF files.
This happens via:
final String encodedURL = resp.encodeRedirectURL(redirectURL);
resp.sendRedirect(encodedURL); //ok here because redirection to other server and not to itself
The problem is that WebLogic appends a JSESSIONIDto the URL and the apache fails to serve the PDF Document.
How can I prevent WebLogic from adding the JSESSIONID to the URL?
The whole point en encodeRedirectURL is to include the session ID in the URL if necessary. f you think it's not necessary to include it, don't encode the URL:
resp.sendRedirect(redirectURL);
the problem was, that in our weblogic.xml cookies were disabled:
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
<session-descriptor>
<cookies-enabled>false</cookies-enabled>
</session-descriptor>
whe solved the issue by setting them to true. in this special application, this was not a problem:
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
<session-descriptor>
<cookies-enabled>true</cookies-enabled>
</session-descriptor>
Adding this to my Facelets based application's web.xml avoids JSESSIONID:
<session-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>

Configure domain-wide WebLogic error page

In WebLogic, there's a way to customize standard error pages like HTTP 404 inside the web applications using web.xml
<web-app xmlns="http://java.sun.com/xml/ns/j2ee">
<error-page>
<error-code>404</error-code>
<location>errors/404.htm</location>
</error-page>
</web-app>
Is there a way to configure default domain-wide error page for all the applications WebLogic has running without editing web.xml? Would it be possible to capture the 404 in Apache and serve a common error page?
I don't know of a way to set the 404 page domain-wide (I doubt there is a way since this is intended to be provided separately by each app).
However, you can catch it from the web-tier. For Apache, you can use the ErrorDocument directive. For example, ErrorDocument 404 /404.html
It's possible to define an error page in Apache WebLogic plugin:
http://download.oracle.com/docs/cd/E12840_01/wls/docs103/plugins/apache.html