1 12 13 package org.ejtools.jmx.browser.web.action; 14 15 16 17 import java.io.IOException ; 18 19 import java.io.PrintWriter ; 20 21 import java.io.StringWriter ; 22 23 import java.util.Locale ; 24 25 26 27 import javax.servlet.ServletContext ; 28 29 import javax.servlet.ServletException ; 30 31 import javax.servlet.http.HttpServletRequest ; 32 33 import javax.servlet.http.HttpServletResponse ; 34 35 36 37 import org.apache.log4j.Logger; 38 39 import org.apache.struts.action.Action; 40 41 import org.apache.struts.action.ActionError; 42 43 import org.apache.struts.action.ActionErrors; 44 45 import org.apache.struts.action.ActionForm; 46 47 import org.apache.struts.action.ActionForward; 48 49 import org.apache.struts.action.ActionMapping; 50 51 import org.apache.struts.util.MessageResources; 52 53 import org.ejtools.jmx.browser.model.Resource; 54 55 import org.ejtools.jmx.browser.web.Constants; 56 57 import org.ejtools.jmx.browser.web.JMXContainer; 58 59 60 61 76 77 public class UnregisterAction extends Action 78 79 { 80 81 82 83 private static Logger logger = Logger.getLogger(UnregisterAction.class); 84 85 86 87 88 89 90 91 public UnregisterAction() { } 92 93 94 95 96 97 118 119 public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 120 121 throws IOException , ServletException  122 123 { 124 125 String reference = null; 126 127 128 129 131 Locale locale = getLocale(request); 132 133 MessageResources messages = getResources(); 134 135 136 137 139 ActionErrors errors = new ActionErrors(); 140 141 142 143 reference = request.getParameter("reference"); 144 145 logger.debug("ObjectName requested " + reference); 146 147 148 149 ServletContext context = this.getServlet().getServletContext(); 150 151 JMXContainer tree = (JMXContainer) context.getAttribute(Constants.TREE); 152 153 154 155 if (tree != null) 156 157 { 158 159 logger.debug("Tree root found => " + tree); 160 161 Resource res = (Resource) tree.searchObjectName(reference); 162 163 164 165 if (res != null) 166 167 { 168 169 try 170 171 { 172 173 res.unregisterMBean(); 174 175 } 176 177 catch (Exception e) 178 179 { 180 181 logger.error("Exception occured " + e.getMessage()); 182 183 184 185 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("web.error.mbean.unregister", reference)); 186 187 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("web.error.exception.message", e.getMessage())); 188 189 190 191 StringWriter w = new StringWriter (); 192 193 PrintWriter pw = new PrintWriter (w); 194 195 e.printStackTrace(pw); 196 197 pw.close(); 198 199 200 201 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("web.error.exception.stack", w.toString())); 202 203 } 204 205 } 206 207 else 208 209 { 210 211 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("web.error.no.mbean")); 212 213 } 214 215 } 216 217 else 218 219 { 220 221 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("web.error.cannot.connect")); 222 223 } 224 225 226 227 229 if (!errors.empty()) 230 231 { 232 233 saveErrors(request, errors); 234 235 return (mapping.findForward("error")); 236 237 } 238 239 240 241 return (mapping.findForward("view")); 242 243 } 244 245 } 246 247 248 249
| Popular Tags
|