Compare commits
8 Commits
6f5409f528
...
b78b3e43f4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b78b3e43f4 | ||
|
|
07afcf3aa2 | ||
|
|
e0736ff6df | ||
|
|
0d801466cf | ||
|
|
ff53be5d13 | ||
|
|
cc787f445a | ||
|
|
97c57d4fb1 | ||
|
|
ff3908cdd2 |
@ -9,12 +9,18 @@ public class BodyQueryBehavior<TRecAction>(IRecDbContext dbContext) : IPipelineB
|
||||
where TRecAction : RecActionDto
|
||||
{
|
||||
public async Task<Unit> Handle(TRecAction action, RequestHandlerDelegate<Unit> next, CancellationToken cancel)
|
||||
{
|
||||
{
|
||||
if (action.BodyQuery is null)
|
||||
return await next(cancel);
|
||||
|
||||
|
||||
var result = await dbContext.BodyQueryResults.FromSqlRaw(action.BodyQuery).FirstOrDefaultAsync(cancel);
|
||||
action.Body = result?.RawBody;
|
||||
|
||||
if (result?.RawBody is null)
|
||||
throw new InvalidOperationException(
|
||||
$"Body query did not return a result or returned a null REQUEST_BODY. " +
|
||||
$"ProfileId: {action.ProfileId}, ActionId: {action.ActionId}.");
|
||||
|
||||
action.Body = result.RawBody;
|
||||
|
||||
return await next(cancel);
|
||||
}
|
||||
|
||||
@ -18,13 +18,24 @@ public class HeaderQueryBehavior<TRecAction>(IRecDbContext dbContext, ILogger<He
|
||||
var result = await dbContext.HeaderQueryResults.FromSqlRaw(action.HeaderQuery).FirstOrDefaultAsync(cancel);
|
||||
|
||||
if(result?.RawHeader is null)
|
||||
{
|
||||
logger?.LogWarning("Header query did not return a result or returned a null REQUEST_HEADER. Profile ID: {ProfileId}, Action ID: {ActionId}", action.ProfileId, action.ActionId);
|
||||
|
||||
action.IsReturnedNoData.HeaderQuery = true;
|
||||
|
||||
return await next(cancel);
|
||||
}
|
||||
|
||||
var headerDict = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(result.RawHeader);
|
||||
|
||||
if(headerDict is null)
|
||||
{
|
||||
logger?.LogWarning("Failed to deserialize header query result: {RawHeader}. Profile ID: {ProfileId}, Action ID: {ActionId}", result.RawHeader, action.ProfileId, action.ActionId);
|
||||
logger?.LogWarning(
|
||||
"Header JSON deserialization returned null. RawHeader: {RawHeader}, ProfileId: {ProfileId}, ActionId: {ActionId}",
|
||||
result.RawHeader, action.ProfileId, action.ActionId);
|
||||
|
||||
action.IsReturnedNoData.HeaderQuery = true;
|
||||
|
||||
return await next(cancel);
|
||||
}
|
||||
|
||||
|
||||
@ -60,6 +60,8 @@ public record RecActionDto
|
||||
|
||||
public string? Body { get; set; }
|
||||
|
||||
public (bool BodyQuery, bool HeaderQuery) IsReturnedNoData = (false, false);
|
||||
|
||||
public string? PostprocessingQuery { get; init; }
|
||||
|
||||
public UriBuilder ToEndpointUriBuilder()
|
||||
|
||||
@ -40,6 +40,27 @@ public class InvokeRecActionCommandHandler(
|
||||
.ToHttpMethod()
|
||||
.ToHttpRequestMessage(request.EndpointUri);
|
||||
|
||||
if(request.Body is not null)
|
||||
{
|
||||
using var reqBody = new StringContent(request.Body);
|
||||
httpReq.Content = reqBody;
|
||||
}
|
||||
else if(request.BodyQuery is not null && !request.IsReturnedNoData.BodyQuery)
|
||||
{
|
||||
logger?.LogWarning(
|
||||
"Although BodyQuery returns null, the IsReturnedNoData variable has not been set to TRUE. " +
|
||||
"This indicates that BodyQueryBehavior has not been executed or that the relevant control step has been skipped. " +
|
||||
"The relevant behavior must be verified to ensure that the process does not produce unexpected conditions. " +
|
||||
"ProfileId: {ProfileId}, ActionId: {ActionId}",
|
||||
request.ProfileId,
|
||||
request.ActionId
|
||||
);
|
||||
}
|
||||
|
||||
if (request.Headers is not null)
|
||||
foreach (var header in request.Headers)
|
||||
httpReq.Headers.Add(header.Key, header.Value);
|
||||
|
||||
using var response = await http.SendAsync(httpReq, cancel);
|
||||
var body = await response.Content.ReadAsStringAsync(cancel);
|
||||
var headers = response.Headers.ToDictionary();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user