Want to create custom error page for Grizzly server - grizzly

We want custom error pages has to be served whenever there is an error, because default error page provides too much information which we don't want. Please provide document for the same, if any.
Grizzly server version: 2.3.16
thanks in advance

Please use the following:
server.getServerConfiguration().setDefaultErrorPageGenerator(...);

Note that in order to get the ErrorPageGenerator working, you need to attach it to the server configuration before Grizzly server is started.
So you should be doing something like that:
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(
baseUri,
resourceConfig,
false // so Grizzly won't start automatically
);
httpServer.getServerConfiguration().setDefaultErrorPageGenerator(...);
httpServer.start();

Related

Is there a way to hide Grizzly server version when displaying error pages?

Is there a way to hide Grizzly server version when displaying error pages for security reasons. Also could you point me document for configuring Grizzly server. Not able to find from https://grizzly.java.net.
Grizzly server version: 2.3.16.
thanks in advance.
please do the following:
httpServer.getServerConfiguration().setHttpServerVersion("");

Wildfly Undertow HTTP Response 200 but no content

I am developing a simple web service using Eclipse Java EE IDE for Web Developers : Version: Kepler Service Release 2 Build id: 20140224-0627 and Wildfly-8.2.0.Final. I chose wildfly-javaee7-webapp-blank-archetype using Maven and started development. Firstly, there was no problem, I could add some simple jsp pages and also a simple html page with some images and javascript inclusion then I could deployed, launched and accessed those pages by browser. But all of a sudden, Wildfly (I guess Undertow maybe?) started to response with HTTP response 200 with no content... I really don't get what is going on. I also did rollback my sources to the very early simple pages only. But still the symptoms are the same. Also I have tried to use newer version of Wildfly-9.0.1.Final and deployed manually but I haven't seen any difference.
ex1) this is ok. (Of course browsers take care of this...)
ex2) this kind of contents won't be loaded and sent back as content 0...
I doubted local path issue but I haven't changed anything and it was loaded earlier.
It would be really appreciated if somebody could give me a solution.
Finally I have solved this problem. I have found a problem on a servlet I have added at last. Actually I was trying to migrate my web service running on glassfish and did migrate files one by one. I specified a URL to be handled by the servlet in Web.xml when it run on glassfish. But somehow, it's not working on Wildfly which means all URL request are unexpectedly handled by the servlet... Since I have no idea to specify url to be handled by the specific servlet in Web.xml for Wildfly, I decided to filter request URL in the servlet code. So it is working now. Thank you guys trying to help me...

spring-boot fronted with Apache and AJP

There are a lot of documents out there explaining that you should use various other things (including simple proxying) but AJP is flexible and fast, and it really helps me integrate our SAML2 SSO without any of the webapps having to worry about any of that.
I am now trying to get a spring-boot application working the same way and having a really terrible time of it. The main symptom is "Bad Gateway" with error messages like:
[error] ajp_get_reply::jk_ajp_common.c (2126): (boot_worker_1) Tomcat
is down or refused connection. No response has been sent to the client
(yet)
[info] ajp_service::jk_ajp_common.c (2623): (boot_worker_1) sending
request to tomcat failed (recoverable), because of protocol error
(attempt=1)
[error] ajp_connection_tcp_get_message::jk_ajp_common.c (1289): wrong
message format 0x4854 from 127.0.0.1:8092
The last one seemed like a clue but I have not been able to find it.
The spring boot manual seems to suggest that if you only have a single connection you can set it up in application.properties - this is what I would ideally like to do, but I haven't been able to find any examples of this. From a distribution point of view, though, this seems ideal - publish a jar, give the user a documented properties file.
Since that didn't work, I tried doing it programmatically like this:
#Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
Connector ajpConnector = new Connector();
ajpConnector.setProtocol("AJP/1.3");
ajpConnector.setPort(8092);
ajpConnector.setSecure(false);
ajpConnector.setAllowTrace(false);
ajpConnector.setScheme("http");
tomcat.addAdditionalTomcatConnectors(ajpConnector);
return tomcat;
}
(I'd really rather not get into having to configure SSL for a localhost connection because it just complicates things, and once you spend time in the unsecured worlds of zookeeper, kafka, etc. you kind of give up after a while and figure your ESB is RFC1918 and firewalled anyway).
My questions are:
1) Can this all really be done with the properties file, and how?
2) With the above hard-coded configuration, I can telnet to port 8092 and issue GET requests ... I'm not sure why I can do this, because these GETs are http and I have configured the protocol to AJP/1.3 so I don't THINK it should work. But is that the problem Apache is having? I can't find any explanation of "wrong message format 0x4854" or error "-11."
--Chris
i had the same problem and resolve it by adding the connector implementation.
for example :
Connector ajpConnector = new Connector("org.apache.coyote.ajp.AjpNioProtocol");
list of available implementations :
https://tomcat.apache.org/tomcat-8.0-doc/config/ajp.html#Common_Attributes
(protocol)
or simply specify the protocol (AJP instead of HTTP):
Connector ajpConnector = new Connector("AJP/1.3");
For complete example to dynamically read values from properties file please see https://blog.swdev.ed.ac.uk/2015/06/24/adding-embedded-tomcat-ajp-support-to-a-spring-boot-application/

