1 16 17 18 package org.apache.webapp.admin.resources; 19 20 import java.io.IOException ; 21 import java.net.URLDecoder ; 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.Locale ; 25 import javax.servlet.ServletException ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 import javax.servlet.http.HttpSession ; 29 import org.apache.struts.action.Action; 30 import org.apache.struts.action.ActionError; 31 import org.apache.struts.action.ActionErrors; 32 import org.apache.struts.action.ActionForm; 33 import org.apache.struts.action.ActionForward; 34 import org.apache.struts.action.ActionMapping; 35 import javax.management.Attribute ; 36 import javax.management.MBeanServer ; 37 import javax.management.MBeanServerFactory ; 38 import javax.management.QueryExp ; 39 import javax.management.Query ; 40 import javax.management.ObjectInstance ; 41 import javax.management.ObjectName ; 42 import javax.management.JMException ; 43 import javax.management.MBeanAttributeInfo ; 44 import javax.management.MBeanOperationInfo ; 45 import javax.management.MBeanInfo ; 46 import org.apache.struts.util.MessageResources; 47 import org.apache.webapp.admin.ApplicationServlet; 48 49 50 58 59 public final class SaveResourceLinkAction extends Action { 60 61 62 64 67 private MBeanServer mserver = null; 68 69 71 72 87 public ActionForward execute(ActionMapping mapping, 88 ActionForm form, 89 HttpServletRequest request, 90 HttpServletResponse response) 91 throws IOException , ServletException { 92 93 if (mserver == null) { 95 mserver = ((ApplicationServlet) getServlet()).getServer(); 96 } 97 MessageResources resources = getResources(request); 98 HttpSession session = request.getSession(); 99 Locale locale = getLocale(request); 100 101 if (isCancelled(request)) { 103 return (mapping.findForward("List ResourceLinks Setup")); 104 } 105 106 if (!isTokenValid(request)) { 108 response.sendError 109 (HttpServletResponse.SC_BAD_REQUEST, 110 resources.getMessage(locale, "users.error.token")); 111 return (null); 112 } 113 114 ResourceLinkForm resourceLinkForm = (ResourceLinkForm) form; 116 String objectName = resourceLinkForm.getObjectName(); 117 118 if (objectName == null) { 120 121 String signature[] = new String [2]; 122 signature[0] = "java.lang.String"; 123 signature[1] = "java.lang.String"; 124 125 Object params[] = new Object [2]; 126 params[0] = resourceLinkForm.getName(); 127 params[1] = resourceLinkForm.getType(); 128 129 String resourcetype = resourceLinkForm.getResourcetype(); 130 String path = resourceLinkForm.getPath(); 131 String host = resourceLinkForm.getHost(); 132 String domain = resourceLinkForm.getDomain(); 133 134 ObjectName oname = null; 135 136 try { 137 138 if (resourcetype.equals("Global")) { 139 oname = new ObjectName ( domain + 140 ResourceUtils.RESOURCELINK_TYPE + 141 ResourceUtils.GLOBAL_TYPE + 142 ",name=" + params[0]); 143 } else if (resourcetype.equals("Context")) { 144 oname = new ObjectName ( domain + 145 ResourceUtils.RESOURCELINK_TYPE + 146 ResourceUtils.CONTEXT_TYPE + 147 ",path=" + path + ",host=" + host + 148 ",name=" + params[0]); 149 } 150 151 if (mserver.isRegistered(oname)) { 152 ActionErrors errors = new ActionErrors(); 153 errors.add("name", 154 new ActionError("resources.invalid.name")); 155 saveErrors(request, errors); 156 return (new ActionForward(mapping.getInput())); 157 } 158 159 oname = ResourceUtils.getNamingResourceObjectName(domain, 160 resourcetype, path, host); 161 162 objectName = (String ) mserver.invoke(oname, "addResourceLink", 164 params, signature); 165 166 } catch (Exception e) { 167 168 getServlet().log 169 (resources.getMessage(locale, "users.error.invoke", 170 "addResourceLink"), e); 171 response.sendError 172 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 173 resources.getMessage(locale, "users.error.invoke", 174 "addResourceLink")); 175 return (null); 176 } 177 178 } 179 180 String attribute = null; 182 try { 183 184 ObjectName oname = new ObjectName (objectName); 185 186 attribute = "global"; 187 mserver.setAttribute 188 (oname, 189 new Attribute (attribute, resourceLinkForm.getGlobal())); 190 attribute = "type"; 191 mserver.setAttribute 192 (oname, 193 new Attribute (attribute, resourceLinkForm.getType())); 194 195 } catch (Exception e) { 196 197 getServlet().log 198 (resources.getMessage(locale, "users.error.set.attribute", 199 attribute), e); 200 response.sendError 201 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 202 resources.getMessage(locale, "users.error.set.attribute", 203 attribute)); 204 return (null); 205 206 } 207 208 return (mapping.findForward("ResourceLinks List Setup")); 210 211 } 212 213 214 } 215 | Popular Tags |