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 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 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);
        }
        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);
        }