}
/** Ask the an JSONRPCBridge object to handle the json request. */
@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
WOResponse response = AjaxUtils.createResponse(request, context);
String inputString = request.contentString();
if (log.isDebugEnabled()) {
log.debug("AjaxProxy.handleRequest: input = " + inputString);
}
// Process the request
JSONObject input = null;
Object output = null;
try {
input = new JSONObject(inputString);
Object proxy;
if (canGetValueForBinding("proxy")) {
proxy = valueForBinding("proxy");
}
else {
proxy = parent();
}
String proxyName = (String) valueForBinding("proxyName");
JSONRPCBridge bridge = null;
if (canGetValueForBinding("AjaxBridge")) {
bridge = (JSONRPCBridge) valueForBinding("AjaxBridge");
}
else {
bridge = JSONBridge.createBridge();
if (canSetValueForBinding("AjaxBridge")) {
setValueForBinding(bridge, "AjaxBridge");
}
}
bridge.registerObject(proxyName, proxy);
output = bridge.call(new Object[] { request, context, response, proxy }, input);
}
catch (NoSuchElementException e) {
log.error("No method in request");
output = JSONRPCResult.MSG_ERR_NOMETHOD;
}
catch (Exception e) {
log.error("Exception", e);
output = JSONRPCResult.MSG_ERR_NOMETHOD;
}
// Write the response
if (log.isDebugEnabled()) {
log.debug("AjaxProxy.handleRequest: output = " + output);
}
response.appendContentString(output.toString());
return response;
}