Browse Source

REPORT-6700 完善+远程设计过渡方案

master
yaoh.wu 7 years ago
parent
commit
5e8bbeef0a
  1. 7
      designer-base/src/com/fr/design/remote/action/RemoteDesignAuthorityManagerAction.java
  2. 41
      designer-base/src/com/fr/design/utils/DesignUtils.java
  3. 2
      designer-base/src/com/fr/env/DesignAuthorityConfigurable.java
  4. 512
      designer-base/src/com/fr/env/RemoteEnv.java
  5. 209
      designer-base/src/com/fr/env/RemoteEnvUtils.java

7
designer-base/src/com/fr/design/remote/action/RemoteDesignAuthorityManagerAction.java

@ -48,11 +48,8 @@ public class RemoteDesignAuthorityManagerAction extends UpdateAction {
public void doOk() { public void doOk() {
DesignAuthority[] authorities = managerPane.update(); DesignAuthority[] authorities = managerPane.update();
if (!FRContext.getCurrentEnv().isLocalEnv()) { if (!FRContext.getCurrentEnv().isLocalEnv()) {
try { boolean success = ((RemoteEnv) FRContext.getCurrentEnv()).updateAuthorities(authorities);
((RemoteEnv) FRContext.getCurrentEnv()).updateAuthorities(authorities); FRContext.getLogger().info("update remote design authority: " + success);
} catch (Exception exception) {
FRContext.getLogger().error(exception.getMessage());
}
} }
} }

41
designer-base/src/com/fr/design/utils/DesignUtils.java

@ -1,11 +1,11 @@
package com.fr.design.utils; package com.fr.design.utils;
import com.fr.base.BaseUtils; import com.fr.base.BaseUtils;
import com.fr.base.ServerConfig;
import com.fr.base.Env; import com.fr.base.Env;
import com.fr.base.EnvException; import com.fr.base.EnvException;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.base.FeedBackInfo; import com.fr.base.FeedBackInfo;
import com.fr.base.ServerConfig;
import com.fr.base.Utils; import com.fr.base.Utils;
import com.fr.base.remote.RemoteDeziConstants; import com.fr.base.remote.RemoteDeziConstants;
import com.fr.dav.DavXMLUtils; import com.fr.dav.DavXMLUtils;
@ -23,6 +23,7 @@ import com.fr.general.FRLogger;
import com.fr.general.GeneralContext; import com.fr.general.GeneralContext;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.http.HttpClient; import com.fr.general.http.HttpClient;
import com.fr.security.JwtUtils;
import com.fr.stable.ArrayUtils; import com.fr.stable.ArrayUtils;
import com.fr.stable.CodeUtils; import com.fr.stable.CodeUtils;
import com.fr.stable.EncodeConstants; import com.fr.stable.EncodeConstants;
@ -30,8 +31,11 @@ import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.start.StartServer; import com.fr.start.StartServer;
import javax.swing.*; import javax.swing.JOptionPane;
import java.awt.*; import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Desktop;
import java.awt.Font;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -75,6 +79,7 @@ public class DesignUtils {
/** /**
* 通过端口是否被占用判断设计器有没有启动 * 通过端口是否被占用判断设计器有没有启动
* s * s
*
* @return 启动了返回true * @return 启动了返回true
*/ */
public static boolean isStarted() { public static boolean isStarted() {
@ -120,11 +125,12 @@ public class DesignUtils {
} }
/** /**
*建立监听端口 * 建立监听端口
*
* @param startPort 端口 * @param startPort 端口
* @param suffixs 文件后缀 * @param suffixs 文件后缀
*/ */
public static void creatListeningServer(final int startPort,final String[] suffixs) { public static void creatListeningServer(final int startPort, final String[] suffixs) {
Thread serverSocketThread = new Thread() { Thread serverSocketThread = new Thread() {
public void run() { public void run() {
ServerSocket serverSocket = null; ServerSocket serverSocket = null;
@ -146,7 +152,7 @@ public class DesignUtils {
String path = f.getAbsolutePath(); String path = f.getAbsolutePath();
boolean isMatch = false; boolean isMatch = false;
for(int i= 0; i<suffixs.length;i++){ for (int i = 0; i < suffixs.length; i++) {
isMatch = isMatch || path.endsWith(suffixs[i]); isMatch = isMatch || path.endsWith(suffixs[i]);
} }
if (isMatch) { if (isMatch) {
@ -257,17 +263,17 @@ public class DesignUtils {
} }
} }
private static boolean isTextField(String key){ private static boolean isTextField(String key) {
return key.startsWith("TextField.") || key.startsWith("PasswordField."); return key.startsWith("TextField.") || key.startsWith("PasswordField.");
} }
private static FRFont getCurrentLocaleFont(){ private static FRFont getCurrentLocaleFont() {
FRFont guiFRFont; FRFont guiFRFont;
Locale defaultLocale = Locale.getDefault(); Locale defaultLocale = Locale.getDefault();
if (isDisplaySimSun(defaultLocale)) { if (isDisplaySimSun(defaultLocale)) {
guiFRFont = getNamedFont("SimSun"); guiFRFont = getNamedFont("SimSun");
} else if(isDisplayDialog(defaultLocale)) { } else if (isDisplayDialog(defaultLocale)) {
guiFRFont = getNamedFont("Dialog"); guiFRFont = getNamedFont("Dialog");
} else { } else {
guiFRFont = getNamedFont("Tahoma"); guiFRFont = getNamedFont("Tahoma");
@ -284,7 +290,7 @@ public class DesignUtils {
if (!guiFRFont.canDisplay(displayChar)) { if (!guiFRFont.canDisplay(displayChar)) {
//比如想在中文或英文系统里用韩文设计器 //比如想在中文或英文系统里用韩文设计器
guiFRFont = getNamedFont("Dialog"); guiFRFont = getNamedFont("Dialog");
if(!guiFRFont.canDisplay(displayChar)) { if (!guiFRFont.canDisplay(displayChar)) {
FRContext.getLogger().error(Inter.getLocText("FR-Base_SimSun_Not_Found")); FRContext.getLogger().error(Inter.getLocText("FR-Base_SimSun_Not_Found"));
} }
} }
@ -293,15 +299,15 @@ public class DesignUtils {
return guiFRFont; return guiFRFont;
} }
private static FRFont getNamedFont(String name){ private static FRFont getNamedFont(String name) {
return FRFont.getInstance(name, Font.PLAIN, 12); return FRFont.getInstance(name, Font.PLAIN, 12);
} }
private static boolean isDisplaySimSun(Locale defaultLocale){ private static boolean isDisplaySimSun(Locale defaultLocale) {
return ComparatorUtils.equals(defaultLocale, Locale.SIMPLIFIED_CHINESE); return ComparatorUtils.equals(defaultLocale, Locale.SIMPLIFIED_CHINESE);
} }
private static boolean isDisplayDialog(Locale defaultLocale){ private static boolean isDisplayDialog(Locale defaultLocale) {
return ComparatorUtils.equals(defaultLocale, Locale.TRADITIONAL_CHINESE) return ComparatorUtils.equals(defaultLocale, Locale.TRADITIONAL_CHINESE)
|| ComparatorUtils.equals(defaultLocale, Locale.JAPANESE) || ComparatorUtils.equals(defaultLocale, Locale.JAPANESE)
|| ComparatorUtils.equals(defaultLocale, Locale.JAPAN) || ComparatorUtils.equals(defaultLocale, Locale.JAPAN)
@ -313,7 +319,7 @@ public class DesignUtils {
* 访问服务器环境-空参数 * 访问服务器环境-空参数
*/ */
public static void visitEnvServer() { public static void visitEnvServer() {
visitEnvServerByParameters(StringUtils.EMPTY, new String[] {}, new String[] {}); visitEnvServerByParameters(StringUtils.EMPTY, new String[]{}, new String[]{});
} }
/** /**
@ -342,8 +348,11 @@ public class DesignUtils {
if (Utils.isEmbeddedParameter(postfixOfUri)) { if (Utils.isEmbeddedParameter(postfixOfUri)) {
String time = Calendar.getInstance().getTime().toString().replaceAll(" ", ""); String time = Calendar.getInstance().getTime().toString().replaceAll(" ", "");
boolean isUserPrivilege = ((RemoteEnv) FRContext.getCurrentEnv()).writePrivilegeMap(time, postfixOfUri); boolean isUserPrivilege = ((RemoteEnv) FRContext.getCurrentEnv()).writePrivilegeMap(time, postfixOfUri);
postfixOfUri = isUserPrivilege ? postfixOfUri + "&fr_check_url=" + time + "&id=" + FRContext.getCurrentEnv().getUserID(): postfixOfUri ; postfixOfUri = isUserPrivilege ? postfixOfUri + "&fr_check_url=" + time + "&id=" + FRContext.getCurrentEnv().getUserID() : postfixOfUri;
} }
// 加参数给远程设计校验权限。
String design = JwtUtils.createDefaultJWT(FRContext.getCurrentEnv().getUser());
postfixOfUri = postfixOfUri + "&design=" + design;
String urlPath = getWebBrowserPath(); String urlPath = getWebBrowserPath();
Desktop.getDesktop().browse(new URI(urlPath + postfixOfUri)); Desktop.getDesktop().browse(new URI(urlPath + postfixOfUri));
@ -486,7 +495,7 @@ public class DesignUtils {
*/ */
private static ByteArrayInputStream execute4InputStream(HttpClient client) throws Exception { private static ByteArrayInputStream execute4InputStream(HttpClient client) throws Exception {
int statusCode = client.getResponseCode(); int statusCode = client.getResponseCode();
if(statusCode != HttpURLConnection.HTTP_OK){ if (statusCode != HttpURLConnection.HTTP_OK) {
throw new EnvException("Method failed: " + statusCode); throw new EnvException("Method failed: " + statusCode);
} }
InputStream in = client.getResponseStream(); InputStream in = client.getResponseStream();

2
designer-base/src/com/fr/env/DesignAuthorityConfigurable.java vendored

@ -6,5 +6,5 @@ public interface DesignAuthorityConfigurable {
DesignAuthority[] getAuthorities(); DesignAuthority[] getAuthorities();
boolean updateAuthorities(DesignAuthority[] authorities) throws Exception; boolean updateAuthorities(DesignAuthority[] authorities);
} }

512
designer-base/src/com/fr/env/RemoteEnv.java vendored

File diff suppressed because it is too large Load Diff

209
designer-base/src/com/fr/env/RemoteEnvUtils.java vendored

@ -1,117 +1,238 @@
package com.fr.env; package com.fr.env;
import com.fr.base.EnvException;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.dav.DavXMLUtils;
import com.fr.file.filetree.FileNode;
import com.fr.general.IOUtils;
import com.fr.report.DesignAuthority; import com.fr.report.DesignAuthority;
import com.fr.report.util.AuthorityXMLUtils;
import com.fr.stable.EncodeConstants; import com.fr.stable.EncodeConstants;
import com.fr.third.org.apache.http.HttpEntity; import com.fr.third.org.apache.commons.io.IOUtils;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse; import com.fr.third.org.apache.http.HttpResponse;
import com.fr.third.org.apache.http.HttpStatus;
import com.fr.third.org.apache.http.client.ClientProtocolException;
import com.fr.third.org.apache.http.client.ResponseHandler;
import com.fr.third.org.apache.http.client.methods.HttpUriRequest; import com.fr.third.org.apache.http.client.methods.HttpUriRequest;
import com.fr.third.org.apache.http.client.methods.RequestBuilder; import com.fr.third.org.apache.http.client.methods.RequestBuilder;
import com.fr.third.org.apache.http.entity.ContentType; import com.fr.third.org.apache.http.entity.ContentType;
import com.fr.third.org.apache.http.entity.InputStreamEntity; import com.fr.third.org.apache.http.entity.InputStreamEntity;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients; import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.third.org.apache.http.util.EntityUtils;
import com.fr.web.utils.AuthorityXMLUtils;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.Map;
public class RemoteEnvUtils { public class RemoteEnvUtils {
private RemoteEnvUtils() { private RemoteEnvUtils() {
} }
public static boolean updateAuthorities(DesignAuthority[] authorities, RemoteEnv env) { private static ResponseHandler<InputStream> responseHandler = new ResponseHandler<InputStream>() {
@Override
public InputStream handleResponse(HttpResponse response) throws IOException {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
throw new ClientProtocolException("Method failed: " + response.getStatusLine().toString());
}
InputStream in = response.getEntity().getContent();
if (in == null) {
return null;
}
// 读取并返回
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
return new ByteArrayInputStream(out.toByteArray());
}
};
public static InputStream simulateRPCByHttpPost(byte[] bytes, Map<String, String> parameters, boolean isSignIn, RemoteEnv env) throws EnvException {
String path = env.getPath();
RequestBuilder builder = RequestBuilder.post(path);
InputStream inputStream = null;
for (Map.Entry<String, String> entry : parameters.entrySet()) {
builder.addParameter(entry.getKey(), entry.getValue());
}
if (!isSignIn) {
builder.addParameter("id", env.getValidUserID());
}
InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(bytes));
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
HttpUriRequest request = builder
.setEntity(reqEntity)
.build();
inputStream = httpClient.execute(request, responseHandler);
} catch (IOException e) {
FRContext.getLogger().error(e.getMessage());
}
return inputStream;
}
public static InputStream simulateRPCByHttpPost(Map<String, String> parameters, boolean isSignIn, RemoteEnv env) throws EnvException {
String path = env.getPath();
RequestBuilder builder = RequestBuilder.post(path);
InputStream inputStream = null;
for (Map.Entry<String, String> entry : parameters.entrySet()) {
builder.addParameter(entry.getKey(), entry.getValue());
}
if (!isSignIn) {
builder.addParameter("id", env.getValidUserID());
}
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
HttpUriRequest request = builder
.build();
inputStream = httpClient.execute(request, responseHandler);
} catch (IOException e) {
FRContext.getLogger().error(e.getMessage());
}
return inputStream;
}
public static InputStream simulateRPCByHttpGet(Map<String, String> parameters, boolean isSignIn, RemoteEnv env) throws EnvException {
String path = env.getPath();
RequestBuilder builder = RequestBuilder.get(path);
InputStream inputStream = null;
for (Map.Entry<String, String> entry : parameters.entrySet()) {
builder.addParameter(entry.getKey(), entry.getValue());
}
if (!isSignIn) {
builder.addParameter("id", env.getValidUserID());
}
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
HttpUriRequest request = builder.build();
inputStream = httpClient.execute(request, responseHandler);
} catch (IOException e) {
FRContext.getLogger().error(e.getMessage());
}
return inputStream;
}
public static InputStream headBeatConnection(RemoteEnv env) {
String path = env.getPath();
String username = env.getUser();
InputStream inputStream = null;
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
HttpUriRequest request = RequestBuilder.get(path)
.addParameter("op", "fr_remote_design")
.addParameter("cmd", "heart_beat")
.addParameter("user", username)
.addParameter("id", env.getValidUserID())
.build();
inputStream = httpClient.execute(request, responseHandler);
} catch (IOException | EnvException e) {
FRContext.getLogger().error(e.getMessage());
}
return inputStream;
}
public static InputStream testConnection(boolean isSignIn, RemoteEnv env) throws EnvException {
String username = env.getUser();
String path = env.getPath();
String password = env.getPassword();
InputStream inputStream = null;
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
RequestBuilder builder = RequestBuilder.get(path);
if (!isSignIn) {
builder.addParameter("id", env.getValidUserID());
}
HttpUriRequest request = builder
.addParameter("op", "fr_remote_design")
.addParameter("cmd", "test_server_connection")
.addParameter("user", username)
.addParameter("password", URLEncoder.encode(password, EncodeConstants.ENCODING_UTF_8))
.build();
inputStream = httpClient.execute(request, responseHandler);
} catch (IOException e) {
FRContext.getLogger().error(e.getMessage());
}
return inputStream;
}
public static InputStream updateAuthorities(DesignAuthority[] authorities, RemoteEnv env) throws EnvException {
String path = env.getPath(); String path = env.getPath();
// 远程设计临时用户id // 远程设计临时用户id
String userID = env.getUserID(); String userID = env.getValidUserID();
String res = null; InputStream inputStream = null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
AuthorityXMLUtils.writeDesignAuthoritiesXML(authorities, outputStream); AuthorityXMLUtils.writeDesignAuthoritiesXML(authorities, outputStream);
InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(outputStream.toByteArray()), ContentType.TEXT_XML); InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(outputStream.toByteArray()), ContentType.TEXT_XML);
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
HttpUriRequest request = RequestBuilder.post(path) HttpUriRequest request = RequestBuilder.post(path)
.addParameter("id", userID) .addParameter("id", userID)
.addParameter("op", "remote_design_authority") .addParameter("op", "remote_design_authority")
.addParameter("cmd", "update_authorities") .addParameter("cmd", "update_authorities")
.setEntity(reqEntity) .setEntity(reqEntity)
.build(); .build();
try (CloseableHttpResponse response = httpClient.execute(request)) { inputStream = httpClient.execute(request, responseHandler);
HttpEntity entity = response.getEntity();
res = IOUtils.inputStream2String(entity.getContent(), EncodeConstants.ENCODING_UTF_8);
EntityUtils.consume(entity);
}
} catch (IOException e) { } catch (IOException e) {
FRContext.getLogger().error(e.getMessage()); FRContext.getLogger().error(e.getMessage());
} }
return res != null && Boolean.valueOf(res); return inputStream;
} }
public static DesignAuthority[] getAuthorities(RemoteEnv env) { public static InputStream getAuthorities(RemoteEnv env) throws EnvException {
String path = env.getPath(); String path = env.getPath();
// 远程设计临时用户id // 远程设计临时用户id
String userID = env.getUserID(); String userID = env.getValidUserID();
DesignAuthority[] authorities = null; InputStream inputStream = null;
try (CloseableHttpClient httpClient = HttpClients.createDefault();) { try (CloseableHttpClient httpClient = HttpClients.createSystem();) {
HttpUriRequest request = RequestBuilder.get(path) HttpUriRequest request = RequestBuilder.get(path)
.addParameter("id", userID) .addParameter("id", userID)
.addParameter("op", "remote_design_authority") .addParameter("op", "remote_design_authority")
.addParameter("cmd", "get_authorities") .addParameter("cmd", "get_authorities")
.build(); .build();
inputStream = httpClient.execute(request, responseHandler);
try (CloseableHttpResponse response = httpClient.execute(request)) {
HttpEntity entity = response.getEntity();
authorities = AuthorityXMLUtils.readDesignAuthoritiesXML(entity.getContent());
EntityUtils.consume(entity);
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
}
} catch (IOException e) { } catch (IOException e) {
FRContext.getLogger().error(e.getMessage()); FRContext.getLogger().error(e.getMessage());
} }
return authorities; return inputStream;
} }
public static FileNode[] listFile(String pFilePath, boolean isWebReport, RemoteEnv env) { public static InputStream listFile(String pFilePath, boolean isWebReport, RemoteEnv env) throws EnvException {
String path = env.getPath(); String path = env.getPath();
// 远程设计临时用户id // 远程设计临时用户id
String userID = env.getUserID(); String userID = env.getValidUserID();
String username = env.getUser(); String username = env.getUser();
FileNode[] fileNodes = null; InputStream inputStream = null;
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpUriRequest request = RequestBuilder.get(path) HttpUriRequest request = RequestBuilder.get(path)
.addParameter("op", "fs_remote_design") .addParameter("op", "fs_remote_design")
.addParameter("cmd", "design_list_file") .addParameter("cmd", "design_list_file")
.addParameter("file_path", pFilePath) .addParameter("file_path", pFilePath)
.addParameter("currentUserName", username) .addParameter("currentUserName", username)
.addParameter("currentUserId", userID) .addParameter("currentUserId", userID)
.addParameter("id", userID)
.addParameter("isWebReport", Boolean.toString(isWebReport)) .addParameter("isWebReport", Boolean.toString(isWebReport))
.build(); .build();
inputStream = httpClient.execute(request, responseHandler);
try (CloseableHttpResponse response = httpClient.execute(request)) {
HttpEntity entity = response.getEntity();
fileNodes = DavXMLUtils.readXMLFileNodes((entity.getContent()));
EntityUtils.consume(entity);
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
}
} catch (IOException e) { } catch (IOException e) {
FRContext.getLogger().error(e.getMessage()); FRContext.getLogger().error(e.getMessage());
} }
return fileNodes != null ? fileNodes : new FileNode[0]; return inputStream;
} }
} }

Loading…
Cancel
Save