diff --git a/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java b/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java index d58c6cc7fa..278dfe5ccb 100644 --- a/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java +++ b/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java @@ -1,14 +1,13 @@ package com.fr.design.actions.file; import com.fr.base.BaseUtils; -import com.fr.base.Env; -import com.fr.base.FRContext; -import com.fr.dav.LocalEnv; +import com.fr.base.env.resource.LocalEnvConfig; +import com.fr.base.env.resource.RemoteEnvConfig; +import com.fr.core.env.EnvConfig; import com.fr.design.DesignerEnvManager; import com.fr.design.actions.UpdateAction; import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.tabledata.ResponseDataSourceChange; -import com.fr.design.dialog.InformationWarnPane; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; @@ -18,21 +17,17 @@ import com.fr.design.menu.MenuDef; import com.fr.design.menu.SeparatorDef; import com.fr.env.RemoteEnv; import com.fr.env.SignIn; -import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; import com.fr.general.Inter; import com.fr.log.FineLoggerFactory; import com.fr.stable.EnvChangedListener; -import com.fr.stable.ProductConstants; -import com.fr.stable.StringUtils; -import javax.swing.*; +import javax.swing.JOptionPane; import java.awt.event.ActionEvent; import java.util.HashMap; import java.util.Iterator; import java.util.Map; - public class SwitchExistEnv extends MenuDef { public SwitchExistEnv() { @@ -41,18 +36,20 @@ public class SwitchExistEnv extends MenuDef { this.setHasScrollSubMenu(true); initMenuDef(); JTemplate t = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); - if(t != null) { - GeneralContext.addEnvWillChangedListener(t.getFullPathName(), new EnvChangedListener() { - public void envChanged() { - SwitchExistEnv.this.clearShortCuts(); - initMenuDef(); - } - }); + if (t != null) { + GeneralContext.addEnvWillChangedListener( + t.getFullPathName(), + new EnvChangedListener() { + public void envChanged() { + SwitchExistEnv.this.clearShortCuts(); + initMenuDef(); + } + }); } } private void initMenuDef() { - //ButtonGroup group = new ButtonGroup(); + // ButtonGroup group = new ButtonGroup(); Iterator nameIt = DesignerEnvManager.getEnvManager().getEnvNameIterator(); while (nameIt.hasNext()) { String name = nameIt.next(); @@ -65,15 +62,14 @@ public class SwitchExistEnv extends MenuDef { public static class GetExistEnvAction extends UpdateAction implements ResponseDataSourceChange { public GetExistEnvAction() { - } public GetExistEnvAction(String envName) { this.setName(envName); - Env env = DesignerEnvManager.getEnvManager().getEnv(envName); - if (env instanceof LocalEnv) { + EnvConfig env = DesignerEnvManager.getEnvManager().getEnv(envName); + if (env instanceof LocalEnvConfig) { this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/data/bind/localconnect.png")); - } else if (env instanceof RemoteEnv) { + } else if (env instanceof RemoteEnvConfig) { this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/data/bind/distanceconnect.png")); } } @@ -101,28 +97,24 @@ public class SwitchExistEnv extends MenuDef { */ public void actionPerformed(ActionEvent e) { DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); - Env selectedEnv = envManager.getEnv(this.getName()); + EnvConfig selectedEnv = envManager.getEnv(this.getName()); try { if (selectedEnv instanceof RemoteEnv && !((RemoteEnv) selectedEnv).testServerConnection()) { - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"})); - return; - } - String remoteVersion = selectedEnv.getDesignerVersion(); - if (StringUtils.isBlank(remoteVersion) || ComparatorUtils.compare(remoteVersion, ProductConstants.DESIGNER_VERSION) < 0) { - String infor = Inter.getLocText("Server-version-tip"); - String moreInfo = Inter.getLocText("Server-version-tip-moreInfo"); - FineLoggerFactory.getLogger().error(infor); - new InformationWarnPane(infor, moreInfo, Inter.getLocText("Tooltips")).show(); + JOptionPane.showMessageDialog( + DesignerContext.getDesignerFrame(), + Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"})); return; } SignIn.signIn(selectedEnv); HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().refreshToolArea(); fireDSChanged(); } catch (Exception em) { - FRContext.getLogger().error(em.getMessage(), em); - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"})); + FineLoggerFactory.getLogger().error(em.getMessage(), em); + JOptionPane.showMessageDialog( + DesignerContext.getDesignerFrame(), + Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"})); TemplatePane.getInstance().editItems(); } } } -} \ No newline at end of file +} diff --git a/designer-base/src/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/com/fr/design/mainframe/DesignerFrame.java index d8096aab27..98f7de5f90 100644 --- a/designer-base/src/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/com/fr/design/mainframe/DesignerFrame.java @@ -35,6 +35,7 @@ import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import com.fr.design.menu.MenuManager; import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.event.EventDispatcher; import com.fr.file.FILE; import com.fr.file.FILEFactory; import com.fr.file.FileFILE; @@ -43,8 +44,6 @@ import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.general.GeneralContext; import com.fr.general.Inter; -import com.fr.general.env.EnvContext; -import com.fr.log.FineLoggerFactory; import com.fr.plugin.context.PluginContext; import com.fr.plugin.injectable.PluginModule; import com.fr.plugin.manage.PluginFilter; @@ -83,6 +82,9 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import static com.fr.core.env.EnvEvents.AFTER_SIGN_OUT; +import static com.fr.core.env.EnvEvents.BEFORE_SIGN_OUT; + public class DesignerFrame extends JFrame implements JTemplateActionListener, TargetModifiedListener { public static final String DESIGNER_FRAME_NAME = "designer_frame"; public static final Dimension MIN_SIZE = new Dimension(100, 100); @@ -351,7 +353,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta .getResourceAsStream("/com/fr/base/images/oem/logo.ico")); this.setIconImages(image); } catch (IOException e) { - FRContext.getLogger().error(e.getMessage(), e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); this.setIconImage(BaseUtils.readImage("/com/fr/base/images/oem/logo.png")); } } @@ -965,11 +967,11 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta Env currentEnv = FRContext.getCurrentEnv(); try { - EnvContext.fireBeforeSignOut(); + EventDispatcher.fire(BEFORE_SIGN_OUT); currentEnv.signOut(); - EnvContext.fireAfterSignOut(); + EventDispatcher.fire(AFTER_SIGN_OUT); } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); } this.setVisible(false); this.dispose(); @@ -1025,7 +1027,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta } } } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); } } event.dropComplete(true); diff --git a/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java b/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java index ebc69aef58..846583538b 100644 --- a/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java +++ b/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java @@ -9,6 +9,7 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; import com.fr.general.Inter; +import com.fr.general.LogRecordTime; import com.fr.general.log.Log4jConfig; import com.fr.log.FineLoggerFactory; import com.fr.log.LogHandler; @@ -341,4 +342,8 @@ public class DesignerLogHandler { }; } + + public void printRemoteLog(LogRecordTime logRecordTime) { + logHandlerArea.printStackTrace(logRecordTime); + } } \ No newline at end of file diff --git a/designer-base/src/com/fr/env/RemoteEnv.java b/designer-base/src/com/fr/env/RemoteEnv.java index f004606f4f..a9124b9e91 100644 --- a/designer-base/src/com/fr/env/RemoteEnv.java +++ b/designer-base/src/com/fr/env/RemoteEnv.java @@ -1,47 +1,34 @@ package com.fr.env; -import com.fr.base.AbstractEnv; +import com.fr.base.env.old.AbstractEnv; import com.fr.base.EnvException; -import com.fr.base.FRContext; -import com.fr.base.ModifiedTable; -import com.fr.base.Parameter; -import com.fr.base.StoreProcedureParameter; import com.fr.base.TableData; -import com.fr.base.Utils; +import com.fr.base.env.EnvContext; +import com.fr.base.env.resource.RemoteEnvConfig; import com.fr.base.remote.RemoteDeziConstants; +import com.fr.core.env.EnvConstants; import com.fr.data.TableDataSource; -import com.fr.data.core.DataCoreUtils; -import com.fr.data.core.db.TableProcedure; -import com.fr.data.impl.Connection; import com.fr.data.impl.EmbeddedTableData; -import com.fr.data.impl.storeproc.ProcedureDataModel; import com.fr.data.impl.storeproc.StoreProcedure; import com.fr.dav.DavXMLUtils; -import com.fr.dav.UserBaseEnv; import com.fr.design.DesignerEnvManager; -import com.fr.design.ExtraDesignClassManager; -import com.fr.design.dialog.InformationWarnPane; -import com.fr.design.file.HistoryTemplateListPane; -import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.DesignerFrameFileDealerPane; import com.fr.file.CacheManager; import com.fr.file.ConnectionConfig; import com.fr.file.TableDataConfig; -import com.fr.file.filetree.FileNode; import com.fr.general.CommonIOUtils; import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; import com.fr.general.Inter; import com.fr.general.LogRecordTime; import com.fr.general.LogUtils; +import com.fr.general.http.HttpToolbox; import com.fr.io.utils.ResourceIOUtils; import com.fr.json.JSONArray; -import com.fr.json.JSONException; import com.fr.json.JSONObject; -import com.fr.license.function.VT4FR; -import com.fr.regist.License; +import com.fr.log.FineLoggerFactory; import com.fr.report.DesignAuthority; +import com.fr.report.util.AuthorityXMLUtils; import com.fr.share.ShareConstants; import com.fr.stable.ArrayUtils; import com.fr.stable.EncodeConstants; @@ -53,14 +40,11 @@ import com.fr.stable.StringUtils; import com.fr.stable.SvgProvider; import com.fr.stable.file.XMLFileManagerProvider; import com.fr.stable.project.ProjectConstants; -import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLTools; -import com.fr.stable.xml.XMLableReader; +import com.fr.third.guava.collect.ImmutableMap; import com.fr.web.ResourceConstants; -import com.fr.report.util.AuthorityXMLUtils; import javax.swing.JOptionPane; -import javax.swing.UIManager; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; @@ -80,141 +64,46 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; -import java.net.NoRouteToHostException; -import java.net.Socket; -import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; -import java.util.logging.Level; -import java.util.regex.Pattern; + +import static com.fr.third.guava.base.Preconditions.checkArgument; /** * @author null */ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurable { - private static final int TIME_OUT = 30 * 1000; - private static final int PLAIN_SOCKET_PORT = 80; - private static final int SSL_PORT = 443; - private static final int MAX_PER_ROUTE = 20; - private static final int MAX_TOTAL = 100; - private static final String REMOTE_PLUGIN = "remote_plugin.info"; private static final String CERT_KEY = "javax.net.ssl.trustStore"; private static final String PWD_KEY = "javax.net.ssl.trustStorePassword"; private static final String HTTPS_PREFIX = "https:"; private final static String[] FILE_TYPE = {"cptx", "cpt", "frm", "form", "cht", "chart"}; - private String path; - private String user; - private String password; - private Clock clock = null; - private String userID; - private Timer timer; - private int licNotSupport = 0; - private boolean isRoot = false; - private Timer logTimer = null; - private static ThreadLocal threadLocal = new ThreadLocal<>(); - private boolean isReadTimeOut = false; private String buildFilePath; + private RemoteEnvConfig env; - public RemoteEnv() { - this.clock = new Clock(this); - } public RemoteEnv(String path, String userName, String password) { - this(); - this.path = path; - this.user = userName; - this.password = password; + env = new RemoteEnvConfig(path, userName, password); } - /** - * 返回env配置路径 - */ @Override public String getPath() { - return this.path; - } - - public void setPath(String s) { - this.path = s; + return env.getPath(); } - /** - * 当前设计环境的用户名,用于远程设计 - */ @Override public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - clearUserID(); + return env.getUsername(); } public String getPassword() { - return password; - } - - /** - * 修复密码中包含特殊字符,无法登录的问题 - * - * @return encoded password - */ - private String getEncodedPassword() { - try { - return URLEncoder.encode(password, "UTF-8"); - } catch (UnsupportedEncodingException e) { - return password; - } - } - - public void setPassword(String password) { - this.password = password; - clearUserID(); + return env.getPassword(); } - public Clock getClock() { - return this.clock; - } - - public void setClock(Clock clock) { - this.clock = clock; - } - - private void clearUserID() { - this.userID = null; - } - - public void setThreadLocal(String value) { - synchronized (this) { - threadLocal.set(value); - } - - } - - public String getThreadLocal() { - return threadLocal.get(); - } - - /** - * 所有与服务器端交互前,都要调用这个方法生成UserID - */ - public String getValidUserID() throws EnvException { - // 如果登录之后userID还是null - if (this.userID == null) { - if (!VT4FR.RemoteDesign.support() && licNotSupport <= 0) { - licNotSupport++; - JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Lic_does_not_Support_Remote")); - } - throw new EnvException(Inter.getLocText("Env-Invalid_User_and_Password")); - } - - return this.userID; + @Override + public String getUserID() { + return EnvContext.currentToken(); } /** @@ -248,15 +137,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl } } - private void doWithTimeOutException() { - boolean isNotNeedTip = ComparatorUtils.equals(getThreadLocal(), "HEART_BEAT") || ComparatorUtils.equals(getThreadLocal(), "LOG_MESSAGE"); - if (!isReadTimeOut && !isNotNeedTip) { - isReadTimeOut = true; - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"Data", "read_time_out"})); - isReadTimeOut = false; - } - FRContext.getLogger().info("Connection reset "); - } /** @@ -285,7 +165,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl try { result = CommonIOUtils.inputStream2String(in, EncodeConstants.ENCODING_UTF_8); } catch (UnsupportedEncodingException e) { - FRContext.getLogger().error(e.getMessage(), e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); } return result; } @@ -324,126 +204,64 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl private boolean testConnection(boolean needMessage, boolean isRegisteServer, Component parentComponent) throws Exception { - refreshHttpSProperty(); - changeEnvPathFromExtra(); - - if (path.startsWith("https") && (!DesignerEnvManager.getEnvManager().isHttps())) { - return false; - } - - InputStream inputStream = RemoteEnvUtils.testConnection(true, this); - inputStream = filterInputStream(inputStream); - String res = IOUtils.inputStream2String(inputStream, EncodeConstants.ENCODING_UTF_8); - - if (StringUtils.isEmpty(res)) { + checkArgument(parentComponent instanceof Component, "parentComponent should be a java.awt.component"); + Component component = parentComponent; + String url = String.format("%s/connection", EnvConstants.toDecisionPath(getPath())); + ImmutableMap params = ImmutableMap.of( + "version", (Object) ProductConstants.DESIGNER_VERSION + ); + ImmutableMap headers = ImmutableMap.of( + EnvConstants.USERNAME, getUser(), + EnvConstants.PWD, getPassword()); + String res = HttpToolbox.post(url, params, headers); + if (res == null) { if (needMessage) { - JOptionPane.showMessageDialog( - parentComponent, - Inter.getLocText("Datasource-Connection_failed"), - UIManager.getString("OptionPane.messageDialogTitle", parentComponent.getLocale()), - JOptionPane.ERROR_MESSAGE - ); + JOptionPane.showMessageDialog(component, Inter.getLocText("Datasource-Connection_failed")); } return false; } else if (ComparatorUtils.equals(res, "true")) { - if (!clock.connected && isRegisteServer) { - //服务器中断又重新启动之后,重新向远程服务器注册 - register2Server(); - } return true; - } else if (ComparatorUtils.equals(res, "invalid username or password.")) { - JOptionPane.showMessageDialog( - parentComponent, - Inter.getLocText( - new String[]{"Datasource-Connection_failed", "Registration-User_Name", "Password", "Error"}, - new String[]{",", "", "", "!"} - ), - Inter.getLocText("FR-Server-All_Error"), - JOptionPane.ERROR_MESSAGE); - return false; - } else if (res.contains("RegistEditionException")) { - if (needMessage) { - JOptionPane.showMessageDialog( - parentComponent, - Inter.getLocText( - new String[]{"Datasource-Connection_failed", "Version-does-not-support"}, - new String[]{",", "!"} - ), - UIManager.getString("OptionPane.messageDialogTitle", parentComponent.getLocale()), - JOptionPane.ERROR_MESSAGE - ); - } else { - FRContext.getLogger().info( - Inter.getLocText( - new String[]{"Datasource-Connection_failed", "Version-does-not-support"}, - new String[]{",", "!"} - ) - ); - } - return false; - } else if (ComparatorUtils.equals(res, "war not support remote design.")) { - if (needMessage) { - JOptionPane.showMessageDialog( - parentComponent, - Inter.getLocText( - new String[]{"Datasource-Connection_failed", "NS-war-remote"}, - new String[]{",", "!"} - ), - UIManager.getString("OptionPane.messageDialogTitle", parentComponent.getLocale()), - JOptionPane.ERROR_MESSAGE - ); + } else { + if (ComparatorUtils.equals(res, EnvConstants.AUTH_ERROR)) { + JOptionPane.showMessageDialog(component, + Inter.getLocText(new String[]{"Datasource-Connection_failed", "Registration-User_Name", "Password", "Error"}, new String[]{",", "", "", "!"}) + , Inter.getLocText("FR-Server-All_Error"), JOptionPane.ERROR_MESSAGE); + return false; } else { - FRContext.getLogger().info( - Inter.getLocText( - new String[]{"Datasource-Connection_failed", "NS-war-remote"}, - new String[]{",", "!"} - ) - ); + if (ComparatorUtils.equals(res, EnvConstants.WAR_ERROR)) { + if (needMessage) { + JOptionPane.showMessageDialog(component, Inter.getLocText(new String[]{"Datasource-Connection_failed", "NS-war-remote"}, new String[]{",", "!"})); + } else { + FineLoggerFactory.getLogger().info(Inter.getLocText(new String[]{"Datasource-Connection_failed", "NS-war-remote"}, new String[]{",", "!"})); + } + return false; + } else { + if (needMessage) { + JOptionPane.showMessageDialog(component, Inter.getLocText(new String[]{"Datasource-Connection_failed", "Version-does-not-support"}, new String[]{",", "!"})); + } else { + FineLoggerFactory.getLogger().info(Inter.getLocText(new String[]{"Datasource-Connection_failed", "Version-does-not-support"}, new String[]{",", "!"})); + } + return false; + } } - return false; - } else { - throw new EnvException(res); } } - private void changeEnvPathFromExtra() { - //在env连接之前, 加载一下不依赖env的插件. 看看需不需要改变参数. - DesignerEnvProcessor processor - = ExtraDesignClassManager.getInstance().getSingle(DesignerEnvProcessor.XML_TAG); - if (processor != null) { - this.path = processor.changeEnvPathBeforeConnect(user, password, path); - } - } private void refreshHttpSProperty() { - if (path.startsWith(HTTPS_PREFIX) && System.getProperty(CERT_KEY) == null) { + if (getPath().startsWith(HTTPS_PREFIX) && System.getProperty(CERT_KEY) == null) { DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); System.setProperty(CERT_KEY, envManager.getCertificatePath()); System.setProperty(PWD_KEY, envManager.getCertificatePass()); } } - private void register2Server() { - try { - SignIn.signIn(this); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - } /** * 心跳访问,用来更新当前用户的访问时间 * * @throws Exception e */ - public void heartBeatConnection() throws Exception { - // 刷新参数 - refreshHttpSProperty(); - // 获取结果 - InputStream inputStream = RemoteEnvUtils.headBeatConnection(this); - // 处理结果 - filterInputStream(inputStream); - } /** * 返回描述该运行环境的名字 @@ -455,227 +273,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return Inter.getLocText("Env-Remote_Server"); } - /** - * 登录,返回userID - */ - @Override - public void signIn() throws Exception { - if (clock != null && clock.connected) { - return; - } - String remoteVersion = getDesignerVersion(); - if (StringUtils.isBlank(remoteVersion) || ComparatorUtils.compare(remoteVersion, ProductConstants.DESIGNER_VERSION) < 0) { - throw new Exception("version not match"); - } - clearUserID(); - startLogTimer(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "r_sign_in"); - para.put("user", user); - para.put("password", getEncodedPassword()); - - simulateRPC(para, true); - - //neil:调用Clock方法,10秒向服务器发送一个字节,确保没掉线 - if (clock == null) { - Clock clock = new Clock(this); - setClock(clock); - } - clock.start(); - - // 远程登录的心跳访问, 防止设计器强制关闭而没有Logout - if (timer != null) { - timer.cancel(); - } - timer = new Timer(); - timer.schedule(new TimerTask() { - @Override - public void run() { - try { - RemoteEnv.this.setThreadLocal("HEART_BEAT"); - RemoteEnv.this.heartBeatConnection(); - } catch (Exception e) { - FRContext.getLogger().error("Server may be disconnected.", e); - } - } - }, RemoteDeziConstants.HEARTBEAT_DELAY, RemoteDeziConstants.HEARTBEAT_DELAY); - } - - - private void startLogTimer() { - if (logTimer != null) { - logTimer.cancel(); - } - - logTimer = new Timer(); - logTimer.schedule(new TimerTask() { - @Override - public void run() { - try { - RemoteEnv.this.setThreadLocal("LOG_MESSAGE"); - FRContext.getCurrentEnv().printLogMessage(); - } catch (Exception e) { - FRContext.getLogger().info(e.getMessage()); - } - } - }, 10000, 10000); - } - - private void stopLogTimer() { - if (logTimer != null) { - logTimer.cancel(); - logTimer = null; - } - } - - /** - * 根据userID sign out - * - * @return 成功签出返回true - * @throws Exception e - */ - @Override - public boolean signOut() throws Exception { - if (userID == null) { - return true; - } - stopLogTimer(); - // richer:登出的时候就把定时发送的时钟停掉 - clock.stop(); - // richer:把轮训使用的定时器也去掉 - timer.cancel(); - - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "r_sign_out"); - para.put("id", userID); - - return simulateRPC(para, false); - } - - protected boolean simulateRPC(HashMap para, boolean isSignIn) throws Exception { - refreshHttpSProperty(); - // execute method取到input stream再转成String - String result = null; - try { - result = stream2String(filterInputStream(RemoteEnvUtils.simulateRPCByHttpGet(para, isSignIn, this))); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - if (result == null) { - return false; - } - if (result.contains("RegistEditionException")) { - JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Lic_does_not_Support_Remote")); - return false; - } - try { - JSONObject jo = new JSONObject(result); - if (isSignIn) { - if (jo.has("id")) { - userID = jo.getString("id"); - } - if (jo.has("isRoot")) { - isRoot = jo.getBoolean("isRoot"); - } - - if (userID != null) { - return true; - } - } else { - if (jo.has("res")) { - return jo.getBoolean("res"); - } - } - String exception = jo.getString("exp"); - if (exception != null) { - throw new EnvException(exception); - } - } catch (JSONException je) { - return true; - } - - return true; - } - - protected boolean doLockOperation(String[] filePaths, String cmd) throws Exception { - if (filePaths == null || filePaths.length == 0) { - return true; - } - - JSONArray ja = new JSONArray(filePaths); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", cmd); - para.put("pathes", ja.toString()); - - return simulateRPC(para, false); - } - - /** - * 取路径filePath下面文件的lock - *

- * 处于同一个原子操作,要么拿到所有的锁,要么一个锁也没有拿到 - */ - public boolean getLock(String[] filePathes) throws Exception { - return doLockOperation(filePathes, "design_get_lock"); - } - - /** - * 解锁文件 - * - * @param filePaths 文件路径 - * @return 成功解锁返回true - * @throws Exception e - */ - public boolean releaseLock(String[] filePaths) throws Exception { - return doLockOperation(filePaths, "design_release_lock"); - } - - /** - * 当前Env下,tplPath目录下是否存在模板 - * - * @param reportPath 路径 - * @return 是否存在 - */ - @Override - public boolean isTemplateExist(String reportPath) throws Exception { - refreshHttpSProperty(); - if (reportPath == null) { - return false; - } - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_report_exist"); - para.put("report_path", reportPath); - - InputStream input = filterInputStream(RemoteEnvUtils.simulateRPCByHttpGet(para, false, this)); - return ComparatorUtils.equals(stream2String(input), "true"); - } - - /** - * 解锁当前模板,用于远程设计。当远程设计某张模板 时,在解锁之前改模板处于锁定状态 - * - * @param tplPath 路径 - * @throws Exception e - */ - @Override - public void unlockTemplate(String tplPath) throws Exception { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_close_report"); - para.put(RemoteDeziConstants.TEMPLATE_PATH, tplPath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - String info = Utils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8); - - FRContext.getLogger().info(info); - } - public class Bytes2ServerOutputStream extends OutputStream { private ByteArrayOutputStream out = new ByteArrayOutputStream(); private HashMap nameValuePairs; @@ -705,7 +302,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl try { return postBytes2Server(out.toByteArray(), nameValuePairs); } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); return false; } } @@ -733,33 +330,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl } } - /** - * 测试数据连接是否能够正确的连接上 - * - * @param database 数据连接 - * @return 如果能正确的连接到数据库则返回true - * @throws Exception 无法正确连接到数据库则抛出此异常 - */ - @Override - public boolean testConnection(Connection database) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - // 把database写成xml文件到out - DavXMLUtils.writeXMLFileDatabaseConnection(database, out); - - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_test_con"); - - InputStream input = postBytes2ServerB(out.toByteArray(), para); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - @Override public boolean updateAuthorities(DesignAuthority[] authorities) { refreshHttpSProperty(); @@ -769,7 +339,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl inputStream = filterInputStream(inputStream); res = IOUtils.inputStream2String(inputStream, EncodeConstants.ENCODING_UTF_8); } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); + FineLoggerFactory.getLogger().error(e.getMessage()); } return StringUtils.isNotEmpty(res) && Boolean.valueOf(res); } @@ -784,265 +354,11 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl authorities = AuthorityXMLUtils.readDesignAuthoritiesXML(inputStream); return authorities; } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); + FineLoggerFactory.getLogger().error(e.getMessage()); } return authorities; } - /** - * ben:取schema - */ - @Override - public String[] getTableSchema(Connection database) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - DavXMLUtils.writeXMLFileDatabaseConnection(database, out); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_schema"); - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return null; - } - return DavXMLUtils.readXMLFileSchema(input); - } - - /** - * b:分别取Table,View,Procedure,实际应用时更有意义 - */ - @Override - public TableProcedure[] getTableProcedure(Connection database, String type, String schema) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - DavXMLUtils.writeXMLFileDatabaseConnection(database, out); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_tables"); - para.put("__type__", type); - para.put("__dbschema__", schema); - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return new TableProcedure[0]; - } - return DavXMLUtils.readXMLSQLTables(input); - } - - @Override - public List getProcedures(Connection datasource, String[] schemas, boolean isOracle, boolean isOracleSysSpace) throws Exception { - Map schemaTableProcedureMap = new HashMap<>(); - List sqlTableList = new ArrayList<>(); - TableProcedure[] sqlTableObj; - int len = schemas.length; - if (len > 0) { - for (String schema : schemas) { - sqlTableObj = this.getTableProcedure(datasource, TableProcedure.PROCEDURE, schema); - if (sqlTableObj == null) { - sqlTableObj = new TableProcedure[0]; - } - sqlTableList.add(sqlTableObj); - schemaTableProcedureMap.put(schema, sqlTableObj); - } - } else { - sqlTableObj = this.getTableProcedure(datasource, TableProcedure.PROCEDURE, null); - if (sqlTableObj == null) { - sqlTableObj = new TableProcedure[0]; - } - sqlTableList.add(sqlTableObj); - schemaTableProcedureMap.put(null, sqlTableObj); - } - DataCoreUtils.putProcedureMap(datasource, schemaTableProcedureMap); - return sqlTableList; - } - - /** - * 在当前路径下新建文件夹 - * - * @param folderPath 文件名 - * @return 成功创建返回true - * @throws Exception e - */ - @Override - public boolean createFolder(String folderPath) throws Exception { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_create_folder"); - para.put("folder_path", folderPath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - - /** - * 新建一个文件 - * - * @param filePath :目标文件相对路径 - * @return 成功新建返回true - * @throws Exception e - */ - @Override - public boolean createFile(String filePath) throws Exception { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_create_file"); - para.put("file_path", filePath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - - @Override - public boolean renameFile(String newPath, String oldPath) throws Exception { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_rename_file"); - para.put("newPath", newPath); - para.put("oldPath", oldPath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - - /** - * 判断文件是否存在 - * - * @param filePath :目标文件相对路径 - * @return 文件是否存在 - * @throws Exception e - */ - @Override - public boolean fileExists(String filePath) throws Exception { - refreshHttpSProperty(); - if (filePath == null) { - return false; - } - - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_file_exists"); - para.put("file_path", filePath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - - /** - * 判断文件是否锁住 - * - * @param filePath 文件路径 - * @return 文件被锁住了,返回true - * @throws Exception e - */ - @Override - public boolean fileLocked(String filePath) throws Exception { - refreshHttpSProperty(); - if (filePath == null) { - return false; - } - - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_file_locked"); - para.put("file_path", filePath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - - - /** - * 注册环境,用于检测是否启动定时器,主要用于本地环境来监测远程 - * - * @param env 用户环境 - */ - @Override - public void registerUserEnv(UserBaseEnv env) { - } - - /** - * 用于检测用户环境 - * ,启动定时器 - */ - @Override - public void startUserCheckTimer() { - } - - - /** - * 停止定时器 - */ - public void stopUserCheckTimer() { - } - - /** - * 删除文件 - * - * @param filePath 文件地址 - * @return 删除成功返回true - */ - @Override - public boolean deleteFile(String filePath) { - refreshHttpSProperty(); - if (filePath == null) { - return false; - } - try { - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "delete_file"); - para.put("file_path", filePath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - return false; - } - /** * 远程设计器设计时,假如开了权限就不可预览了。这边放一个全局的map来开后门 * @@ -1056,8 +372,8 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fr_remote_design"); para.put("cmd", "write_privilege_map"); - para.put("current_user", this.user); - para.put("current_password", this.password); + para.put("current_user", getUser()); + para.put("current_password", getPassword()); para.put("key", key); para.put("value", value); @@ -1089,163 +405,27 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl para.put("currentPwd", this.getPassword()); InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - JSONArray ja = new JSONArray(stream2String(input)); - ArrayList toBeRemoveTDName = new ArrayList<>(); - for (int i = 0; i < ja.length(); i++) { - String toBeRemoveConnName = (String) ((JSONObject) ja.get(i)).get("name"); - ConnectionConfig.getInstance().removeConnection(toBeRemoveConnName); - Iterator it = dm.getTableDatas().keySet().iterator(); - while (it.hasNext()) { - String tdName = (String) it.next(); - TableData td = dm.getTableData(tdName); - td.registerNoPrivilege(toBeRemoveTDName, toBeRemoveConnName, tdName); - } - } - - for (int i = 0; i < toBeRemoveTDName.size(); i++) { - dm.removeTableData(toBeRemoveTDName.get(i)); - } - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - } - - /** - * 列出WEB-INF目录下指定路径的文件夹与文件 - * - * @param rootFilePath 指定目录 - * @return WEB-INF目录下指定路径的文件夹与文件 - * @throws Exception e - */ - @Override - public FileNode[] listFile(String rootFilePath) throws Exception { - return listFile(rootFilePath, false); - } - - /** - * 列出WEB-INF上层目录下指定路径的文件夹与文件 - * - * @param rootFilePath 指定目录 - * @return WEB-INF上层目录下指定路径的文件夹与文件 - * @throws Exception e - */ - @Override - public FileNode[] listReportPathFile(String rootFilePath) throws Exception { - return listFile(rootFilePath, true); - } - - private FileNode[] listFile(String rootFilePath, boolean isWebReport) throws Exception { - refreshHttpSProperty(); - InputStream inputStream = RemoteEnvUtils.listFile(rootFilePath, isWebReport, this); - inputStream = filterInputStream(inputStream); - return DavXMLUtils.readXMLFileNodes(inputStream); - } - - - /** - * 列出目标目录下所有cpt文件或文件夹 - * - * @param rootFilePath 指定目录 - * @return 列出目标目录下所有cpt文件或文件夹 - */ - @Override - public FileNode[] listCpt(String rootFilePath) { - return listCpt(rootFilePath, false); - } - - /** - * 列出目标目录下所有cpt文件或文件夹 - * - * @param rootFilePath 指定目录 - * @param recurse 是否递归查找其子目录 - * @return 列出目标目录下所有cpt文件或文件夹 - * @throws Exception e - */ - @Override - public FileNode[] listCpt(String rootFilePath, boolean recurse) { - List fileNodeList = new ArrayList<>(); - try { - listAll(rootFilePath, fileNodeList, new String[]{"cpt"}, recurse); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - } - return fileNodeList.toArray(new FileNode[fileNodeList.size()]); - } - - private void listAll(String rootFilePath, List nodeList, String[] fileTypes, boolean recurse) throws Exception { - FileNode[] fns = listFile(rootFilePath); - for (FileNode fileNode : fns) { - if (isAcceptFileType(fileNode, fileTypes)) { - nodeList.add(fileNode); - } else if (fileNode.isDirectory()) { - if (recurse) { - listAll(rootFilePath + File.separator + fileNode.getName(), nodeList, fileTypes, true); - } else { - nodeList.add(fileNode); - } - } - } - } - - private boolean isAcceptFileType(FileNode fileNode, String[] fileTypes) { - for (String fileType : fileTypes) { - if (fileNode.isFileType(fileType)) { - return true; - } - } - return false; - } - - /** - * 获取指定数据集的参数 - * - * @param tableData 数据集 - * @return 数据集的参数 - * @throws Exception 获取参数失败则抛出此异常 - */ - @Override - public Parameter[] getTableDataParameters(TableData tableData) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - //把tableData写成xml文件到out - DavXMLUtils.writeXMLFileTableData(tableData, out); - - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_td_pars"); - InputStream input = postBytes2ServerB(out.toByteArray(), para); - - if (input == null) { - return new Parameter[0]; - } - return DavXMLUtils.readXMLParameters(input); - } - - - /** - * 获取存储过程中的参数 - * - * @param storeProcedure 存储过程 - * @return 返回存储过程中的所有参数组成的数组 - * @throws Exception 如果获取参数失败则抛出此异常 - */ - @Override - public Parameter[] getStoreProcedureParameters(StoreProcedure storeProcedure) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - // 把tableData写成xml文件到out - DavXMLUtils.writeXMLFileStoreProcedureAndSource(storeProcedure, out); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_sp_pars"); - InputStream input = postBytes2ServerB(out.toByteArray(), para); + RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) + ); + JSONArray ja = new JSONArray(stream2String(input)); + ArrayList toBeRemoveTDName = new ArrayList<>(); + for (int i = 0; i < ja.length(); i++) { + String toBeRemoveConnName = (String) ((JSONObject) ja.get(i)).get("name"); + ConnectionConfig.getInstance().removeConnection(toBeRemoveConnName); + Iterator it = dm.getTableDatas().keySet().iterator(); + while (it.hasNext()) { + String tdName = (String) it.next(); + TableData td = dm.getTableData(tdName); + td.registerNoPrivilege(toBeRemoveTDName, toBeRemoveConnName, tdName); + } + } - if (input == null) { - return new Parameter[0]; + for (int i = 0; i < toBeRemoveTDName.size(); i++) { + dm.removeTableData(toBeRemoveTDName.get(i)); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage()); } - return DavXMLUtils.readXMLParameters(input); } @Override @@ -1321,163 +501,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return filterInputStream(RemoteEnvUtils.simulateRPCByHttpPost(bytes, para, false, this)); } - /** - * Read XML.
- * The method will be invoked when read data from XML file.
- * May override the method to read the data that you saved. - */ - @Override - public void readXML(XMLableReader reader) { - if (reader.isChildNode()) { - String tmpVal; - if ("DIR".equals(reader.getTagName())) { - if ((tmpVal = reader.getAttrAsString("path", null)) != null) { - this.path = tmpVal; - } - if ((tmpVal = reader.getAttrAsString("user", null)) != null) { - this.user = tmpVal; - } - if ((tmpVal = reader.getAttrAsString("password", null)) != null) { - this.password = tmpVal; - } - } - } - } - - /** - * Write XML.
- * The method will be invoked when save data to XML file.
- * May override the method to save your own data. - * - * @param writer the PrintWriter. - */ - @Override - public void writeXML(XMLPrintWriter writer) { - writer.startTAG("DIR").attr("path", this.path).attr("user", this.user).attr("password", this.password).end(); - } - - - public static class Clock { - - private static final long CONNECT_INTERVAL = 3000L; - private boolean connected = false; - - private RemoteEnv remoteEnv; - - public Clock(RemoteEnv remoteEnv) { - this.remoteEnv = remoteEnv; - } - - /** - * 开始连接 - */ - public void start() { - if (connected) { - return; - } - connected = true; - - new Thread(new Runnable() { - @Override - public void run() { - // richie:连续三次尝试连接都没有响应才判定为丢失连接 - while (connected) { - try { - attemptConnect(); - } catch (Exception ex) { - try { - attemptConnect(); - } catch (Exception ee) { - try { - attemptConnect(); - } catch (Exception exc) { - stop(); - if (exc instanceof NoRouteToHostException) { - //网络问题导致的连接中断 - if (JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Remote_Connect2Server_Again"), UIManager.getString("OptionPane.titleText"), JOptionPane.YES_NO_OPTION) - == JOptionPane.OK_OPTION) { - //调用重新连接服务器的方法 - connectedAgain(); - } - } else { - //服务器关闭引起的连接中断 - if (JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Remote_Re_Connect_to_Server"), UIManager.getString("OptionPane.titleText"), JOptionPane.YES_NO_OPTION) - == JOptionPane.OK_OPTION) { - //调用重新连接服务器的方法 - connectedAgain(); - } - } - } - } - } - } - } - }).start(); - } - - /** - * 服务器连接中断后重新连接 - */ - private void connectedAgain() { - try { - if (!remoteEnv.testServerConnectionWithOutShowMessagePane()) { - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"Datasource-Connection_failed", "check_communication"}, - new String[]{",", "!"})); - DesignerFrameFileDealerPane.getInstance().refresh(); - return; - } - String remoteVersion = remoteEnv.getDesignerVersion(); - if (StringUtils.isBlank(remoteVersion) || ComparatorUtils.compare(remoteVersion, ProductConstants.DESIGNER_VERSION) < 0) { - String infor = Inter.getLocText("FR-Server_Version_Tip"); - String moreInfo = Inter.getLocText("FR-Server_Version_Tip_MoreInfo"); - FRContext.getLogger().log(Level.WARNING, infor); - new InformationWarnPane(infor, moreInfo, Inter.getLocText("FR-Designer_Tooltips")).show(); - return; - } - SignIn.signIn(remoteEnv); - HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().refreshToolArea(); - } catch (Exception em) { - FRContext.getLogger().error(em.getMessage(), em); - } - } - - /** - * 停止连接 - */ - public void stop() { - connected = false; - } - - private void attemptConnect() throws Exception { - Thread.sleep(CONNECT_INTERVAL); - Pattern pattern = Pattern.compile("[/:]+"); - String[] strs = pattern.split(remoteEnv.path); - - //host,如:192.168.100.195 - String shost = strs[1]; - //端口,如:8080 - int sport = Integer.parseInt(strs[2]); - - Socket socket = new Socket(shost, sport); - //OOBBINLINE:是否支持发送一个字节的TCP紧急数据,false表示服务器不用处理这个数据 - socket.setOOBInline(false); - socket.sendUrgentData(0xFF); - socket.close(); - } - } - - /** - * 读报表运行环境所需的配置文件,如datasource.xml, config.xml,这些文件都保存在WEB-INF/resources目录下面 - * - * @param resourceName 配置文件的名字,如datasource.xml - * @return 输入流 - * @throws Exception e - */ - @Override - public InputStream readResource(String resourceName) throws Exception { - return readBean(resourceName, ProjectConstants.RESOURCES_NAME); - } - /** * 读取路径下的svg文件 @@ -1496,7 +519,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl para.put("op", "fr_remote_design"); para.put("cmd", "design_read_svgfile"); para.put("resourcePath", path); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); InputStream input = filterInputStream( @@ -1514,7 +537,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl fileArray.add(file); } } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); + FineLoggerFactory.getLogger().error(e.getMessage()); } return fileArray.toArray(new String[0]); @@ -1536,7 +559,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl para.put("op", "svgrelate"); para.put("cmd", "design_save_svg"); para.put("filePath", svgFile.getFilePath()); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); // 通过ByteArrayOutputStream将svg写成字节流 @@ -1550,11 +573,11 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl try { xformer.transform(source, result); } catch (TransformerException ex) { - FRContext.getLogger().error(ex.getMessage()); + FineLoggerFactory.getLogger().error(ex.getMessage()); } } catch (TransformerConfigurationException ex) { - FRContext.getLogger().error(ex.getMessage()); + FineLoggerFactory.getLogger().error(ex.getMessage()); return false; } @@ -1567,7 +590,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return false; } } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); + FineLoggerFactory.getLogger().error(e.getMessage()); return false; } @@ -1590,7 +613,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl para.put("cmd", "design_save_resource"); para.put("resource", mgr.fileName()); para.put("class_name", mgr.getClass().getName()); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); // alex:通过ByteArrayOutputStream将mgr写成字节流 @@ -1608,7 +631,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return false; } } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); + FineLoggerFactory.getLogger().error(e.getMessage()); return false; } @@ -1653,38 +676,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return new Bytes2ServerOutputStream(para); } - /** - * 返回数据库表的列名 - * - * @param selectedName 所选择数据库名 - * @param schema 数据库模式,用于存储过程 - * @param tableName 所选择数据库名 - */ - @Override - public String[] getColumns(String selectedName, String schema, String tableName) throws Exception { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_columns"); - para.put("dsName", selectedName); - para.put("schema", schema); - para.put("tableName", tableName); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return null; - } - - String columns = stream2String(input); - if (StringUtils.isEmpty(columns)) { - return null; - } - return columns.split("\\."); - } - /** * 返回模板文件路径 */ @@ -1693,98 +684,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return getPath().substring(0, getPath().lastIndexOf("/")); } - @Override - public String getProcedureText(String connectionName, String databaseName) throws Exception { - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_procedure_text"); - para.put("procedure_name", databaseName); - para.put("connectionName", connectionName); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return StringUtils.EMPTY; - } - return DavXMLUtils.readXMLProcedureText(input); - } - - @Override - public StoreProcedureParameter[] getStoreProcedureDeclarationParameters(String connectionName, String databaseName, String parameterDefaultValue) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_sp_parameters"); - para.put("__name__", databaseName); - para.put("__default_value__", parameterDefaultValue); - para.put("connectionName", connectionName); - - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return new StoreProcedureParameter[0]; - } - return DavXMLUtils.readXMLStoreProcedureParameters(input); - } - - /** - * 获取datasource.xml文件的修改表 - */ - @Override - public ModifiedTable getDataSourceModifiedTables(String type) { - refreshHttpSProperty(); - try { - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "get_datasource_modified_tables"); - para.put("type", type); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - if (input == null) { - return new ModifiedTable(); - } - return DavXMLUtils.readXMLModifiedTables(input); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - return new ModifiedTable(); - } - - - /** - * 写修改表 - * - * @param modifiedTable 修改表 - * @param type 操作类型,是数据连接还是服务器数据集 - * @return 写入成功返回true - */ - @Override - public boolean writeDataSourceModifiedTables(ModifiedTable modifiedTable, String type) { - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - // 把tableData写成xml文件到out - DavXMLUtils.writeXMLModifiedTables(modifiedTable, out); - try { - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "update_modifytable_to_server"); - para.put("type", type); - - InputStream input = postBytes2ServerB(out.toByteArray(), para); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - return false; - } - public String[] getProcedureColumns(StoreProcedure storeProcedure, Map parameterMap) throws Exception { refreshHttpSProperty(); String[] columns; @@ -1803,7 +702,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl columns = DavXMLUtils.readXMLSPColumns(input); return columns; } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); + FineLoggerFactory.getLogger().error(e.getMessage()); } return new String[0]; @@ -1826,7 +725,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl columns = DavXMLUtils.readXMLSPColumns(input); return columns; } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); + FineLoggerFactory.getLogger().error(e.getMessage()); } return new String[0]; @@ -1851,102 +750,11 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl LogRecordTime[] records = LogUtils.readXMLLogRecords(input); } - @Override - public String getUserID() { - return userID; - } - - - /** - * 预览存储过程 - * - * @param storeProcedure 存储过程 - * @param parameterMap 参数map - * @param rowCount 行数 - * @return 返回取到的存储过程 - */ - @Override - public ProcedureDataModel[] previewProcedureDataModel(StoreProcedure storeProcedure, Map parameterMap, int rowCount) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - // 把tableData写成xml文件到out - DavXMLUtils.writeXMLFileStoreProcedureAndSource(storeProcedure, out); - - // 把parameterMap转成JSON格式的字符串 - JSONObject jo = new JSONObject(parameterMap); - String jsonParameter = jo.toString(); - - try { - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "list_sp"); - para.put("pars", jsonParameter); - - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return null; - } - - TableData[] tableDatas = DavXMLUtils.readXMLTableDataArray(input); - if (tableDatas == null || tableDatas.length == 0) { - return new ProcedureDataModel[0]; - } - ProcedureDataModel[] procedureDataModels = new ProcedureDataModel[tableDatas.length]; - for (int i = 0; i < tableDatas.length; i++) { - if (tableDatas[i] instanceof EmbeddedTableData) { - procedureDataModels[i] = ((EmbeddedTableData) tableDatas[i]).trans2ProcedureDataModel(); - } - } - return procedureDataModels; - - - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - return new ProcedureDataModel[0]; - } - - - @Override - public String getAppName() { - return "WebReport"; - } - - /** - * 是否为Oracle数据连接 - * - * @param database 数据连接 - * @return 是返回true - * @throws Exception e - */ - @Override - public boolean isOracle(Connection database) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - DavXMLUtils.writeXMLFileDatabaseConnection(database, out); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_isOracle"); - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return true; - } - return DavXMLUtils.readXMLBoolean(input); - } - @Override public String[] getSupportedTypes() { return FILE_TYPE; } - /** - * 在模板面板中是否支持增加打开所在文件夹、重命名、删除三个工具栏选项 - * - * @return 不支持返回false - */ - @Override - public boolean isSupportLocalFileOperate() { - return false; - } /** * 判断是否有文件夹权限 @@ -1961,7 +769,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fs_remote_design"); para.put("cmd", "design_filefolder_allow"); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put(RemoteDeziConstants.TEMPLATE_PATH, path); InputStream input = filterInputStream( @@ -1973,49 +781,12 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl } return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); + FineLoggerFactory.getLogger().error(e.getMessage()); return false; } } - /** - * 是否是管理员身份 - * - * @return 是则返回true - */ - @Override - public boolean isRoot() { - return isRoot; - } - - /** - * 是否为压缩包部署 - * - * @return 是则返回true - */ - @Override - public boolean isPackDeploy() { - return false; - } - - @Override - public String getDesignerVersion() { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_designer_version"); - para.put("user", user); - para.put("password", getEncodedPassword()); - - try { - return stream2String(filterInputStream(RemoteEnvUtils.simulateRPCByHttpGet(para, true, this))); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - return null; - } - @Override public InputStream getDataSourceInputStream(String filePath) throws Exception { return readBean(filePath, "datasource"); @@ -2041,20 +812,11 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl allRoleList.add(roleName); } } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); + FineLoggerFactory.getLogger().error(e.getMessage()); } return allRoleList; } - @Override - public String getLicName() { - return License.FILE_NAME; - } - - @Override - public void setLicName(String licName) { - //do nth - } /** @@ -2135,7 +897,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fr_remote_design"); para.put("cmd", "design_read_reufile"); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); //拿到服务端传过来的整个共享文件夹的压缩文件的文件流 @@ -2156,7 +918,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl }); } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); + FineLoggerFactory.getLogger().error(e.getMessage()); } finally { if (zipFilePath != null) { @@ -2181,7 +943,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fr_remote_design"); para.put("cmd", "design_install_reufile"); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); para.put("reuFileName", reuFile.getName()); @@ -2218,7 +980,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fr_remote_design"); para.put("cmd", "design_remove_reufile"); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); para.put("reuFileName", fileName); @@ -2238,7 +1000,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fr_remote_design"); para.put("cmd", "design_get_share_path"); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); InputStream input = filterInputStream( @@ -2250,16 +1012,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl } } - @Override - public void doWhenServerShutDown() { - - } - - @Override - public boolean isLocalEnv() { - - return false; - } @Override public boolean hasPluginServiceStarted(String key) { @@ -2267,22 +1019,4 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return true; } - @Override - public JSONArray getPluginStatus() { - refreshHttpSProperty(); - try { - HashMap para = new HashMap<>(); - para.put("op", "plugin"); - para.put("cmd", "get_status"); - para.put("current_uid", this.getValidUserID()); - para.put("currentUsername", this.getUser()); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - return new JSONArray(stream2String(input)); - } catch (Exception e) { - return JSONArray.create(); - } - } } \ No newline at end of file