/** * Create a service request for the given ServiceToken. This method creates the request, populating * existing headers and cookies for the same service. The request is populated with all the defaults * for the service being invoked and requires only the request body to be set. Headers and cookies may be * manipulated as needed by the application before submitting the ServiceRequest via invokeService. * * @param serviceToken ServiceToken to be used for the creation of the request. * @return ServiceRequest with pre-populated headers, cookies and defaults for the service. * @since v2.0.6 */ public ServiceRequest GetServiceRequest(ServiceToken serviceToken) { // 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 getServiceRequest..."); } ServiceRequest result = null; if (this._delegate != null) { result = this._delegate.GetServiceRequest(serviceToken); if (logger != null) { logger.Log(ILoggingLogLevel.Debug, this.apiGroup.ToString(), "ServiceBridge executed 'getServiceRequest' in " + (TimerUtil.CurrentTimeMillis() - tIn) + "ms."); } } else { if (logger != null) { logger.Log(ILoggingLogLevel.Error, this.apiGroup.ToString(), "ServiceBridge no delegate for 'getServiceRequest'."); } } return(result); }
/** * Obtains a ServiceToken for the given parameters to be used for the creation of requests. * * @param serviceName Service name. * @param endpointName Endpoint name. * @param functionName Function name. * @param method Method type. * @return ServiceToken to create a service request or null if the given parameter combination is not * configured in the platform's XML service definition file. * @since v2.0.6 */ public ServiceToken GetServiceToken(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 getServiceToken..."); } ServiceToken result = null; if (this._delegate != null) { result = this._delegate.GetServiceToken(serviceName, endpointName, functionName, method); if (logger != null) { logger.Log(ILoggingLogLevel.Debug, this.apiGroup.ToString(), "ServiceBridge executed 'getServiceToken' in " + (TimerUtil.CurrentTimeMillis() - tIn) + "ms."); } } else { if (logger != null) { logger.Log(ILoggingLogLevel.Error, this.apiGroup.ToString(), "ServiceBridge no delegate for 'getServiceToken'."); } } return(result); }
/** * Sets the ServiceToken of the request. * * @param ServiceToken ServiceToken to be used for the invocation. * @since V2.0.6 */ public void SetServiceToken(ServiceToken ServiceToken) { this.ServiceToken = ServiceToken; }
/** * Convenience constructor. * * @param Content Content payload. * @param ServiceToken ServiceToken for the request. * @since V2.0.6 */ public ServiceRequest(string content, ServiceToken serviceToken) : base() { this.Content = Content; this.ServiceToken = ServiceToken; }
/** * 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); }