基本思路: 将BusinessServer的Table对象序列化XML或JSON格式数据,调用biz-client的api请求另一个BusinessServer.
代码类似:

1  发送端的代码

private static void test() {
String query = "select p, p.sName, p.sPhoto from SA_OPPerson p where p.sCode='test'";
Table table = KSQL.select(query, null, "/system/data", null);
table.getProperties().put(Table.PROP_NAME_ROWID, "p");
try {
Iterator it = table.iterator();
while (it.hasNext()) {
Row r = it.next();
for (String key : table.getColumnNames()) {
Object value = r.getValue(key);
if (value instanceof Clob) {
Clob clob = (Clob) value;
value = clob.getSubString(1, (int) clob.length());
} else if (value instanceof Blob) {
Blob blob = (Blob) value;
value = new String(blob.getBytes(1, (int) blob.length()));
}
System.out.print(key + "=" + value + ",");
}
System.out.println();
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage() + "", e);
}
ActionEngine.init("http://192.168.1.89:8080/BusinessServer");
String name = "system";
String password = "123456";
String ip = "127.0.0.1";
ActionResult ar = ActionEngine.login2(name, ActionUtils.md5(password), ip, null, new Date(System.currentTimeMillis()), new HashMap<String, Object>(), ActionUtils.JSON_CONTENT_TYPE, null);
if (ar.isSuccess()){
String bsessionID = ar.getBSessionID();
try{
Action action = new Action();
action.setProcess("/demo/process/process/and/andProcess");
action.setActivity("mainActivity");
action.setName("testTableWrapperAction");
TableWrapper tw = new TableWrapper();
tw.setTable(table);
Element e = tw.writer(null);
System.out.println(e.asXML());
action.setParameter("table", e);
ActionResult ar2 = ActionEngine.invokeAction(action, ActionUtils.JSON_CONTENT_TYPE, bsessionID, null, null);
if (ar2.isSuccess()){
JSONObject json = (JSONObject)ar2.getDatas().get(0);
System.out.println(json);
}else{
throw new RuntimeException(ar2.getMessage());
}
}catch(Exception e){
throw new RuntimeException(e.getMessage(), e);
}finally{
ActionEngine.logout(bsessionID);
}
}else{
throw new RuntimeException(ar.getMessage());
}
}

2  接收端的代码

public static void testTableWrapper(Document table){
try{
TableWrapper tw = new TableWrapper();
tw.reader(table.getRootElement(), null);
Table tobj = tw.getTable();
Iterator it = tobj.iterator();
while (it.hasNext()){
Row r = it.next();
for (String name : tobj.getColumnNames()){
Object value = r.getValue(name);
if (value instanceof Clob){
Clob clob = (Clob)value;
value = clob.getSubString(1, (int)clob.length());
}else if (value instanceof Blob){
Blob blob = (Blob)value;
value = new String(blob.getBytes(1, (int) blob.length()));
}
System.out.print(name + "=" + value + ",");
}
System.out.println();
}
}catch(Exception e){
throw new RuntimeException(e.getMessage()+"", e);
}
}

3  TableWrapper实现(参考附件)

 TableWrapper.java

 

本文由WeX5君整理,WeX5一款开源免费的html5开发工具H5 App开发就用WeX5!

阅读其他app 开发相关文章:http://doc.wex5.com/?p=3443