1 16 17 package org.apache.webapp.admin.connector; 18 19 import java.io.IOException ; 20 import java.util.Collections ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 import java.util.Locale ; 24 import java.util.TreeSet ; 25 import java.util.Set ; 26 import java.util.ArrayList ; 27 import javax.servlet.ServletException ; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 import javax.servlet.http.HttpSession ; 31 import org.apache.struts.action.Action; 32 import org.apache.struts.action.ActionErrors; 33 import org.apache.struts.action.ActionForm; 34 import org.apache.struts.action.ActionForward; 35 import org.apache.struts.action.ActionMapping; 36 37 import javax.management.MBeanServer ; 38 import javax.management.MBeanServerFactory ; 39 import javax.management.QueryExp ; 40 import javax.management.Query ; 41 import javax.management.ObjectInstance ; 42 import javax.management.ObjectName ; 43 import javax.management.JMException ; 44 import org.apache.struts.util.MessageResources; 45 46 import org.apache.webapp.admin.ApplicationServlet; 47 import org.apache.webapp.admin.TomcatTreeBuilder; 48 49 55 56 public class DeleteConnectorAction extends Action { 57 58 61 private MBeanServer mBServer = null; 62 63 64 65 66 67 69 84 public ActionForward execute(ActionMapping mapping, 85 ActionForm form, 86 HttpServletRequest request, 87 HttpServletResponse response) 88 throws IOException , ServletException { 89 90 91 HttpSession session = request.getSession(); 93 Locale locale = getLocale(request); 94 MessageResources resources = getResources(request); 95 96 try { 98 mBServer = ((ApplicationServlet) getServlet()).getServer(); 99 } catch (Throwable t) { 100 throw new ServletException 101 ("Cannot acquire MBeanServer reference", t); 102 } 103 104 String domain = null; 105 ConnectorsForm connectorsForm = new ConnectorsForm(); 108 String select = request.getParameter("select"); 109 if (select != null) { 110 String connectors[] = new String [1]; 111 connectors[0] = select; 112 connectorsForm.setConnectors(connectors); 113 114 try { 116 domain = (new ObjectName (select)).getDomain(); 117 } catch (Exception e) { 118 throw new ServletException 119 ("Error extracting service name from the connector to be deleted", e); 120 } 121 } 122 request.setAttribute("connectorsForm", connectorsForm); 123 124 ArrayList list = new ArrayList (); 126 try { 127 String pattern = domain + TomcatTreeBuilder.CONNECTOR_TYPE + 128 TomcatTreeBuilder.WILDCARD; 129 Iterator items = 130 mBServer.queryNames(new ObjectName (pattern), null).iterator(); 131 while (items.hasNext()) { 132 Object item = items.next(); 133 list.add(item.toString()); 134 } 135 } catch (Exception e) { 136 getServlet().log 137 (resources.getMessage(locale, "users.error.select")); 138 response.sendError 139 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 140 resources.getMessage(locale, "users.error.select")); 141 return (null); 142 } 143 Collections.sort(list); 144 request.setAttribute("connectorsList", list); 145 146 return (mapping.findForward("Connectors")); 148 } 149 } 150 | Popular Tags |