I ran into an issue that I want to put up on the board for consideration to fixing in future versions, this is in the border-land between bug and feature so I'd much like this improvement in 2.1
* Improved hot deployment functionality with regards to registered MBeans
We are experiencing problems in hot deploying applications which have registered their own custom MBeans. Where we are in control of our own MBeans this might not be a bit problem since we can then do an unregister and then a register again. The problematic situation is where we have thirdparty libraries which register the MBeans and we have no control of the source code.
A possible design in glassfish to solve this situation is to make use of an AOP framework to intercept the calls to “registerMBean / createMBean” and setup some context information which mbeans an application has registered and when undeploying it also unregister the MBeans that this app has registered. It’s a quite nice and elegant solution in my mind.
Here is some sample code to demonstrate the problem. Make a war with this and access the servlet once, then redeploy and access it again, it will fail. This is perhaps not a major issue if the code is your own, then just write a manual unregister/register. But the big problem is with thirdparty libraries which are less than optimally written. In all I think GF has a small blame in this and that the application sandbox is not perfect eventough this is in the land outside of the specifications.
/**
* Very Simple test servlet to test compression filter
* @author Amy Roh
* @version $Revision: 1.3 $, $Date: 2006/10/12 14:31:29 $
*/
public class CompressionFilterTestServlet extends HttpServlet {
private static interface DummyMBean
{
public String getName();
public void setName(String val);
}
private static class Dummy implements DummyMBean
{
private String name = "Kalle";
public String getName() { return name; }
public void setName(String val) { name = val; }
}
Dummy mbean;
public CompressionFilterTestServlet()
{
System.out.println("HejsanHoppsan!");
try {
MBeanServer srv = ManagementFactory.getPlatformMBeanServer();
mbean = new Dummy();
ObjectName name = ObjectName.getInstance("netent:type=dummy,name=kalle");
srv.registerMBean(mbean, name);
} catch (InstanceAlreadyExistsException ex) {
Logger.getLogger(CompressionFilterTestServlet.class.getName()).log(Level.SEVERE, "Not good, instance already exists", ex);
} catch (Exception ex) {
Logger.getLogger(CompressionFilterTestServlet.class.getName()).log(Level.SEVERE, "Not good", ex);
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletOutputStream out = response.getOutputStream();
response.setContentType("text/plain");
Enumeration e = ((HttpServletRequest)request).getHeaders("Accept-Encoding");
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
out.println(name);
if (name.indexOf("gzip") != -1) {
out.println("gzip supported -- able to compress");
}
else {
out.println("gzip not supported");
}
}
out.println("Compression Filter Test Servlet");
out.close();
}
}
[Message sent by forum member 'jesper_soderlund' (jesper_soderlund)]
http://forums.java.net/jive/thread.jspa?messageID=245814