Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
开发团队
Flowable Engine
提交
8b3b750b
F
Flowable Engine
项目概览
开发团队
/
Flowable Engine
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Flowable Engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8b3b750b
编写于
7月 09, 2013
作者:
F
Frederik Heremans
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ACT-1740: Replacing newlines for status-name
上级
3daabd55
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
84 addition
and
4 deletion
+84
-4
modules/activiti-common-rest/src/main/java/org/activiti/rest/application/ActivitiStatusService.java
.../org/activiti/rest/application/ActivitiStatusService.java
+15
-4
modules/activiti-rest/src/test/java/org/activiti/rest/ActivitiStatusServiceTest.java
...est/java/org/activiti/rest/ActivitiStatusServiceTest.java
+69
-0
未找到文件。
modules/activiti-common-rest/src/main/java/org/activiti/rest/application/ActivitiStatusService.java
浏览文件 @
8b3b750b
...
...
@@ -37,6 +37,10 @@ import org.restlet.service.StatusService;
*/
public
class
ActivitiStatusService
extends
StatusService
{
protected
static
final
String
NEWLINE_REPLACE_REGEX
=
"\\r\\n|\\r|\\n"
;
/**
* Overriding this method to return a JSON-object representing the error that occurred instead of
* the default HTML body Restlet provides.
...
...
@@ -73,22 +77,29 @@ public class ActivitiStatusService extends StatusService {
if
(
throwable
instanceof
ActivitiObjectNotFoundException
)
{
// 404 - Entity not found
status
=
new
Status
(
Status
.
CLIENT_ERROR_NOT_FOUND
.
getCode
(),
throwable
.
getMessage
(
),
null
,
null
);
status
=
new
Status
(
Status
.
CLIENT_ERROR_NOT_FOUND
.
getCode
(),
getSafeStatusName
(
throwable
.
getMessage
()
),
null
,
null
);
}
else
if
(
throwable
instanceof
ActivitiIllegalArgumentException
)
{
// 400 - Bad Request
status
=
new
Status
(
Status
.
CLIENT_ERROR_BAD_REQUEST
.
getCode
(),
throwable
.
getMessage
(
),
null
,
null
);
status
=
new
Status
(
Status
.
CLIENT_ERROR_BAD_REQUEST
.
getCode
(),
getSafeStatusName
(
throwable
.
getMessage
()
),
null
,
null
);
}
else
if
(
throwable
instanceof
ActivitiOptimisticLockingException
||
throwable
instanceof
ActivitiTaskAlreadyClaimedException
)
{
// 409 - Conflict
status
=
new
Status
(
Status
.
CLIENT_ERROR_CONFLICT
.
getCode
(),
throwable
.
getMessage
(
),
null
,
null
);
status
=
new
Status
(
Status
.
CLIENT_ERROR_CONFLICT
.
getCode
(),
getSafeStatusName
(
throwable
.
getMessage
()
),
null
,
null
);
}
else
if
(
throwable
instanceof
ResourceException
)
{
ResourceException
re
=
(
ResourceException
)
throwable
;
status
=
re
.
getStatus
();
}
else
if
(
throwable
instanceof
ActivitiException
)
{
status
=
new
Status
(
Status
.
SERVER_ERROR_INTERNAL
.
getCode
(),
throwable
.
getMessage
(
),
null
,
null
);;
status
=
new
Status
(
Status
.
SERVER_ERROR_INTERNAL
.
getCode
(),
getSafeStatusName
(
throwable
.
getMessage
()
),
null
,
null
);;
}
else
{
status
=
null
;
}
return
status
;
}
protected
String
getSafeStatusName
(
String
name
)
{
if
(
name
!=
null
)
{
return
name
.
replaceAll
(
NEWLINE_REPLACE_REGEX
,
" "
);
}
return
null
;
}
}
modules/activiti-rest/src/test/java/org/activiti/rest/ActivitiStatusServiceTest.java
0 → 100644
浏览文件 @
8b3b750b
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.activiti.rest
;
import
junit.framework.TestCase
;
import
org.activiti.engine.ActivitiException
;
import
org.activiti.engine.ActivitiIllegalArgumentException
;
import
org.activiti.engine.ActivitiObjectNotFoundException
;
import
org.activiti.engine.ActivitiOptimisticLockingException
;
import
org.activiti.engine.ActivitiTaskAlreadyClaimedException
;
import
org.activiti.rest.application.ActivitiStatusService
;
import
org.restlet.data.Status
;
import
org.restlet.service.StatusService
;
/**
* @author Frederik Heremans
*/
public
class
ActivitiStatusServiceTest
extends
TestCase
{
private
StatusService
statusService
;
@Override
protected
void
setUp
()
throws
Exception
{
statusService
=
new
ActivitiStatusService
();
}
public
void
testNewlineInMessage
()
throws
Exception
{
Status
status
=
statusService
.
getStatus
(
new
ActivitiException
(
"This is a\n newline"
),
null
);
assertNotNull
(
status
);
assertEquals
(
"This is a newline"
,
status
.
getName
());
}
public
void
test404WhenNotFound
()
throws
Exception
{
Status
status
=
statusService
.
getStatus
(
new
ActivitiObjectNotFoundException
(
String
.
class
),
null
);
assertNotNull
(
status
);
assertEquals
(
Status
.
CLIENT_ERROR_NOT_FOUND
,
status
);
}
public
void
test400WhenIllegalArgument
()
throws
Exception
{
Status
status
=
statusService
.
getStatus
(
new
ActivitiIllegalArgumentException
(
"testing"
),
null
);
assertNotNull
(
status
);
assertEquals
(
Status
.
CLIENT_ERROR_BAD_REQUEST
,
status
);
}
public
void
test409WhenConflict
()
throws
Exception
{
Status
status
=
statusService
.
getStatus
(
new
ActivitiTaskAlreadyClaimedException
(
"id"
,
"assignee"
),
null
);
assertNotNull
(
status
);
assertEquals
(
Status
.
CLIENT_ERROR_CONFLICT
,
status
);
status
=
statusService
.
getStatus
(
new
ActivitiOptimisticLockingException
(
"testing"
),
null
);
assertNotNull
(
status
);
assertEquals
(
Status
.
CLIENT_ERROR_CONFLICT
,
status
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录