flowable-ui-idm,task,modeler 三个模块可以正常显示中文,但是flowable-ui-admin中文不能正常显示(flowable6.1.2以下版本包括该版本),比如我们定义了流程之后,显示查询之后,如下图所示:
下面,我们看一下这个bug出现的原因。首先我们看一下上传文档对应的实现,该服务功能位于DeploymentCollectionResource类中的uploadDeployment方法中,实例代码如下:
public DeploymentResponse uploadDeployment(@ApiParam(name = "deploymentKey") @RequestParam(value = "deploymentKey", required = false) String deploymentKey,
@ApiParam(name = "deploymentName") @RequestParam(value = "deploymentName", required = false) String deploymentName,
@ApiParam(name = "tenantId") @RequestParam(value = "tenantId", required = false) String tenantId,
HttpServletRequest request, HttpServletResponse response) {
......
if (StringUtils.isEmpty(deploymentName)) {
}
看到上述的代码StringUtils.isEmpty(deploymentName)就明白了,原来这个地方并没有进行编码工作,中文当然要乱码了,正确的写法,应该是对所有的参数进行解码,类似下面的代码:
URLDecoder.decode(string, "UTF-8")
如果这个问题,让我们自己解决可能有点麻烦,所以直接反馈给flowable官方了,目前官方已经修复了该bug。如下所示:
.../src/main/java/org/flowable/rest/service/api/repository/DeploymentCollectionResource.java
@@ -13,6 +13,8 @@
packageorg.flowable.rest.service.api.repository;
+importjava.io.UnsupportedEncodingException;
+importjava.net.URLDecoder;
importjava.util.HashMap;
importjava.util.Map;
importjava.util.zip.ZipInputStream;
@@ -143,6 +145,9 @@ public DeploymentResponse uploadDeployment(@ApiParam(name = "deploymentKey") @Re
thrownewFlowableIllegalArgumentException("Multipart request is required");
}
+StringqueryString=request.getQueryString();
+MapdecodedQueryStrings=splitQueryString(queryString);
+
MultipartHttpServletRequestmultipartRequest=(MultipartHttpServletRequest) request;
if(multipartRequest.getFileMap().size()==0) {
@@ -167,7 +172,7 @@ public DeploymentResponse uploadDeployment(@ApiParam(name = "deploymentKey") @Re
thrownewFlowableIllegalArgumentException("File must be of type .bpmn20.xml, .bpmn, .bar or .zip");
}
-if(StringUtils.isEmpty(deploymentName)) {
+if(!decodedQueryStrings.containsKey("deploymentName")||StringUtils.isEmpty(decodedQueryStrings.get("deploymentName"))) {
StringfileNameWithoutExtension=fileName.split("\\.")[0];
if(StringUtils.isNotEmpty(fileNameWithoutExtension)) {
@@ -176,11 +181,11 @@ public DeploymentResponse uploadDeployment(@ApiParam(name = "deploymentKey") @Re
deploymentBuilder.name(fileName);
}else{
- deploymentBuilder.name(deploymentName);
+ deploymentBuilder.name(decodedQueryStrings.get("deploymentName"));
}
-if(deploymentKey!=null) {
- deploymentBuilder.key(deploymentKey);
+if(decodedQueryStrings.containsKey("deploymentKey")||StringUtils.isNotEmpty(decodedQueryStrings.get("deploymentKey"))) {
+ deploymentBuilder.key(decodedQueryStrings.get("deploymentKey"));
}
if(tenantId!=null) {
@@ -200,4 +205,23 @@ public DeploymentResponse uploadDeployment(@ApiParam(name = "deploymentKey") @Re
thrownewFlowableException(e.getMessage(), e);
}
}
+
+publicMapsplitQueryString(StringqueryString) {
+MapqueryMap=newHashMap<>();
+for(Stringparam:queryString.split("&")) {
+ queryMap.put(StringUtils.substringBefore(param,"="), decode(StringUtils.substringAfter(param,"=")));
+ }
+returnqueryMap;
+ }
+
+protectedStringdecode(Stringstring) {
+if(string!=null) {
+try{
+returnURLDecoder.decode(string,"UTF-8");
+ }catch(UnsupportedEncodingExceptionuee) {
+thrownewIllegalStateException("JVM does not support UTF-8 encoding.", uee);
+ }
+ }
+returnnull;
+ }
}
2modules/flowable-ui-admin/src/main/webapp/scripts/app.js
@@ -208,7 +208,7 @@ flowableAdminApp
//.registerAvailableLanguageKeys(['en'], {
//'en-*': 'en'
//})
- .useSanitizeValueStrategy('sanitizeParameters')
+ .useSanitizeValueStrategy('escapeParameters')
.uniformLanguageTag('bcp47')
.determinePreferredLanguage();
2modules/flowable-ui-idm/flowable-ui-idm-app/src/main/webapp/scripts/idm-app.js
@@ -126,7 +126,7 @@ flowableApp
//.registerAvailableLanguageKeys(['en'], {
//'en-*': 'en'
//})
- .useSanitizeValueStrategy('sanitizeParameters')
+ .useSanitizeValueStrategy('escapeParameters')
.uniformLanguageTag('bcp47')
.determinePreferredLanguage();
}])
2modules/flowable-ui-modeler/flowable-ui-modeler-app/src/main/webapp/scripts/app.js
@@ -140,7 +140,7 @@ flowableModeler
//.registerAvailableLanguageKeys(['en'], {
//'en-*': 'en'
//})
- .useSanitizeValueStrategy('sanitizeParameters')
+ .useSanitizeValueStrategy('escapeParameters')
.uniformLanguageTag('bcp47')
.determinePreferredLanguage();
2modules/flowable-ui-task/flowable-ui-task-app/src/main/webapp/scripts/landing-app.js
@@ -66,7 +66,7 @@ flowableApp
//.registerAvailableLanguageKeys(['en'], {
//'en-*': 'en'
//})
- .useSanitizeValueStrategy('sanitizeParameters')
+ .useSanitizeValueStrategy('escapeParameters')
.uniformLanguageTag('bcp47')
.determinePreferredLanguage();
}])
2...es/flowable-ui-task/flowable-ui-task-app/src/main/webapp/workflow/scripts/workflow-app.js
@@ -112,7 +112,7 @@ flowableApp
//.registerAvailableLanguageKeys(['en'], {
//'en-*': 'en'
//})
- .useSanitizeValueStrategy('sanitizeParameters')
+ .useSanitizeValueStrategy('escapeParameters')
.uniformLanguageTag('bcp47')
.determinePreferredLanguage();