看看這會有所幫助。這進入了擴展BaseEvaluator的類。通過Spring將bean連線,然後將評估者設置爲您的操作。
public boolean evaluate(JSONObject jsonObject) {
boolean result = false;
final RequestContext rc = ThreadLocalRequestContext.getRequestContext();
final String userId = rc.getUserId();
try {
final Connector conn = rc.getServiceRegistry().getConnectorService().getConnector("alfresco", userId, ServletUtil.getSession());
final Response response = conn.call("/someco/example?echo=false");
if (response.getStatus().getCode() == Status.STATUS_OK) {
System.out.println(response.getResponse());
try {
org.json.JSONObject json = new org.json.JSONObject(response.getResponse());
result = Boolean.parseBoolean(((String) json.get("result")));
} catch (JSONException je) {
je.printStackTrace();
return false;
}
} else {
System.out.println("Call failed, code:" + response.getStatus().getCode());
return false;
}
} catch (ConnectorServiceException cse) {
cse.printStackTrace();
return false;
}
return result;
}
在這個例子中,我用一個簡單的例子網頁腳本回顯您的JSON和交換機基於「回聲」參數的值的結果。所以當它用「false」調用時,JSON返回false並且評估器返回false。
我應該指出評估方法期望的org.json.simple.JSONObject與我用來攔截響應JSON結果的org.json.JSONObject之間的名稱衝突。
你看過BaseEvaluator的源代碼嗎?這應該回答你關於JSONObject的問題。你肯定需要自己調用回購層。 Surf框架已經支持這個功能,所以你應該可以利用Surf API來做到這一點。儘管找到一個例子有困難。 –