Custom error pages in JBoss 5.0 EAP web applications - java

I'm deploying a web application and I want to have a default 404 page applicable to all my web applications unless stated otherwise in each application web.xml
I've accomplished something changing "jboss-as\server\myapp\deployers\jbossweb.deployer\web.xml" and adding the following
<error-page>
<error-code>404</error-code>
<location>/error404.html</location>
</error-page>
Then all 404 errors I get are redirected to /error404.html without changing each application's web.xml as I wanted.
Anyway the bizarre thing is that each war I'm deploying must have a error404.html copy because it's looking for it in its own context. I tried putting error pages in jboss-as\server\myapp\deploy\ROOT.war and they work for non-defined URLs but not for already defined applications.
Can I have only one copy of my error pages for ALL contexts and that page defined only in one web.xml?
Thanks a lot in advance.

Rafa,
is "myapp" a custom profile you created? If not then try changing the file /jboss/server/all/deployers/jbossweb.deployer/web.xml.
Where "all" is one of the available jboss profiles (all, default, standard, ...).

Related

Tomcat error page issue

I have configured my tomcat6 web.xml to show my custom error page by adding these lines, described here
<error-page>
<error-code>500</error-code>
<location>/web_server_error.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/web_server_error.html</location>
</error-page>
Also I came to know for each application deployed I need to put the same configuration as I did for ROOT, which is fine.
My issue is I have a simple folder webapps/docs. If I try to access any file existing in this folder say /docs/mypage.html, I can access it perfectly but if the file or directory doesn't exist in the folder like docs/faq/ I need the same error page but tomcat is showing its 404 error page.
Actually I need it because my client mention this in a vulnerability list, i.e. in this scenario the attacker can get aware of the file structure so we need to show one page on all errors.
I need to know as it is a simple folder instead of any application how to handle this issue or is it simple impossible?
Any help is highly appreciated.
This is not possible in Tomcat 6. Servlet 3.0 specifies global error pages but Tomcat 6 implements Servlet 2.5.
But it's possible to "workaround" by writing a ErrorReportValve class and register it. But beware: This is Tomcat specific!
The folder is not a web application.so your configure does not work!

Different session IDs for JAX-RS resources

I faced a very strange behavior with WildFly 8.x (tested with 8.1 and 8.0 also). If I deploy my WAR as ROOT (set the '/' as context-root in jboss-web.xml) my JAX-RS resource classes will have different session IDs (each resource class will have a unique session id). But in fact, if I set anything else other than '/' as the context-root everything works as I expected originally (every JAX-RS resource class share the same session).
I know that REST services are stateless and I don't have to worry about sessions but I'm so curious why it behaves like that. Does anyone have any ideas?
Thanks!
Here's a sample minimal project where you can reproduce this issue: https://github.com/aberkes/cdi-sessionscoped-bean-demo
The idea is that by default if you deploy to ROOT, jboss doesn't use a fixed cookie path parameter. This is made for the case, when you have other applications running in different sub-folders and requiring their own independent sessions.
To change this behaviour, you may use the
<session-config>
<cookie-config>
<path>/</path>
</cookie-config>
</session-config>
parameter in your web.xml. Then all jsessions will be bound to the root path.

Wicket mount a 404 error page

Is there way to mount a 404 error page in Wicket-1.5.x without adding:
<error-page>
<error-code>404</error-code>
<location>/NotFound</location>
</error-page>
to my web.xml file?
I have several applications that all use the same/similar Look/Feel. I've extracted out a lot of the common functionality including my error pages to some shared jar files. I'm already mounting a lot of common pages (Login Pages, Error Pages, etc) via an Iinitializer. Is there a way I can do the same for 404 errors?
UPDATE:
In Doing more research I also found this question:
Can I redirect to a valid Wicket page when attempting to access a non-existent page?
Which also seems to state that editing web.xml is the solution.
As I said I have several applications while editing the file isn't hard and there isn't that many, it's one more thing I'll have to remember next time I upgrade them.
If it makes a difference I'm using Tomcat-6.x Is there possibly a way to fake the <error-page> configuration setting in my web.xml by modifying ServletContext?
As far as I know you need those lines in your web.xml, but once you've done that you can still mount your common page along with everything else in your IInitializer:
application.mount(
new QueryStringUrlCodingStrategy("NotFound", NotFoundErrorPage.class));

How to put jsp in ROOT folder of tomcat so that the jsp is picked by all web apps

I have multiple web applications defined in my tomcat. In case of any exception, I want to throw one jsp (done using SimpleMappingExceptionResolver tag of spring). When I put the jsps in the web-inf folder of the web applications, it works fine which is obvious.
But I want to put this jsp at a common place in tomcat such as ROOT library. But if I do this, tomcat is not able to find my jsp. Can somebody tell me if any changes in web.xml is required to make this happen or I should put this jsp somewhere else.
Thanks in advance.
What do you mean by 'picked up' or 'access'? You can put a jsp file on the tomcat ROOT application, and do a 302 redirect into it everytime you encounter exception.
For example place you all-apps generic exception page on webapps/ROOT/generic_exception.jsp, then on each of your apps, add this to the web.xml
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/myapp_error.jsp</location>
</error-page>
That should redirect request into myapp_error.jsp (inside myapp) if any uncaught exception surfaces. Then inside myapp_error.jsp, just perform html meta redirect to /generic_exception.jsp
However the drawback of this approach is you are redirected into different web-app, it's difficult / require extra work if you want to pass session attributes

How to specify html page globally in Jboss?

We have a filter that redirects user to error.html, if the user is not authorized. Right now, we are keeping error.html page inside the WAR, but is there any way to make the html file public so that every war file can access this error page? It would be still better, if we make this html page as a jar and keep it in server/default/lib.
Here is the sample that is used in filter.
`reqDespacher = request.getRequestDispatcher("error.html")`
and the accessing url is
http://localhost/Context_root/error.html
Any help would be appreciated.
In JBoss5 or JBoss6, you can copy and then define this custom error.html inside the /deployer/jbossweb.deployer/web.xml of the server instance that you are running. This will require a reboot of the JBoss instance. Example for error code 404:
<error-page>
<error-code>404</error-code>
<location><relative_path_to_error_html_file_under_jbossweb.deployer_folder></location>
</error-page>
Secondly, instead of re-directing request by specifying a page manually like you are doing currently, you should use the <error-page> and <error-code> deployment directive to define custom error pages. See specify-the-default-error-page-in-web-xml-in-servlet for a detailed example on how to add error-code directives on web.xml.
For JBoss AS7 global error page configuration take a look at how-to-customize-jboss-as7-404-page .

Categories