1 16 17 package org.apache.webapp.admin.resources; 18 19 import java.io.IOException ; 20 import java.net.URLDecoder ; 21 import java.util.Iterator ; 22 import java.util.Locale ; 23 import javax.management.Attribute ; 24 import javax.management.AttributeNotFoundException ; 25 import javax.management.MBeanServer ; 26 import javax.management.MBeanServerFactory ; 27 import javax.management.QueryExp ; 28 import javax.management.Query ; 29 import javax.management.ObjectInstance ; 30 import javax.management.ObjectName ; 31 import javax.management.JMException ; 32 import javax.management.MBeanAttributeInfo ; 33 import javax.management.MBeanOperationInfo ; 34 import javax.management.MBeanInfo ; 35 import javax.servlet.ServletException ; 36 import javax.servlet.http.HttpServletRequest ; 37 import javax.servlet.http.HttpServletResponse ; 38 import javax.servlet.http.HttpSession ; 39 import org.apache.struts.action.Action; 40 import org.apache.struts.action.ActionErrors; 41 import org.apache.struts.action.ActionForm; 42 import org.apache.struts.action.ActionForward; 43 import org.apache.struts.action.ActionMapping; 44 import org.apache.struts.util.MessageResources; 45 import org.apache.webapp.admin.ApplicationServlet; 46 47 48 58 59 public final class SetUpDataSourceAction extends Action { 60 61 63 64 67 private MBeanServer mserver = null; 68 69 70 72 73 88 public ActionForward execute(ActionMapping mapping, 89 ActionForm form, 90 HttpServletRequest request, 91 HttpServletResponse response) 92 throws IOException , ServletException { 93 94 if (mserver == null) { 96 mserver = ((ApplicationServlet) getServlet()).getServer(); 97 } 98 MessageResources resources = getResources(request); 99 HttpSession session = request.getSession(); 100 Locale locale = getLocale(request); 101 102 String objectName = request.getParameter("objectName"); 104 String resourcetype = request.getParameter("resourcetype"); 105 String path = request.getParameter("path"); 106 String host = request.getParameter("host"); 107 String domain = request.getParameter("domain"); 108 109 DataSourceForm dataSourceForm = new DataSourceForm(); 110 dataSourceForm.setResourcetype(resourcetype); 111 dataSourceForm.setPath(path); 112 dataSourceForm.setHost(host); 113 dataSourceForm.setDomain(domain); 114 dataSourceForm.setType(ResourceUtils.DATASOURCE_CLASS); 115 116 if (objectName == null) { 117 dataSourceForm.setNodeLabel 118 (resources.getMessage(locale, "resources.actions.datasrc.create")); 119 dataSourceForm.setObjectName(null); 120 dataSourceForm.setActive("4"); 121 dataSourceForm.setIdle("2"); 122 dataSourceForm.setWait("5000"); 123 dataSourceForm.setType(ResourceUtils.DATASOURCE_CLASS); 124 125 } else { 126 dataSourceForm.setNodeLabel 127 (resources.getMessage(locale, "resources.actions.datasrc.edit")); 128 dataSourceForm.setObjectName(objectName); 129 130 String attribute = null; 131 try { 132 ObjectName oname = new ObjectName (objectName); 133 try { 134 attribute = "name"; 135 dataSourceForm.setJndiName 136 ((String ) mserver.getAttribute(oname, attribute)); 137 attribute = "url"; 138 dataSourceForm.setUrl 139 ((String ) mserver.getAttribute(oname, attribute)); 140 attribute = "driverClassName"; 141 dataSourceForm.setDriverClass 142 ((String ) mserver.getAttribute(oname, attribute)); 143 attribute = "username"; 144 dataSourceForm.setUsername 145 ((String ) mserver.getAttribute(oname, attribute)); 146 attribute = "password"; 147 dataSourceForm.setPassword 148 ((String ) mserver.getAttribute(oname, attribute)); 149 attribute = "validationQuery"; 150 dataSourceForm.setQuery 151 ((String ) mserver.getAttribute(oname, attribute)); 152 } catch (AttributeNotFoundException ex) { 153 } 155 try { 156 attribute = "maxActive"; 157 dataSourceForm.setActive 158 ((String ) mserver.getAttribute(oname, attribute)); 159 } catch (AttributeNotFoundException e) { 160 dataSourceForm.setActive("4"); 162 } 163 try { 164 attribute = "maxIdle"; 165 dataSourceForm.setIdle 166 ((String ) mserver.getAttribute(oname, attribute)); 167 } catch (AttributeNotFoundException e) { 168 dataSourceForm.setIdle("2"); 170 } 171 try { 172 attribute = "maxWait"; 173 dataSourceForm.setWait 174 ((String ) mserver.getAttribute(oname, attribute)); 175 } catch (AttributeNotFoundException e) { 176 dataSourceForm.setWait("5000"); 178 } 179 } catch (Exception e) { 180 getServlet().log 181 (resources.getMessage(locale, 182 "users.error.attribute.get", attribute), e); 183 response.sendError 184 (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 185 resources.getMessage 186 (locale, "users.error.attribute.get", attribute)); 187 return (null); 188 } 189 } 190 191 saveToken(request); 193 request.setAttribute("dataSourceForm", dataSourceForm); 194 return (mapping.findForward("DataSource")); 195 196 } 197 } 198 | Popular Tags |