Custom 500 error page not working with JBoss AS 7.1.1 - jboss7.x

I have a JAX-RS application deployed on JBoss AS 7.1.1.
In the web.xml file I configured custom error pages:
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
It's working ok for 404 (no found) errors.
However, for 500 (internal server error), it doesn't work as expected:
if my method throws an Exception, then my custom error page is displayed
however, if I use in my method return Response.serverError.build()
or return Response.status(500).build() then the default JBoss error page is displayed instead of my custom one!
How can I fix this?
Thank you for your answers.

ExceptionMapper impl class catches the exception instead of letting the custom error page to be resolved from web.xml
The resolution would be to remove the ExceptionMapper impl class.

Related

Swagger UI integration with Camel ...not able to access index.html on port

I'm using Camel to integrate Swagger. I downloaded dist folder renamed to swagger and updated index.html but I'm not able to access ui it through my application port: http://localhost:${port}/${contextPath}/swagger/index.html
but if I type http://localhost:${port}/api-doc, I get the swagger json dump.
I can access index.html if go to the file and open it manually with browser. How do i access index.html using my application port?
http://localhost:${port}/${contextPath}/swagger/index.html
You need to expose an endpoint that would return your index.html file. Try adding the following to your RouteBuilder:
rest("/swagger")
.produces("text/html")
.get("/index.html")
.responseMessage().code(200).message("Swagger UI").endResponseMessage()
.to("direct://get/swagger/ui/path");
from("direct://get/swagger/ui/path")
.routeId("SwaggerUI")
.setBody().simple("resource:classpath:/swagger/index.html");
The first route defines a restful endpoint /swagger/index.html that accepts a GET request and returns text/html.
The second route uses Camel's Simple component to read the actual index.html into the Exchange Message Body.
So if you go to localhost:${port}/${contextPath}/swagger/index.html, it should load the index.html file correctly.
Note that inside indext.html you need to substitute the URL that would return the JSON dump of your API so that the Swagger UI can render it.
I am using Camel Jetty as the REST component. For jetty you just need add an additional ResourceHandler to handle SwaggerUI resource. Below using Spring xml language to configure REST:
<restConfiguration component="jetty" host="{{rest_hostname}}" port="{{rest_listen_port}}"
bindingMode="off" apiContextPath="api-docs" apiContextListing="true"
enableCORS="true">
<!--ResourceHandler to handle Swagger UI contents on the jetty-->
<endpointProperty key="handlers" value="swaggerUIHandler"/>
......
......
</restConfiguration>
I use swaggerUI in a jar provided by webjars. Configure handler bean:
<bean id="swaggerUIHandler" class="com.yifanwu.examples.camel.JettyResourceHandlerFactory" factory-method="buildResourceHandler">
<!--your resource path is just "swagger" assuming it is on the classpath-->
<constructor-arg name="resourcePath" value="META-INF/resources/webjars"/>
</bean>
Bean factory:
public class JettyResourceHandlerFactory {
public static ResourceHandler buildResourceHandler(String resourcePath) throws Exception {
ResourceHandler rh = new ResourceHandler();
rh.setResourceBase(JettyResourceHandlerFactory.class.getClassLoader()
.getResource(resourcePath)
.toURI().toString());
return rh;
}
}
Full example Here: github
An easier solution would be to add a web.xml file, move your resources to your /webapp directory, adding the following filter in web.xml
<filter>
<filter-name>RestSwaggerCorsFilter</filter-name>
<filter-class>org.apache.camel.swagger.servlet.RestSwaggerCorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RestSwaggerCorsFilter</filter-name>
<url-pattern>/api-docs/*</url-pattern>
<url-pattern>/rest/*</url-pattern>
</filter-mapping>
See the Camel Swagger documentation for details: http://camel.apache.org/swagger-java.html

How Can we call Http request inside tomcat Valve

I want to hit restfull api inside tomcat valve. I create tomcat valve successfully using this link [How to create tomcat valve ][1]
[1]: Verify header before request receive in tomcat .Now i want to authorized headers inside valve. In my application There is restful web service for authorized token. I used spring rest template for hit webservice but when i restart tomcat when is show me error multivaluedmap class not found ,but same code run in simple java application.After this I used Apache http client for hit rest web service (code is ok) . But when i restart tomcat there is again exception : java.lang.NoClassDefFoundError: org/apache/http/client/ClientProtocolException
I simple want to authorized header inside tomcat valve so anyone can suggest to me how can i hit restfull api inside tomcat valve.
I think you should try with tomcat class loader .These Exception occur when these class not loaded. So you should load these class on runtime with the help tomcat class loader.
java.lang.NoClassDefFoundError:
org/apache/http/client/ClientProtocolException
It means this class not found . You should be add required jar files in tomcat.It is helpful for loading the class on runtime.

WSO2 Identity Server - Cannot Configure Custom Catch-all Exception Page

WSO2 Identity Server 5.0.0
For things such as a 500 errors and anything unforeseen, I'd like to configure my Identity Server instance to have our own branded error page to hide the server technology for security reasons and also just allow the error a little confusion.
At any rate, this no help: https://docs.wso2.com/display/IS500/Customizing+Error+Messages
I tried editing /repository/conf/tomcat/carbon/WEB-INF/web.xml and added the standard way to define an error page for exceptions:
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/NiceError.jsp</location>
</error-page>
and then placed NiceError.jsp in /repository/conf/tomcat/carbon/
So when I make a 500 error reoccurr, things change, but I'm sent to the carbon management console login page. If I decide to login, I get served up with an 405 error like so:
HTTP Status 405 - HTTP method GET is not supported by this URL
type Status report
message HTTP method GET is not supported by this URL
description The specified HTTP method is not allowed for the requested resource.
Apache Tomcat/7.0.55
The URL looks like: https://hostname:9443/NiceError.jsp?sessionDataKey=eabd6c25-7c79-40a9-af87-3cd80a68367e&loginStatus=true
That doesn't help.
How can this kind of thing be setup to work? It can't be hard with the right information. Right? :)
The referred documentation page is to customize error messages for identity related errors as its name sounds. It is not to create custom error pages.
By the way if you need to create custom error page, which is applicable to all web applications in your server instance, you may need to add your error page to web.xml in /repository/conf/tomcat/ directory. It defines default values for all web applications loaded into your instance of Tomcat. As each application get deployed, above file is processed, followed by the /WEB-INF/web.xml deployment descriptor from your own applications.
Thanks

What is the right way to handle error pages in moqui

To redirect user to an error page I am adding entry in web.xml for 401 (Unauthorized) error code. But I don't find it correct. As, I am adding following code in web.xml which is in framework.
<error-page>
<error-code>401</error-code>
<location>/myapp/Error/Error401.html</location>
</error-page>
And, What if there are more than one component in my application and I want to redirect on different error pages on same error code as per component. Please guide me as to how can I achieve the same?
Thanks in advance.

Error Page Not Shown - when wrong context root is given

I have one application deployed on JBoss 7.x under the context root "helloworld" that has:
welcome.jsp and error.jsp.
The custom error page specified in the web.xml DD as:
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
when I access the page as:
http://localhost:8080/helloworld/welcome.jsp
I get the page as expected.
http://localhost:8080/helloworld/welcome_does_not_exist.jsp
takes me to:
http://localhost:8080/helloworld/error.jsp
however
http://localhost:8080/helloworld_DOES_NOT_EXIST/welcome.jsp
does not take me to the custom error page but shows:
========
HTTP Status 404 - /helloworld_DOES_NOT_EXIST/welcome.jsp
type Status report
message /helloworld_DOES_NOT_EXIST/welcome.jsp
description The requested resource (/helloworld_DOES_NOT_EXIST/welcome.jsp)
is not available.
JBoss Web/7.0.13.Final
=========
Could you please let me know how to set the error page so that even when we specify the wrong context root we get the custom error page?
Thanks.