public PlatformMiddleware(IPlatform platform, IServiceMethod service, IPlatformMetrics metrics) { _platform = platform; _service = service; _logger = platform.GetLogger(typeof(PlatformMiddleware)); _metrics = metrics; }
/** * Convenience constructor. * * @param ServiceName Name of the configured service. * @param EndpointName Name of the endpoint configured for the service. * @param FunctionName Name of the function configured for the endpoint. * @param InvocationMethod Method type configured for the function. * @since V2.0.6 */ public ServiceToken(string serviceName, string endpointName, string functionName, IServiceMethod invocationMethod) : base() { this.ServiceName = ServiceName; this.EndpointName = EndpointName; this.FunctionName = FunctionName; this.InvocationMethod = InvocationMethod; }
/** * Invokes the given method specified in the API request object. * * @param request APIRequest object containing method name and parameters. * @return APIResponse with status code, message and JSON response or a JSON null string for void functions. Status code 200 is OK, all others are HTTP standard error conditions. */ public new APIResponse Invoke(APIRequest request) { APIResponse response = new APIResponse(); int responseCode = 200; String responseMessage = "OK"; String responseJSON = "null"; switch (request.GetMethodName()) { case "getServiceRequest": ServiceToken serviceToken0 = GetJSONProcessor().DeserializeObject <ServiceToken>(request.GetParameters()[0]); ServiceRequest response0 = this.GetServiceRequest(serviceToken0); if (response0 != null) { responseJSON = GetJSONProcessor().SerializeObject(response0); } break; case "getServiceToken": string serviceName1 = GetJSONProcessor().DeserializeObject <string>(request.GetParameters()[0]); string endpointName1 = GetJSONProcessor().DeserializeObject <string>(request.GetParameters()[1]); string functionName1 = GetJSONProcessor().DeserializeObject <string>(request.GetParameters()[2]); IServiceMethod method1 = GetJSONProcessor().DeserializeObject <IServiceMethod>(request.GetParameters()[3]); ServiceToken response1 = this.GetServiceToken(serviceName1, endpointName1, functionName1, method1); if (response1 != null) { responseJSON = GetJSONProcessor().SerializeObject(response1); } break; case "getServiceTokenByUri": string uri2 = GetJSONProcessor().DeserializeObject <string>(request.GetParameters()[0]); ServiceToken response2 = this.GetServiceTokenByUri(uri2); if (response2 != null) { responseJSON = GetJSONProcessor().SerializeObject(response2); } break; case "getServicesRegistered": ServiceToken[] response3 = this.GetServicesRegistered(); if (response3 != null) { responseJSON = GetJSONProcessor().SerializeObject(response3); } break; case "invokeService": ServiceRequest serviceRequest4 = GetJSONProcessor().DeserializeObject <ServiceRequest>(request.GetParameters()[0]); IServiceResultCallback callback4 = new ServiceResultCallbackImpl(request.GetAsyncId()); this.InvokeService(serviceRequest4, callback4); break; case "isServiceRegistered": string serviceName5 = GetJSONProcessor().DeserializeObject <string>(request.GetParameters()[0]); string endpointName5 = GetJSONProcessor().DeserializeObject <string>(request.GetParameters()[1]); string functionName5 = GetJSONProcessor().DeserializeObject <string>(request.GetParameters()[2]); IServiceMethod method5 = GetJSONProcessor().DeserializeObject <IServiceMethod>(request.GetParameters()[3]); bool response5 = this.IsServiceRegistered(serviceName5, endpointName5, functionName5, method5); responseJSON = GetJSONProcessor().SerializeObject(response5); break; default: // 404 - response null. responseCode = 404; responseMessage = "ServiceBridge does not provide the function '" + request.GetMethodName() + "' Please check your client-side API version; should be API version >= v2.2.15."; break; } response.SetResponse(responseJSON); response.SetStatusCode(responseCode); response.SetStatusMessage(responseMessage); return(response); }
/** * Sets the invocation method type. * * @param InvocationMethod Method type. * @since V2.0.6 */ public void SetInvocationMethod(IServiceMethod InvocationMethod) { this.InvocationMethod = InvocationMethod; }
/** * Checks whether a specific service, endpoint, function and method type is configured in the platform's * XML service definition file. * * @param serviceName Service name. * @param endpointName Endpoint name. * @param functionName Function name. * @param method Method type. * @return Returns true if the service is configured, false otherwise. * @since v2.0.6 */ public bool IsServiceRegistered(string serviceName, string endpointName, string functionName, IServiceMethod method) { // Start logging elapsed time. long tIn = TimerUtil.CurrentTimeMillis(); ILogging logger = AppRegistryBridge.GetInstance().GetLoggingBridge(); if (logger != null) { logger.Log(ILoggingLogLevel.Debug, this.apiGroup.ToString(), "ServiceBridge executing isServiceRegistered..."); } bool result = false; if (this._delegate != null) { result = this._delegate.IsServiceRegistered(serviceName, endpointName, functionName, method); if (logger != null) { logger.Log(ILoggingLogLevel.Debug, this.apiGroup.ToString(), "ServiceBridge executed 'isServiceRegistered' in " + (TimerUtil.CurrentTimeMillis() - tIn) + "ms."); } } else { if (logger != null) { logger.Log(ILoggingLogLevel.Error, this.apiGroup.ToString(), "ServiceBridge no delegate for 'isServiceRegistered'."); } } return(result); }