Java tutorial
/** * PureInfo Quake * @(#)WebConfigSetAction.java 1.0 2006-2-14 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.srmcenter.datasync.client.config.action; import java.io.File; import java.io.FileNotFoundException; import java.util.Properties; import org.apache.commons.httpclient.ProxyHost; import org.apache.struts.action.ActionForward; import com.pureinfo.ark.interaction.ActionBase; import com.pureinfo.force.PureFactory; import com.pureinfo.force.PureSystem; import com.pureinfo.force.exception.PureException; import com.pureinfo.force.exception.PureRuntimeException; import com.pureinfo.force.io.ClassResourceUtil; import com.pureinfo.force.lang.PropertiesUtil; import com.pureinfo.force.net.impl.HttpUtilImpl; import com.pureinfo.force.runtime.engine.EngineBean; import com.pureinfo.force.runtime.engine.EngineServer; import com.pureinfo.srmcenter.datasync.client.SyncClientConstants; /** * <P> * Created on 2006-2-14 11:11:36 <BR> * Last modified on 2006-2-14 * </P> * * * @author wind * @version 1.0, 2006-2-14 * @since Quake 1.0 */ public class WebConfigSetAction extends ActionBase { /** * @see com.pureinfo.ark.interaction.ActionBase#executeAction() */ public ActionForward executeAction() throws PureException { String sFileName = ClassResourceUtil.mapFullPath("plugin/system/system-datasync.properties", true); File file = new File(sFileName); if (!file.getParentFile().exists()) file.mkdir(); Properties props = new Properties(); props.put("sync.server.host", request.getRequiredString("serverHost", true, "")); props.put("sync.active.start.time", request.getRequiredString("activeTime", true, "")); props.put("sync.upload.start.time", request.getRequiredString("uploadTime", true, "")); props.put("sync.download.start.time", request.getRequiredString("downloadTime", true, "")); props.put("sync.proxy.host", request.getString("proxyHost", true)); props.put("sync.proxy.port", request.getString("proxyPort", true)); props.put("sync.proxy.user", request.getString("proxyUser", true)); props.put("sync.proxy.password", request.getString("proxyPassword", true)); props.put("sync.count.per.time", request.getRequiredString("countPerTime", true, "")); props.put("sync.retry.times", request.getRequiredString("retryTimes", true, "")); try { PropertiesUtil.storeToFile(props, file); PureSystem.getProperties().putAll(props); } catch (FileNotFoundException ex) { throw new PureException(PureException.UNKNOWN, "", ex); } finally { props.clear(); } setProxy(); // restart engine restartEngine(); return mapping.findForward("success"); } private void restartEngine() { String[] sEngines = { "quake.sync.data.download", "quake.sync.data.update", "quake.sync.data.active" }; EngineServer server = EngineServer.getInstance(); for (int i = 0; i < sEngines.length; i++) { EngineBean engine = server.getEngineBean(sEngines[i]); if (engine == null) { logger.error("engine:\"" + sEngines[i] + "\" is not exist!"); } try { engine.getEngine(false).restart(); } catch (PureException ex) { throw new PureRuntimeException(ex.getErrNo(), ex.getMessage(), ex); } } } public static void setProxy() { HttpUtilImpl httpUtil = (HttpUtilImpl) PureFactory.getBean("sync.httpUtil"); String sHost = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_HOST); ProxyHost host = null; if (sHost != null && sHost.length() > 0) { String sPort = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_PORT); if (sPort == null || sPort.length() == 0) { host = new ProxyHost(sHost); } else { int nPort = Integer.parseInt(sPort); host = new ProxyHost(sHost, nPort); } } httpUtil.setProxyHost(host); String sUser = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_USER); httpUtil.setProxyUser(sUser); String sPassword = PureSystem.getProperty(SyncClientConstants.PROPERTY_PROXY_PASSWORD); httpUtil.setProxyPassword(sPassword); } }