Browse Source

finally

master
hzzz 7 years ago
parent
commit
2a7c5c6381
  1. 16
      designer-base/src/com/fr/design/DesignerEnvManager.java
  2. 14
      designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java
  3. 3
      designer-base/src/com/fr/design/env/DesignerWorkspaceGenerator.java
  4. 88
      designer-realize/src/com/fr/design/mainframe/socketio/DesignerSocketIO.java
  5. 3
      designer-realize/src/com/fr/start/module/DesignerActivator.java

16
designer-base/src/com/fr/design/DesignerEnvManager.java

@ -35,10 +35,12 @@ import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLWriter;
import com.fr.stable.xml.XMLableReader;
import com.fr.workspace.WorkContext;
import com.fr.workspace.connect.AuthException;
import javax.swing.*;
import javax.swing.SwingWorker;
import javax.swing.SwingWorker.StateValue;
import java.awt.*;
import java.awt.Color;
import java.awt.Rectangle;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
@ -476,7 +478,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
* @return 是默认则返回true
*/
public boolean isCurrentEnvDefault() {
DesignerWorkspaceInfo current = this.getWorkspaceInfo(curEnvName);
String defaultEnvPath = StableUtils.pathJoin(new String[]{StableUtils.getInstallHome(), ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBINF_NAME});
return ComparatorUtils.equals(new File(defaultEnvPath).getPath(), current.getPath());
@ -530,7 +532,11 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
if (isCurrentEnvDefault()) {
return;
}
WorkContext.switchTo(DesignerWorkspaceGenerator.generate(getDefaultConfig()));
try {
WorkContext.switchTo(DesignerWorkspaceGenerator.generate(getDefaultConfig()));
} catch (AuthException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
/**
@ -708,7 +714,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
* @param info 对应的环境信息
*/
public void putEnv(String name, DesignerWorkspaceInfo info) {
this.nameEnvMap.put(name, info);
}

14
designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java

@ -10,7 +10,6 @@ import com.fr.design.env.DesignerWorkspaceInfo;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.TemplatePane;
import com.fr.design.menu.KeySetUtils;
import com.fr.design.menu.MenuDef;
import com.fr.design.menu.SeparatorDef;
@ -20,6 +19,8 @@ import com.fr.general.Inter;
import com.fr.stable.EnvChangedListener;
import com.fr.workspace.WorkContext;
import com.fr.workspace.WorkContextCallback;
import com.fr.workspace.Workspace;
import com.fr.workspace.connect.AuthException;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
@ -103,7 +104,16 @@ public class SwitchExistEnv extends MenuDef {
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
final String envName = getName();
DesignerWorkspaceInfo selectedEnv = envManager.getWorkspaceInfo(envName);
WorkContext.switchTo(DesignerWorkspaceGenerator.generate(selectedEnv), new WorkContextCallback() {
Workspace workspace;
try {
workspace = DesignerWorkspaceGenerator.generate(selectedEnv);
} catch (AuthException exception) {
JOptionPane.showMessageDialog(
DesignerContext.getDesignerFrame(),
Inter.getLocText(new String[]{"Env-Invalid_User_and_Password"}));
return;
}
WorkContext.switchTo(workspace, new WorkContextCallback() {
@Override
public void success() {
DesignerEnvManager.getEnvManager().setCurEnvName(envName);

3
designer-base/src/com/fr/design/env/DesignerWorkspaceGenerator.java vendored

@ -2,6 +2,7 @@ package com.fr.design.env;
import com.fr.workspace.WorkContext;
import com.fr.workspace.Workspace;
import com.fr.workspace.connect.AuthException;
import com.fr.workspace.connect.WorkspaceClient;
/**
@ -9,7 +10,7 @@ import com.fr.workspace.connect.WorkspaceClient;
*/
public class DesignerWorkspaceGenerator {
public static Workspace generate(DesignerWorkspaceInfo config) {
public static Workspace generate(DesignerWorkspaceInfo config) throws AuthException {
if (config == null || config.getType() == null) {
return null;

88
designer-realize/src/com/fr/design/mainframe/socketio/DesignerSocketIO.java

@ -0,0 +1,88 @@
package com.fr.design.mainframe.socketio;
import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.design.mainframe.loghandler.DesignerLogHandler;
import com.fr.general.LogRecordTime;
import com.fr.general.LogUtils;
import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
import com.fr.third.guava.base.Optional;
import com.fr.third.guava.primitives.Ints;
import com.fr.workspace.WorkContext;
import com.fr.workspace.Workspace;
import com.fr.workspace.base.WorkspaceConstants;
import com.fr.workspace.engine.server.rpc.netty.RemoteCallClient;
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
public class DesignerSocketIO {
private static Optional<Socket> socketIO = Optional.absent();
private static final Emitter.Listener printLog = new Emitter.Listener() {
@Override
public void call(Object... objects) {
try {
LogRecordTime[] logRecordTimes = LogUtils.readXMLLogRecords(new ByteArrayInputStream((byte[]) objects[0]));
for (LogRecordTime logRecordTime : logRecordTimes) {
DesignerLogHandler.getInstance().printRemoteLog(logRecordTime);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
};
public static void close() {
if (socketIO.isPresent()) {
socketIO.get().close();
socketIO = Optional.absent();
}
}
public static void update() {
Workspace current = WorkContext.getCurrent();
if (current.isLocal()) {
return;
}
try {
String uri = getSocketUri(current);
socketIO = Optional.of(IO.socket(new URI(uri)));
socketIO.get().on(WorkspaceConstants.WS_LOGRECORD, printLog);
socketIO.get().connect();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
private static String getSocketUri(Workspace current) throws IOException {
URL url = new URL(current.getPath());
int port = getPort(current);
return String.format("http://%s:%s%s?%s=%s",
url.getHost(),
port,
WorkspaceConstants.WS_NAMESPACE,
DecisionServiceConstants.WEB_SOCKET_TOKEN_NAME,
RemoteCallClient.getInstance().getToken());
}
private static int getPort(Workspace current) throws IOException {
String url = current.getPath() + WorkspaceConstants.CONTROLLER_PREFIX + WorkspaceConstants.CONTROLLER_SOCKETIO_PORT;
try {
String portStr = HttpToolbox.get(url);
JSONObject jsonObject = new JSONObject(portStr);
return Ints.tryParse(jsonObject.optString("data"));
} catch (JSONException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
}

3
designer-realize/src/com/fr/start/module/DesignerActivator.java

@ -50,6 +50,7 @@ import com.fr.design.mainframe.form.FormReportComponentComposite;
import com.fr.design.mainframe.loghandler.DesignerLogAppender;
import com.fr.design.mainframe.loghandler.DesignerLogImpl;
import com.fr.design.mainframe.loghandler.LogMessageBar;
import com.fr.design.mainframe.socketio.DesignerSocketIO;
import com.fr.design.module.DesignModuleFactory;
import com.fr.design.parameter.FormParameterReader;
import com.fr.design.parameter.ParameterPropertyPane;
@ -123,6 +124,7 @@ public class DesignerActivator extends Activator implements Prepare {
designerModuleStart();
preLoadPane();
loadLogAppender();
DesignerSocketIO.update();
}
private void loadLogAppender() {
@ -400,6 +402,7 @@ public class DesignerActivator extends Activator implements Prepare {
@Override
public void stop() {
unloadLogAppender();
DesignerSocketIO.close();
}
@Override

Loading…
Cancel
Save