public BrokerMessage process(BrokerMessage request) { Data bodyData = Serializer.Serialize(request); log.debug(bodyData, "bodyData"); Entity entity = new DataEntity(bodyData); String requestUri; if (null == _authenticator) { requestUri = "/_dynamic_/open/services"; } else { if (_authenticator.AuthInt) { requestUri = "/_dynamic_/auth-int/services"; } else { requestUri = "/_dynamic_/auth/services"; } } HttpRequestAdapter requestAdapter = new HttpRequestAdapter(requestUri); requestAdapter.RequestEntity = entity; _httpDispatcher.post(requestAdapter, _authenticator, _responseHandler); return _responseHandler.getResponse(); }
public static String buildJavascriptFault(BrokerMessage request, Exception fault) { log.enteredMethod(); JsonOutput jsonWriter = new JsonStringOutput(); jsonWriter.append("jsonbroker.forwardFault(\"fault\","); JsonObjectHandler jsonObjectHandler = JsonObjectHandler.getInstance(); jsonObjectHandler.WriteValue(request.getMetaData(), jsonWriter); jsonWriter.append(",\""); jsonWriter.append(request.getServiceName()); jsonWriter.append("\",1,0,\""); jsonWriter.append(request.getMethodName()); jsonWriter.append("\","); jsonObjectHandler.WriteValue(FaultSerializer.ToJsonObject(fault), jsonWriter); jsonWriter.append(");"); String answer = jsonWriter.ToString(); log.debug(answer, "answer"); return answer; }
public static BaseException methodNotFound(Object originator, BrokerMessage request) { String methodName = request.getMethodName(); BaseException answer = new BaseException(originator, "Unknown methodName; methodName = '{0}'", methodName); answer.ErrorDomain = "jsonbroker.ServiceHelper.METHOD_NOT_FOUND"; answer.FaultCode = METHOD_NOT_FOUND; return answer; }
private static BrokerMessage process(ServicesRegistery servicesRegistery, BrokerMessage request) { try { return servicesRegistery.process(request); } catch (Exception e) { log.error(e); return BrokerMessage.buildFault(request, e); } }
public static Data Serialize(BrokerMessage message) { JsonStringOutput writer = new JsonStringOutput(); JsonArray messageComponents = message.ToJsonArray(); _jsonArrayHandler.WriteValue(messageComponents, writer); String json = writer.ToString(); byte[] jsonBytes = StringHelper.ToUtfBytes(json); Data answer = new Data(jsonBytes); return answer; }
private void dispachRequest(BrokerMessage request) { JsonArray requestArray = request.ToJsonArray(); byte[] endpointHeader = JsonArrayHelper.ToBytes(requestArray); // channel header ... { String channelHeader = "[\"jsonbroker.JsonbrokerEndpoint\",1,0,null," + endpointHeader.Length + "]\n"; log.debug(channelHeader, "channelHeader"); _channel.Write(channelHeader); } // endpoint header ... { _channel.Write(endpointHeader); _channel.Write(NEWLINE); } }
public static String buildJavascriptResponse(BrokerMessage response) { log.enteredMethod(); JsonStringOutput jsonWriter = new JsonStringOutput(); jsonWriter.append("jsonbroker.forwardResponse(\"response\","); JsonObjectHandler jsonObjectHandler = JsonObjectHandler.getInstance(); jsonObjectHandler.WriteValue(response.getMetaData(), jsonWriter); jsonWriter.append(",\""); jsonWriter.append(response.getServiceName()); jsonWriter.append("\",1,0,\""); jsonWriter.append(response.getMethodName()); jsonWriter.append("\","); jsonObjectHandler.WriteValue(response.GetAssociativeParamaters(), jsonWriter); JsonArray parameters = response.GetOrderedParamaters(); for (int i = 0, count = parameters.Count(); i < count; i++) { jsonWriter.append(','); Object blob = parameters.GetObject(i); JsonHandler handler = JsonHandler.getHandler(blob); handler.WriteValue(blob, jsonWriter); } jsonWriter.append(");"); String answer = jsonWriter.ToString(); log.debug(answer, "answer"); return answer; }
public static BrokerMessage deserialize(Data data) { JsonDataInput jsonInput = new JsonDataInput(data); JsonInputHelper.scanToNextToken(jsonInput); JsonArray messageComponents; try { messageComponents = _jsonArrayHandler.readJSONArray(jsonInput); } catch (BaseException exception) { exception.addContext("Serializer.dataOffset", jsonInput.Cursor); throw exception; } BrokerMessage answer = new BrokerMessage(messageComponents); return answer; }
public BrokerMessage process(BrokerMessage request) { String methodName = request.getMethodName(); if ("echo".Equals(methodName)) { JsonObject associativeParamaters = request.GetAssociativeParamaters(); associativeParamaters = this.echo(associativeParamaters); BrokerMessage answer = BrokerMessage.buildResponse(request); answer.SetAssociativeParamaters(associativeParamaters); return answer; } if ("ping".Equals(methodName)) { this.ping(); BrokerMessage response = BrokerMessage.buildResponse(request); return response; } if ("raiseError".Equals(methodName)) { this.raiseError(); BrokerMessage response = BrokerMessage.buildResponse(request); return response; } throw ServiceHelper.methodNotFound(this, request); }
public static BrokerMessage buildResponse(BrokerMessage request) { BrokerMessage answer = new BrokerMessage(); answer._messageType = BrokerMessageType.RESPONSE; answer._metaData = request.getMetaData(); answer._serviceName = request._serviceName; answer._methodName = request._methodName; answer._associativeParamaters = new JsonObject(); answer._orderedParamaters = new JsonArray(0); return answer; }
public static BrokerMessage buildFault(BrokerMessage request, Exception e) { BrokerMessage answer = new BrokerMessage(); answer._messageType = BrokerMessageType.FAULT; answer._metaData = request.getMetaData(); answer._serviceName = request._serviceName; answer._methodName = request._methodName; answer._associativeParamaters = FaultSerializer.ToJsonObject(e); answer._orderedParamaters = new JsonArray(0); return answer; }
public static BrokerMessage buildMetaRequest(String serviceName, String methodName) { BrokerMessage answer = new BrokerMessage(); answer._messageType = BrokerMessageType.META_REQUEST; answer._serviceName = serviceName; answer._methodName = methodName; return answer; }
public BrokerMessage process(BrokerMessage request) { String methodName = request.getMethodName(); if ("save_bundles".Equals(methodName)) { this.saveAllBundles(); return BrokerMessage.buildResponse(request); } if ("saveBundles".Equals(methodName)) { this.saveAllBundles(); return BrokerMessage.buildResponse(request); } if ("getBundle".Equals(methodName)) { JsonObject associativeParamaters = request.GetAssociativeParamaters(); String bundleName = associativeParamaters.GetString("bundle_name"); JsonObject bundleValue = getBundle(bundleName); BrokerMessage answer = BrokerMessage.buildResponse(request); associativeParamaters = answer.GetAssociativeParamaters(); associativeParamaters.put("bundle_name", bundleName); associativeParamaters.put("bundle_value", bundleValue); return answer; } throw ServiceHelper.methodNotFound(this, request); }
public BrokerMessage process(BrokerMessage request) { if (BrokerMessageType.META_REQUEST == request.getMessageType()) { return this.processMetaRequest(request); } Service serviceDelegate = this.getService( request.getServiceName() ); return serviceDelegate.process(request); }
private BrokerMessage processMetaRequest(BrokerMessage request) { String methodName = request.getMethodName(); if ("getVersion".Equals(methodName)) { JsonObject associativeParamaters = request.GetAssociativeParamaters(); String serviceName = request.getServiceName(); BrokerMessage answer = BrokerMessage.buildMetaResponse(request); associativeParamaters = answer.GetAssociativeParamaters(); if (!_services.ContainsKey(serviceName)) { associativeParamaters.put("exists", false); } else { associativeParamaters.put("exists", true); DescribedService describedService = _services[serviceName]; ServiceDescription serviceDescription = describedService.getServiceDescription(); associativeParamaters.put("majorVersion", serviceDescription.getMajorVersion()); associativeParamaters.put("minorVersion", serviceDescription.getMinorVersion()); } return answer; } throw ServiceHelper.methodNotFound(this, request); }
public BrokerMessage process(BrokerMessage request) { dispachRequest(request); return readResponse(); }