string GetExecutePayload(IDSFDataObject dataObject, IResource resource, WebRequestTO webRequest, ref DataListFormat formatter) { var notDebug = !dataObject.IsDebug || dataObject.RemoteInvoke || dataObject.RemoteNonDebugInvoke; if (notDebug && resource?.DataList != null) { switch (dataObject.ReturnType) { case EmitionTypes.XML: { return(ExecutionEnvironmentUtils.GetXmlOutputFromEnvironment(dataObject, resource.DataList.ToString(), 0)); } case EmitionTypes.SWAGGER: { formatter = DataListFormat.CreateFormat("SWAGGER", EmitionTypes.SWAGGER, "application/json"); return(ExecutionEnvironmentUtils.GetSwaggerOutputForService(resource, resource.DataList.ToString(), webRequest.WebServerUrl)); } default: case EmitionTypes.JSON: { formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); return(ExecutionEnvironmentUtils.GetJsonOutputFromEnvironment(dataObject, resource.DataList.ToString(), 0)); } } } return(string.Empty); }
public static string SetEmitionType(this IDSFDataObject dataObject, WebRequestTO webRequest, string serviceName, NameValueCollection headers) { int extensionStartLocation; var originalServiceName = serviceName; if (!string.IsNullOrEmpty(serviceName) && (extensionStartLocation = serviceName.LastIndexOf(".", StringComparison.Ordinal)) > 0) { dataObject.ReturnType = EmitionTypes.XML; if (extensionStartLocation > 0) { var extension = serviceName.Substring(extensionStartLocation + 1); serviceName = SetReturnTypeForExtension(dataObject, extensionStartLocation, originalServiceName, extension); } } else { if (serviceName == "*" && webRequest.WebServerUrl.EndsWith("/.tests", StringComparison.InvariantCultureIgnoreCase)) { dataObject.ReturnType = EmitionTypes.TEST; } if (serviceName == "*" && webRequest.WebServerUrl.EndsWith("/.tests.trx", StringComparison.InvariantCultureIgnoreCase)) { dataObject.ReturnType = EmitionTypes.TRX; } dataObject.SetContentType(headers); } return(serviceName); }
#pragma warning restore CC0044 protected IResponseWriter CreateForm(WebRequestTO webRequest, string serviceName, string workspaceId, NameValueCollection headers, IPrincipal user) { var a = new Executor.Executor(_workspaceRepository, _resourceCatalog, _testCatalog, _testCoverageCatalog, _serviceTestExecutor, _authorizationService, _dataObjectFactory, _esbChannelFactory, _jwtManager); var response = a.TryExecute(webRequest, serviceName, workspaceId, headers, user); return(response ?? a.BuildResponse(webRequest, serviceName)); }
public override void ProcessRequest(ICommunicationContext ctx) { var postDataListID = GetDataListID(ctx); if (postDataListID != null) { new WebPostRequestHandler().ProcessRequest(ctx); return; } var serviceName = GetServiceName(ctx); var workspaceID = GetWorkspaceID(ctx); var requestTO = new WebRequestTO { ServiceName = serviceName, WebServerUrl = ctx.Request.Uri.ToString(), Dev2WebServer = String.Format("{0}://{1}", ctx.Request.Uri.Scheme, ctx.Request.Uri.Authority) }; var data = GetPostData(ctx, Guid.Empty.ToString()); if (!String.IsNullOrEmpty(data)) { requestTO.RawRequestPayload = data; } // Execute in its own thread to give proper context ;) Thread.CurrentPrincipal = ctx.Request.User; var responseWriter = CreateForm(requestTO, serviceName, workspaceID, ctx.FetchHeaders(), PublicFormats); ctx.Send(responseWriter); }
public override void ProcessRequest(ICommunicationContext ctx) { var serviceName = GetServiceName(ctx); var instanceId = GetInstanceID(ctx); var bookmark = GetBookmark(ctx); var postDataListID = GetDataListID(ctx); var workspaceID = GetWorkspaceID(ctx); var requestTO = new WebRequestTO(); var xml = GetPostData(ctx, postDataListID); if (!String.IsNullOrEmpty(xml)) { requestTO.RawRequestPayload = xml; } requestTO.ServiceName = serviceName; requestTO.InstanceID = instanceId; requestTO.Bookmark = bookmark; requestTO.WebServerUrl = ctx.Request.Uri.ToString(); requestTO.Dev2WebServer = String.Format("{0}://{1}", ctx.Request.Uri.Scheme, ctx.Request.Uri.Authority); // Execute in its own thread to give proper context ;) Thread.CurrentPrincipal = ctx.Request.User; var responseWriter = CreateForm(requestTO, serviceName, workspaceID, ctx.FetchHeaders(), PublicFormats, ctx.Request.User); ctx.Send(responseWriter); }
public override void ProcessRequest(ICommunicationContext ctx) { var serviceName = ctx.GetServiceName(); var instanceId = ctx.GetInstanceID(); var bookmark = ctx.GetBookmark(); var workspaceId = ctx.GetWorkspaceID(); var requestTo = new WebRequestTO(); var xml = new SubmittedData().GetPostData(ctx); if (!string.IsNullOrEmpty(xml)) { requestTo.RawRequestPayload = xml; } requestTo.ServiceName = serviceName; requestTo.InstanceID = instanceId; requestTo.Bookmark = bookmark; requestTo.WebServerUrl = ctx.Request.Uri.ToString(); requestTo.Dev2WebServer = $"{ctx.Request.Uri.Scheme}://{ctx.Request.Uri.Authority}"; var variables = ctx.Request.BoundVariables; if (variables != null) { foreach (string key in variables) { requestTo.Variables.Add(key, variables[key]); } } Thread.CurrentPrincipal = ctx.Request.User; var responseWriter = CreateForm(requestTo, serviceName, workspaceId, ctx.FetchHeaders(), ctx.Request.User); ctx.Send(responseWriter); }
public static void BindRequestVariablesToDataObject(this WebRequestTO request, ref IDSFDataObject dataObject) { if (dataObject == null || request == null) { return; } if (!string.IsNullOrEmpty(request.Bookmark)) { dataObject.CurrentBookmarkName = request.Bookmark; } if (!string.IsNullOrEmpty(request.InstanceID) && Guid.TryParse(request.InstanceID, out Guid tmpId)) { dataObject.WorkflowInstanceId = tmpId; } if (!string.IsNullOrEmpty(request.ServiceName) && string.IsNullOrEmpty(dataObject.ServiceName)) { dataObject.ServiceName = request.ServiceName; } foreach (string key in request.Variables) { dataObject.Environment.Assign(DataListUtil.AddBracketsToValueIfNotExist(key), request.Variables[key], 0); } }
public static string GetPathForAllResources(this WebRequestTO webRequest) { var publicvalue = webRequest.Variables["isPublic"]; var isPublic = bool.Parse(publicvalue ?? "False"); var path = ""; var webServerUrl = webRequest.WebServerUrl; if (isPublic) { var pathStartIndex = webServerUrl.IndexOf("public/", StringComparison.InvariantCultureIgnoreCase); path = webServerUrl.Substring(pathStartIndex) .Replace("/.tests", "") .Replace("public", "") .Replace("Public", "") .TrimStart('/') .TrimEnd('/'); } if (!isPublic) { var pathStartIndex = webServerUrl.IndexOf("secure/", StringComparison.InvariantCultureIgnoreCase); path = webServerUrl.Substring(pathStartIndex) .Replace("/.tests", "") .Replace("secure", "") .Replace("Secure", "") .TrimStart('/') .TrimEnd('/'); } return(path.Replace("/", "\\")); }
private IResponseWriter DefaultExecutionResponse(WebRequestTO webRequest, string serviceName, ExecutionDto executionDto) { var allErrors = new ErrorResultTO(); var currentErrors = executionDto.DataObject.Environment?.Errors?.Union(executionDto.DataObject.Environment?.AllErrors); if (currentErrors != null) { foreach (var error in currentErrors) { if (error.Length > 0) { allErrors.AddError(error, true); } } } executionDto.Request = _esbExecuteRequest; executionDto.ErrorResultTO = allErrors; var executionDtoExtentions = new ExecutionDtoExtentions(executionDto); return(executionDtoExtentions.CreateResponseWriter(new StringResponseWriterFactory())); }
public void ExecutionDtoExtentions_CreateResponseWriter_NotWasInternalService_And_EmitionTypesSWAGGER_Success() { //-------------------------------Arrange---------------------------------- var mockDSFDataObject = new Mock <IDSFDataObject>(); var mockResource = new Mock <IResource>(); mockResource.Setup(o => o.DataList).Returns(new StringBuilder("<DataList>the test string to be built</DataList>")); mockDSFDataObject.Setup(o => o.Environment.HasErrors()).Returns(false); mockDSFDataObject.Setup(o => o.ReturnType).Returns(EmitionTypes.SWAGGER); var dataListDataFormat = DataListFormat.CreateFormat("SWAGGER", EmitionTypes.SWAGGER, "application/json"); var webRequestTO = new WebRequestTO { WebServerUrl = "http://serverName:3142/public/resourceName.api" }; var executionDto = new ExecutionDto { Resource = mockResource.Object, DataObject = mockDSFDataObject.Object, ErrorResultTO = new ErrorResultTO(), DataListFormat = dataListDataFormat, WebRequestTO = webRequestTO, }; var executionDtoExtentions = new ExecutionDtoExtentions(executionDto); //-------------------------------Act-------------------------------------- executionDtoExtentions.CreateResponseWriter(new StringResponseWriterFactory()); //-------------------------------Assert----------------------------------- Assert.AreEqual(expected: "{\r\n \"swagger\": 2,\r\n \"info\": {\r\n \"title\": null,\r\n \"description\": \"\",\r\n \"version\": \"1.0.0\"\r\n },\r\n \"host\": \":0/\",\r\n \"basePath\": \"/\",\r\n \"schemes\": [\r\n \"http\"\r\n ],\r\n \"produces\": [\r\n \"application/json\",\r\n \"application/xml\"\r\n ],\r\n \"paths\": {\r\n \"serviceName\": \"/public/resourceName.api\",\r\n \"get\": {\r\n \"summary\": \"\",\r\n \"description\": \"\",\r\n \"parameters\": []\r\n }\r\n },\r\n \"responses\": {\r\n \"200\": {\r\n \"schema\": {\r\n \"$ref\": \"#/definition/Output\"\r\n }\r\n }\r\n },\r\n \"definitions\": {\r\n \"Output\": {\r\n \"type\": \"object\",\r\n \"properties\": {}\r\n }\r\n }\r\n}", actual: executionDto.PayLoad); }
protected static void BindRequestVariablesToDataObject(WebRequestTO request, ref DsfDataObject dataObject) { if (dataObject != null && request != null) { if (!string.IsNullOrEmpty(request.Bookmark)) { dataObject.CurrentBookmarkName = request.Bookmark; } if (!string.IsNullOrEmpty(request.InstanceID)) { Guid tmpId; if (Guid.TryParse(request.InstanceID, out tmpId)) { dataObject.WorkflowInstanceId = tmpId; } } if (!string.IsNullOrEmpty(request.ServiceName) && string.IsNullOrEmpty(dataObject.ServiceName)) { dataObject.ServiceName = request.ServiceName; } foreach (string key in request.Variables) { dataObject.Environment.Assign(DataListUtil.AddBracketsToValueIfNotExist(key), request.Variables[key], 0); } } }
internal IResponseWriter TryExecute(WebRequestTO webRequest, string serviceName, string workspaceId, NameValueCollection headers, IPrincipal user) { _workspaceGuid = EnsureWorkspaceIdValid(workspaceId); _serializer = new Dev2JsonSerializer(); PrepareDataObject(webRequest, serviceName, headers, user, _workspaceGuid, out _resource); var isTestCoverage = _dataObject.ReturnType == EmitionTypes.Cover || _dataObject.ReturnType == EmitionTypes.CoverJson; var isTestRun = (_dataObject.ReturnType == EmitionTypes.TEST || _dataObject.ReturnType == EmitionTypes.TRX) && _dataObject.TestName == "*"; if (isTestRun) { if (_serviceTestExecutor == null) { _serviceTestExecutor = new ServiceTestExecutor(); } return(ExecuteAsTest(user)); } if (isTestCoverage) { return(ExecuteAsCoverage(webRequest, serviceName, _resource)); } if (_resource is null) { var msg = string.Format(Warewolf.Resource.Errors.ErrorResource.ServiceNotFound, serviceName); _dataObject.Environment.AddError(msg); _dataObject.ExecutionException = new Exception(msg); _executionDataListId = GlobalConstants.NullDataListID; return(null); } var workflowCanBeExecutedByGroup = _dataObject.CanExecuteCurrentResource(_resource, _authorizationService); _canExecute = workflowCanBeExecutedByGroup; _executionDataListId = GlobalConstants.NullDataListID; if (!_canExecute) { var message = webRequest.IsUrlWithTokenPrefix ? Warewolf.Resource.Errors.ErrorResource.TokenNotAuthorizedToExecuteOuterWorkflowException : Warewolf.Resource.Errors.ErrorResource.UserNotAuthorizedToExecuteOuterWorkflowException; var errorMessage = string.Format(message, _dataObject.ExecutingUser?.Identity.Name, _dataObject.ServiceName); _dataObject.Environment.AddError(errorMessage); _dataObject.ExecutionException = new AccessDeniedException(errorMessage); } else { if (_dataObject.ReturnType != EmitionTypes.OPENAPI) { Thread.CurrentPrincipal = user; _executionDataListId = DoExecution(webRequest, serviceName, _workspaceGuid, _dataObject, user); } } return(null); }
static IDSFDataObject CreateNewDsfDataObject(WebRequestTO webRequest, string serviceName, IPrincipal user, Guid workspaceGuid) => _dataObject ?? new DsfDataObject(webRequest.RawRequestPayload, GlobalConstants.NullDataListID, webRequest.RawRequestPayload) { IsFromWebServer = true, ExecutingUser = user, ServiceName = serviceName, WorkspaceID = workspaceGuid, ExecutionID = Guid.NewGuid() };
protected IResponseWriter CreateForm(WebRequestTO webRequest, string serviceName, string workspaceId, NameValueCollection headers, IPrincipal user) { var a = new Executor(_workspaceRepository, _resourceCatalog, _testCatalog, _authorizationService, _dataObjectFactory); var response = a.TryExecute(webRequest, serviceName, workspaceId, headers, user); if (response is null) { return(a.BuildResponse(webRequest, serviceName)); } return(response); }
public static void SetupForWebDebug(this IDSFDataObject dataObject, WebRequestTO webRequest) { var contains = webRequest?.Variables?.AllKeys.Contains("IsDebug"); if (contains != null && contains.Value) { dataObject.IsDebug = true; dataObject.IsDebugFromWeb = true; dataObject.ClientID = Guid.NewGuid(); dataObject.DebugSessionID = Guid.NewGuid(); } }
private Guid DoExecution(WebRequestTO webRequest, string serviceName, Guid workspaceGuid, IDSFDataObject dataObject, IPrincipal userPrinciple) { _esbExecuteRequest = CreateEsbExecuteRequestFromWebRequest(webRequest, serviceName); var executionDataListId = Guid.Empty; Common.Utilities.PerformActionInsideImpersonatedContext(userPrinciple, () => { executionDataListId = dataObject.EsbChannel.ExecuteRequest(dataObject, _esbExecuteRequest, workspaceGuid, out _); _executePayload = _esbExecuteRequest.ExecuteResult.ToString(); }); return(executionDataListId); }
public static void SetupForTestExecution(this IDSFDataObject dataObject, WebRequestTO requestTO, string serviceName, NameValueCollection headers) { if (requestTO.IsRunAllTestsRequest(serviceName)) { dataObject.ReturnType = EmitionTypes.TEST; dataObject.IsServiceTestExecution = true; dataObject.TestName = "*"; } else { dataObject.SetContentType(headers); } }
private IResponseWriter ServiceTestExecutionResponse(WebRequestTO webRequest, string serviceName, ref string executePayload, IDSFDataObject dataObject, Dev2JsonSerializer serializer, bool canExecute) { var formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); if (!canExecute) { return(new StringResponseWriter(dataObject.Environment.FetchErrors(), formatter.ContentType)); } //var esbExecuteRequest = CreateEsbExecuteRequestFromWebRequest(webRequest, serviceName); executePayload = ServiceTestExecutor.SetupForTestExecution(serializer, _esbExecuteRequest, dataObject); return(new StringResponseWriter(executePayload, formatter.ContentType)); }
public override void ProcessRequest(ICommunicationContext ctx) { var serviceName = GetServiceName(ctx); var instanceId = GetInstanceID(ctx); var bookmark = GetBookmark(ctx); GetDataListID(ctx); var workspaceID = GetWorkspaceID(ctx); var formData = new WebRequestTO(); var xml = GetPostData(ctx); if (!String.IsNullOrEmpty(xml)) { formData.RawRequestPayload = xml; } formData.ServiceName = serviceName; formData.InstanceID = instanceId; formData.Bookmark = bookmark; formData.WebServerUrl = ctx.Request.Uri.ToString(); formData.Dev2WebServer = String.Format("{0}://{1}", ctx.Request.Uri.Scheme, ctx.Request.Uri.Authority); if (ExecutingUser == null) { throw new Exception("Null Executing User"); } try { // Execute in its own thread to give proper context ;) var t = new Thread(() => { Thread.CurrentPrincipal = ExecutingUser; var responseWriter = CreateForm(formData, serviceName, workspaceID, ctx.FetchHeaders(), ctx.Request.User); ctx.Send(responseWriter); }); t.Start(); t.Join(); } catch (Exception e) { // ReSharper disable InvokeAsExtensionMethod Dev2Logger.Log.Error(this, e); // ReSharper restore InvokeAsExtensionMethod } }
protected IResponseWriter ExecuteWorkflow(WebRequestTO webRequest, string serviceName, string workspaceId, NameValueCollection headers, IPrincipal user) { if (!serviceName.Contains(".json")) { serviceName += ".json"; } var a = new Executor(_workspaceRepository, _resourceCatalog, _authorizationService, _dataObjectFactory, _esbChannelFactory, _jwtManager); a.TryExecute(webRequest, serviceName, workspaceId, headers, user); var response = a.BuildResponse(webRequest, serviceName); return(response); }
private static EsbExecuteRequest CreateEsbExecuteRequestFromWebRequest(WebRequestTO webRequest, string serviceName) { var esbExecuteRequest = new EsbExecuteRequest { ServiceName = serviceName, }; foreach (string key in webRequest.Variables) { esbExecuteRequest.AddArgument(key, new StringBuilder(webRequest.Variables[key])); } return(esbExecuteRequest); }
private IResponseWriter ExecuteAsCoverage(WebRequestTO webRequest, string serviceName, IWarewolfResource resource) { try { var coverageDataContext = new CoverageDataContext(_dataObject.ResourceID, _dataObject.ReturnType, webRequest.WebServerUrl); coverageDataContext.SetTestCoverageResourceIds(_resourceCatalog.NewContextualResourceCatalog(_authorizationService, _workspaceGuid), webRequest, serviceName, resource); var formatter = ServiceTestCoverageExecutor.GetTestCoverageReports(coverageDataContext, _workspaceGuid, _serializer, _testCoverageCatalog, _resourceCatalog, out _executePayload); return(new StringResponseWriter(_executePayload ?? string.Empty, formatter.ContentType)); } finally { Dev2DataListDecisionHandler.Instance.RemoveEnvironment(_dataObject.DataListID); _dataObject.Environment = null; } }
public override void ProcessRequest(ICommunicationContext ctx) { LoadSecuritySettings(); var serviceName = ctx.GetServiceName(); var instanceId = ctx.GetInstanceID(); var bookmark = ctx.GetBookmark(); var workspaceId = ctx.GetWorkspaceID(); var requestTo = new WebRequestTO { ServiceName = serviceName, InstanceID = instanceId, Bookmark = bookmark, WebServerUrl = $"{ctx.Request.Uri.Scheme}://{ctx.Request.Uri.Authority}/public/{OverrideResource.Name}", Dev2WebServer = $"{ctx.Request.Uri.Scheme}://{ctx.Request.Uri.Authority}" }; var data = SubmittedData.GetPostData(ctx); if (!string.IsNullOrEmpty(data)) { requestTo.RawRequestPayload = data; } var variables = ctx.Request.BoundVariables; if (variables != null) { foreach (string key in variables) { requestTo.Variables.Add(key, variables[key]); } } Thread.CurrentPrincipal = ctx.Request.User; try { var response = ExecuteWorkflow(requestTo, $"{OverrideResource.Name}.json", workspaceId, ctx.FetchHeaders(), ctx.Request.User); ctx.Send(response); } catch (Exception e) { Dev2Logger.Warn($"failed processing login request: {e.Message}", GlobalConstants.WarewolfWarn); throw; } }
public override void ProcessRequest(ICommunicationContext ctx) { var serviceName = GetServiceName(ctx); var instanceId = GetInstanceID(ctx); var bookmark = GetBookmark(ctx); GetDataListID(ctx); var workspaceId = GetWorkspaceID(ctx); var formData = new WebRequestTO(); var xml = GetPostData(ctx); if (!string.IsNullOrEmpty(xml)) { formData.RawRequestPayload = xml; } formData.ServiceName = serviceName; formData.InstanceID = instanceId; formData.Bookmark = bookmark; formData.WebServerUrl = ctx.Request.Uri.ToString(); formData.Dev2WebServer = $"{ctx.Request.Uri.Scheme}://{ctx.Request.Uri.Authority}"; if (ExecutingUser == null) { throw new Exception(ErrorResource.NullExecutingUser); } try { // Execute in its own thread to give proper context ;) var t = new Thread(() => { Thread.CurrentPrincipal = ExecutingUser; var responseWriter = CreateForm(formData, serviceName, workspaceId, ctx.FetchHeaders(), ctx.Request.User); ctx.Send(responseWriter); }); t.Start(); t.Join(); } catch (Exception e) { Dev2Logger.Error(this, e, GlobalConstants.WarewolfError); } }
internal void PrepareDataObject(WebRequestTO webRequest, string serviceName, NameValueCollection headers, IPrincipal user, Guid workspaceGuid, out IResource resource) { _dataObject = _dataObjectFactory.New(workspaceGuid, user, serviceName, webRequest); _dataObject.SetupForWebDebug(webRequest); webRequest.BindRequestVariablesToDataObject(ref _dataObject); _dataObject.SetupForRemoteInvoke(headers); _dataObject.SetEmitionType(webRequest, serviceName, headers); _dataObject.SetupForTestExecution(serviceName, headers); if (_dataObject.ServiceName == null) { _dataObject.ServiceName = serviceName; } _dataObject.SetResourceNameAndId(_resourceCatalog, serviceName, out resource); _dataObject.SetTestResourceIds(_resourceCatalog, webRequest, serviceName); _dataObject.WebUrl = webRequest.WebServerUrl; _dataObject.EsbChannel = new EsbServicesEndpoint(); }
public void ExecutionDtoExtensions_CreateResponseWriter_NotWasInternalService_And_EmitionTypesSWAGGER_Success() { //-------------------------------Arrange---------------------------------- var mockDataObject = new Mock <IDSFDataObject>(); var mockResource = new Mock <IWarewolfResource>(); mockResource.Setup(resource => resource.ResourceName).Returns("resourceName"); var versionInfo = new VersionInfo { VersionNumber = "1.0" }; mockResource.Setup(resource => resource.VersionInfo).Returns(versionInfo); mockResource.Setup(o => o.DataList).Returns(new StringBuilder("<DataList>the test string to be built</DataList>")); mockDataObject.Setup(o => o.Environment.HasErrors()).Returns(false); mockDataObject.Setup(o => o.ReturnType).Returns(EmitionTypes.SWAGGER); var dataListDataFormat = DataListFormat.CreateFormat("SWAGGER", EmitionTypes.SWAGGER, "application/json"); var webRequestTO = new WebRequestTO { WebServerUrl = "http://serverName:3142/public/resourceName.api" }; var executionDto = new ExecutionDto { Resource = mockResource.Object, DataObject = mockDataObject.Object, ErrorResultTO = new ErrorResultTO(), DataListFormat = dataListDataFormat, WebRequestTO = webRequestTO, }; var executionDtoExtensions = new ExecutionDtoExtensions(executionDto); //-------------------------------Act-------------------------------------- executionDtoExtensions.CreateResponseWriter(new StringResponseWriterFactory()); //-------------------------------Assert----------------------------------- var expectedPayload = "{\r\n \"openapi\": \"3.0.1\",\r\n \"info\": {\r\n \"title\": \"resourceName\",\r\n \"description\": \"resourceName\",\r\n \"version\": \"1.0\"\r\n },\r\n \"servers\": [\r\n {\r\n \"url\": \"http://servername\"\r\n }\r\n ],\r\n \"paths\": {\r\n \"/public/resourceName\": {\r\n \"get\": {\r\n \"tags\": [\r\n \"\"\r\n ],\r\n \"description\": \"\",\r\n \"parameters\": [],\r\n \"responses\": {\r\n \"200\": {\r\n \"description\": \"Success\",\r\n \"content\": {\r\n \"application/json\": {\r\n \"schema\": {\r\n \"type\": \"object\",\r\n \"properties\": {}\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}"; Assert.AreEqual(expected: expectedPayload, actual: executionDto.PayLoad); }
public override void ProcessRequest(ICommunicationContext ctx) { var postDataListId = ctx.GetDataListID(); if (postDataListId != null) { new WebPostRequestHandler(_resourceCatalog, _testCatalog, _testCoverageCatalog, _esbChannelFactory).ProcessRequest(ctx); return; } var serviceName = ctx.GetServiceName(); var workspaceId = ctx.GetWorkspaceID(); var requestTo = new WebRequestTO { ServiceName = serviceName, WebServerUrl = ctx.Request.Uri.ToString(), Dev2WebServer = $"{ctx.Request.Uri.Scheme}://{ctx.Request.Uri.Authority}", IsUrlWithTokenPrefix = ctx.Request.IsTokenAuthentication }; var data = new SubmittedData().GetPostData(ctx); if (!string.IsNullOrEmpty(data)) { requestTo.RawRequestPayload = data; } var variables = ctx.Request.BoundVariables; if (variables != null) { foreach (string key in variables) { requestTo.Variables.Add(key, variables[key]); } } // Execute in its own thread to give proper context ;) Thread.CurrentPrincipal = ctx.Request.User; var responseWriter = CreateForm(requestTo, serviceName, workspaceId, ctx.FetchHeaders(), ctx.Request.User); ctx.Send(responseWriter); }
public override void ProcessRequest(ICommunicationContext ctx) { var postDataListID = ctx.GetDataListID(); if (postDataListID != null) { _catalog = _catalog ?? ResourceCatalog.Instance; _testCatalog = _testCatalog ?? TestCatalog.Instance; new WebPostRequestHandler(_catalog, _testCatalog).ProcessRequest(ctx); return; } var serviceName = ctx.GetServiceName(); var workspaceID = ctx.GetWorkspaceID(); var requestTO = new WebRequestTO { ServiceName = serviceName, WebServerUrl = ctx.Request.Uri.ToString(), Dev2WebServer = $"{ctx.Request.Uri.Scheme}://{ctx.Request.Uri.Authority}" }; var data = SubmittedData.GetPostData(ctx); if (!string.IsNullOrEmpty(data)) { requestTO.RawRequestPayload = data; } var variables = ctx.Request.BoundVariables; if (variables != null) { foreach (string key in variables) { requestTO.Variables.Add(key, variables[key]); } } // Execute in its own thread to give proper context ;) Thread.CurrentPrincipal = ctx.Request.User; var responseWriter = CreateForm(requestTO, serviceName, workspaceID, ctx.FetchHeaders(), ctx.Request.User); ctx.Send(responseWriter); }
internal IResponseWriter BuildResponse(WebRequestTO webRequest, string serviceName) { if (_dataObject.IsServiceTestExecution) { return(ServiceTestExecutionResponse(out _executePayload, _dataObject, _serializer, _canExecute)); } if (_dataObject.IsDebugFromWeb) { return(DebugFromWebExecutionResponse(_dataObject, _serializer)); } DataListFormat formatter; if (webRequest.ServiceName.EndsWith(".xml") || _dataObject.ReturnType == EmitionTypes.XML) { formatter = DataListFormat.CreateFormat("XML", EmitionTypes.XML, "text/xml"); } else { formatter = DataListFormat.CreateFormat("JSON", EmitionTypes.JSON, "application/json"); } var executionDto = new ExecutionDto { WebRequestTO = webRequest, ServiceName = serviceName, DataObject = _dataObject, DataListIdGuid = _executionDataListId, WorkspaceID = _workspaceGuid, Resource = _resource, DataListFormat = formatter, PayLoad = _executePayload ?? string.Empty, Serializer = _serializer, }; return(DefaultExecutionResponse(executionDto)); }
void PrepareDataObject(WebRequestTO webRequest, string serviceName, NameValueCollection headers, IPrincipal user, Guid workspaceGuid, out IWarewolfResource resource) { var uri = string.IsNullOrWhiteSpace(webRequest.WebServerUrl) ? new Uri("https://test/") : new Uri(webRequest.WebServerUrl); _dataObject = _dataObjectFactory.New(workspaceGuid, user, serviceName, webRequest); _dataObject.OriginalServiceName = serviceName; _dataObject.SetHeaders(headers); _dataObject.SetupForWebDebug(webRequest); webRequest.BindRequestVariablesToDataObject(ref _dataObject); _dataObject.SetupForRemoteInvoke(headers); _dataObject.SetEmissionType(uri, serviceName, headers); _dataObject.SetupForTestExecution(serviceName, headers); if (_dataObject.ServiceName == null) { _dataObject.ServiceName = serviceName; } _dataObject.SetResourceNameAndId(_resourceCatalog, serviceName, out resource); _dataObject.SetTestResourceIds(_resourceCatalog.NewContextualResourceCatalog(_authorizationService, workspaceGuid), webRequest, serviceName, resource); _dataObject.WebUrl = webRequest.WebServerUrl; _dataObject.EsbChannel = _esbChannelFactory.New(); if (_dataObject.Settings is null) { _dataObject.Settings = new Dev2WorkflowSettingsTO { ExecutionLogLevel = Config.Server.ExecutionLogLevel, EnableDetailedLogging = Config.Server.EnableDetailedLogging, LoggerType = LoggerType.JSON, KeepLogsForDays = 2, CompressOldLogFiles = true }; } var stateNotifier = CustomContainer.Get <IStateNotifierFactory>()?.New(_dataObject); _dataObject.StateNotifier = stateNotifier; }