使用 Spring 的 Web 服务模拟器框架解决方案(9)技术实现步骤6
 
- UID
- 1066743
|

使用 Spring 的 Web 服务模拟器框架解决方案(9)技术实现步骤6
处理层处理层获得 inbound 键,该键将用于确认将要检索的 Spring XML 文件。检索到文件之后,SpringBeanFactory 将使用 XML 文件并将数据转换成已定义的 POJO。Spring 将会在所请求的 XML 文件无法定位时抛出一个封装的 IO Exception。在这种情况下,可以定义并返回默认的 XML 文件,当场景中已经确定了 “默认” 行为时,这项处理将很有用。另一方面是引入处理延迟来模拟事务延迟。这种情况下,常量延迟值会以 WebSphere Environment Provider 值的形式存储。
在清单 5 中,bf.getBean(clazzName) 根据模拟器服务中的键检索数据 XML。注意此处还有一个延迟注入检测,使用的是由 WebSphere Envrionment Provider 定义的值。
清单 5. 数据 XML 与延迟注入的检索示例1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| // Method used for retrieving spring xml
public static Object getDataByBeanId(String clazzName, String action, String key) throws
Exception {
String dataFile = null;
Object response = null;
// check if service is "enabled"
if ((ACCOUNT_SEARCH_ENABLED_KEY != null) && (ACCOUNT_SEARCH_ENABLED_KEY != "")
&& (ACCOUNT_SEARCH_ENABLED_KEY.equalsIgnoreCase("FALSE"))) {
throw new Exception("service is disabled");
}
dataFile = getFile(action, key);
com.simulator.SpringContext stsc = new com.simulator.SpringContext (
dataFile);
org.springframework.beans.factory.BeanFactory bf = stsc
.getBeanFactory();
// retrieve pojo
response = bf.getBean(clazzName);
// check i latency has been injected
if ((ACCOUNT_SEARCH_LATENCY_KEY != NULL) && (ACCOUNT_SEARCH_LATENCY_KEY.length() !=
0)) {
sleep(ACCOUNT_SEARCH_LATENCY_KEY;
}
return response;
|
|
|
|
|
|
|