How to load cache the data present in a table during server start up

I am developing a java web application in which I want to cache all the data present in a table during server start up.
Also if there are any changes in DB values, I wish to refresh the cache (without restarting the server).
I am looking for some material in spring which may help me in achieving that. But I am not able to figure it out.
Please help how can I achieve the same. Also I would like to initialize some beans on server start up.
To start with read the following docs which will get you started.
Refer to Spring document http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/cache.html
Also check this simple tutorial http://viralpatel.net/blogs/cache-support-spring-3-1-m1/
Regarding your bean initialization you can use #PostConstruct annotation on a method of the bean class. Spring will call that method after the bean is constructed.
The application that your planning to build wouldnt be an easy one. In my experience, creating an application like that would require a knowledge of the following:
1. Spring
2. Ehcache
3. JMX
4. Servlet Listeners

glassfish 3.1.2 monitoring EJB container, bean-methods

the glassfish application server provides a nice monitoring REST interface.
To use it u can enable several monitorable items in the admin console, for example the EJB container. The documentation says, you can retreive EJB-statistics for every deployed application.
If you request a URL like localhost:4848/monitoring/domain1/server/applications/APPNAME/EJBNAME you will get statistics for a given EJB of the application.
Further, there is a possibility to look more deeply into each bean-method of the ejb, for example the executiontime, about which the documentation says:
"Time, in milliseconds, spent executing the method for the last successful/unsuccessful attempt to run the operation. This is collected for stateless and stateful session beans and entity beans if monitoring is enabled on the EJB container."
The problem now is, monitoring is enabled on the EJB-container (Level set to HIGH), but nothing is sampled in any bean-method in any EJB in any deployed application.
Is there something special to do in the bean and/or the glassfish ?
Thanks in advance for help,
Chris
EDIT:
Ok, I noticed something more about that behaviour:
In the server log you get a log message for each deployed EJB like that:
INFO: EJB5181:Portable JNDI names for EJB DataFetcher // ...
If I set the ejb-container monitoring level to HIGH (which is what I want to do), I get the following warning for each deployed EJB, regardless which app I deploy:
WARNING: MNTG0201:Flashlight listener registration failed for listener class : com.sun.ejb.monitoring.stats.StatelessSessionBeanStatsProvider , will retry later
I googled the warning but none of the resulst really help me enabling EJB monitoring...
This seems to be a Bug in Glassfish.
EJB Monitoring is currently not working in 3.1.2.
JIRA issue is already raised: http://java.net/jira/browse/GLASSFISH-19677
There is nothing "special" to do.
http://docs.oracle.com/cd/E18930_01/html/821-2431/abeea.html
For me it seems as if you probably enabled the monitoring option on the wrong configuration. Please double check.
To get rid of this message you can disable the monitoring on ejb container option below in the image
From Monitor Data--->Configure monitoring--->make ejb container log off

Resources