Skip to content

Commit

Permalink
Remove activity specific information from HttpRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphr committed Aug 3, 2023
1 parent 773b964 commit da277f6
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected FlowableHttpClient createHttpClient() {

@Override
public CompletableFuture<ExecutionData> execute(DelegatePlanItemInstance planItemInstance, AsyncTaskInvoker taskInvoker) {
HttpRequest request;
RequestData request;

HttpServiceTask httpServiceTask = (HttpServiceTask) planItemInstance.getPlanItemDefinition();
try {
Expand All @@ -83,11 +83,11 @@ public CompletableFuture<ExecutionData> execute(DelegatePlanItemInstance planIte
HttpRequestHandler httpRequestHandler = createHttpRequestHandler(httpServiceTask.getHttpRequestHandler(), cmmnEngineConfiguration);

if (httpRequestHandler != null) {
httpRequestHandler.handleHttpRequest(planItemInstance, request, null);
httpRequestHandler.handleHttpRequest(planItemInstance, request.getHttpRequest(), null);
}

// Validate request
validateRequest(request);
validateRequest(request.getHttpRequest());

boolean parallelInSameTransaction;
if (httpServiceTask.getParallelInSameTransaction() != null) {
Expand All @@ -102,7 +102,7 @@ public CompletableFuture<ExecutionData> execute(DelegatePlanItemInstance planIte
@Override
public void afterExecution(DelegatePlanItemInstance planItemInstance, ExecutionData result) {

HttpRequest request = result.getRequest();
RequestData request = result.getRequest();
HttpResponse response = result.getResponse();

Throwable resultException = result.getException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected FlowableHttpClient createHttpClient() {

@Override
public CompletableFuture<ExecutionData> execute(DelegateExecution execution, AsyncTaskInvoker taskInvoker) {
HttpRequest request;
RequestData request;

HttpServiceTask httpServiceTask = (HttpServiceTask) execution.getCurrentFlowElement();
try {
Expand All @@ -95,11 +95,11 @@ public CompletableFuture<ExecutionData> execute(DelegateExecution execution, Asy
HttpRequestHandler httpRequestHandler = createHttpRequestHandler(httpServiceTask.getHttpRequestHandler(), processEngineConfiguration);

if (httpRequestHandler != null) {
httpRequestHandler.handleHttpRequest(execution, request, null);
httpRequestHandler.handleHttpRequest(execution, request.getHttpRequest(), null);
}

// Validate request
validateRequest(request);
validateRequest(request.getHttpRequest());

boolean parallelInSameTransaction;
if (httpServiceTask.getParallelInSameTransaction() != null) {
Expand All @@ -114,7 +114,7 @@ public CompletableFuture<ExecutionData> execute(DelegateExecution execution, Asy
@Override
public void afterExecution(DelegateExecution execution, ExecutionData result) {

HttpRequest request = result.getRequest();
RequestData request = result.getRequest();
HttpResponse response = result.getResponse();

Throwable resultException = result.getException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;

import org.flowable.common.engine.api.FlowableIllegalStateException;

Expand All @@ -31,14 +30,6 @@ public class HttpRequest {
protected Collection<MultiValuePart> multiValueParts;
protected int timeout;
protected boolean noRedirects;
protected Set<String> failCodes;
protected Set<String> handleCodes;
protected boolean ignoreErrors;
protected boolean saveRequest;
protected boolean saveResponse;
protected boolean saveResponseTransient;
protected boolean saveResponseAsJson;
protected String prefix;

public String getMethod() {
return method;
Expand Down Expand Up @@ -118,67 +109,4 @@ public void setNoRedirects(boolean noRedirects) {
this.noRedirects = noRedirects;
}

public Set<String> getFailCodes() {
return failCodes;
}

public void setFailCodes(Set<String> failCodes) {
this.failCodes = failCodes;
}

public Set<String> getHandleCodes() {
return handleCodes;
}

public void setHandleCodes(Set<String> handleCodes) {
this.handleCodes = handleCodes;
}

public boolean isIgnoreErrors() {
return ignoreErrors;
}

public void setIgnoreErrors(boolean ignoreErrors) {
this.ignoreErrors = ignoreErrors;
}

public boolean isSaveRequest() {
return saveRequest;
}

public void setSaveRequest(boolean saveRequest) {
this.saveRequest = saveRequest;
}

public boolean isSaveResponse() {
return saveResponse;
}

public void setSaveResponse(boolean saveResponse) {
this.saveResponse = saveResponse;
}

public boolean isSaveResponseTransient() {
return saveResponseTransient;
}

public void setSaveResponseTransient(boolean saveResponseTransient) {
this.saveResponseTransient = saveResponseTransient;
}

public boolean isSaveResponseAsJson() {
return saveResponseAsJson;
}

public void setSaveResponseAsJson(boolean saveResponseAsJson) {
this.saveResponseAsJson = saveResponseAsJson;
}

public String getPrefix() {
return prefix;
}

public void setPrefix(String prefix) {
this.prefix = prefix;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ public BaseHttpActivityDelegate(FlowableHttpClient httpClient) {

protected abstract FlowableHttpClient createHttpClient();

protected HttpRequest createRequest(VariableContainer variableContainer, String prefix) {
protected RequestData createRequest(VariableContainer variableContainer, String fallbackPrefix) {
HttpRequest request = new HttpRequest();
RequestData requestData = new RequestData();
requestData.setHttpRequest(request);

request.setMethod(ExpressionUtils.getStringFromField(requestMethod, variableContainer));
request.setUrl(ExpressionUtils.getStringFromField(requestUrl, variableContainer));
Expand All @@ -99,46 +101,47 @@ protected HttpRequest createRequest(VariableContainer variableContainer, String
request.setBodyEncoding(ExpressionUtils.getStringFromField(requestBodyEncoding, variableContainer));
request.setTimeout(ExpressionUtils.getIntFromField(requestTimeout, variableContainer));
request.setNoRedirects(ExpressionUtils.getBooleanFromField(disallowRedirects, variableContainer));
request.setIgnoreErrors(ExpressionUtils.getBooleanFromField(ignoreException, variableContainer));
request.setSaveRequest(ExpressionUtils.getBooleanFromField(saveRequestVariables, variableContainer));
request.setSaveResponse(ExpressionUtils.getBooleanFromField(saveResponseParameters, variableContainer));
request.setSaveResponseTransient(ExpressionUtils.getBooleanFromField(saveResponseParametersTransient, variableContainer));
request.setSaveResponseAsJson(ExpressionUtils.getBooleanFromField(saveResponseVariableAsJson, variableContainer));
request.setPrefix(ExpressionUtils.getStringFromField(resultVariablePrefix, variableContainer));
requestData.setIgnoreErrors(ExpressionUtils.getBooleanFromField(ignoreException, variableContainer));
requestData.setSaveRequest(ExpressionUtils.getBooleanFromField(saveRequestVariables, variableContainer));
requestData.setSaveResponse(ExpressionUtils.getBooleanFromField(saveResponseParameters, variableContainer));
requestData.setSaveResponseTransient(ExpressionUtils.getBooleanFromField(saveResponseParametersTransient, variableContainer));
requestData.setSaveResponseAsJson(ExpressionUtils.getBooleanFromField(saveResponseVariableAsJson, variableContainer));
requestData.setPrefix(ExpressionUtils.getStringFromField(resultVariablePrefix, variableContainer));

String failCodes = ExpressionUtils.getStringFromField(failStatusCodes, variableContainer);
String handleCodes = ExpressionUtils.getStringFromField(handleStatusCodes, variableContainer);

if (failCodes != null) {
request.setFailCodes(ExpressionUtils.getStringSetFromField(failCodes));
requestData.setFailCodes(ExpressionUtils.getStringSetFromField(failCodes));
}
if (handleCodes != null) {
request.setHandleCodes(ExpressionUtils.getStringSetFromField(handleCodes));
requestData.setHandleCodes(ExpressionUtils.getStringSetFromField(handleCodes));
}

if (request.getPrefix() == null) {
request.setPrefix(prefix);
if (requestData.getPrefix() == null) {
requestData.setPrefix(fallbackPrefix);
}

// Save request fields
if (request.isSaveRequest()) {
variableContainer.setVariable(request.getPrefix() + "RequestMethod", request.getMethod());
variableContainer.setVariable(request.getPrefix() + "RequestUrl", request.getUrl());
variableContainer.setVariable(request.getPrefix() + "RequestHeaders", request.getHttpHeadersAsString());
variableContainer.setVariable(request.getPrefix() + "RequestBody", request.getBody());
variableContainer.setVariable(request.getPrefix() + "RequestBodyEncoding", request.getBodyEncoding());
variableContainer.setVariable(request.getPrefix() + "RequestTimeout", request.getTimeout());
variableContainer.setVariable(request.getPrefix() + "DisallowRedirects", request.isNoRedirects());
variableContainer.setVariable(request.getPrefix() + "FailStatusCodes", failCodes);
variableContainer.setVariable(request.getPrefix() + "HandleStatusCodes", handleCodes);
variableContainer.setVariable(request.getPrefix() + "IgnoreException", request.isIgnoreErrors());
variableContainer.setVariable(request.getPrefix() + "SaveRequestVariables", request.isSaveRequest());
variableContainer.setVariable(request.getPrefix() + "SaveResponseParameters", request.isSaveResponse());
}
return request;
if (requestData.isSaveRequest()) {
String prefix = requestData.getPrefix();
variableContainer.setVariable(prefix + "RequestMethod", request.getMethod());
variableContainer.setVariable(prefix + "RequestUrl", request.getUrl());
variableContainer.setVariable(prefix + "RequestHeaders", request.getHttpHeadersAsString());
variableContainer.setVariable(prefix + "RequestBody", request.getBody());
variableContainer.setVariable(prefix + "RequestBodyEncoding", request.getBodyEncoding());
variableContainer.setVariable(prefix + "RequestTimeout", request.getTimeout());
variableContainer.setVariable(prefix + "DisallowRedirects", request.isNoRedirects());
variableContainer.setVariable(prefix + "FailStatusCodes", failCodes);
variableContainer.setVariable(prefix + "HandleStatusCodes", handleCodes);
variableContainer.setVariable(prefix + "IgnoreException", requestData.isIgnoreErrors());
variableContainer.setVariable(prefix + "SaveRequestVariables", requestData.isSaveRequest());
variableContainer.setVariable(prefix + "SaveResponseParameters", requestData.isSaveResponse());
}
return requestData;
}

protected void saveResponseFields(VariableContainer variableContainer, HttpRequest request, HttpResponse response, ObjectMapper objectMapper)
protected void saveResponseFields(VariableContainer variableContainer, RequestData request, HttpResponse response, ObjectMapper objectMapper)
throws IOException {
// Save response fields
if (response != null) {
Expand Down Expand Up @@ -202,8 +205,8 @@ protected void saveResponseFields(VariableContainer variableContainer, HttpReque
}
}

protected CompletableFuture<ExecutionData> prepareAndExecuteRequest(HttpRequest request, boolean parallelInSameTransaction, AsyncTaskInvoker taskInvoker) {
ExecutableHttpRequest httpRequest = httpClient.prepareRequest(request);
protected CompletableFuture<ExecutionData> prepareAndExecuteRequest(RequestData request, boolean parallelInSameTransaction, AsyncTaskInvoker taskInvoker) {
ExecutableHttpRequest httpRequest = httpClient.prepareRequest(request.getHttpRequest());

if (!parallelInSameTransaction) {
CompletableFuture<ExecutionData> future = new CompletableFuture<>();
Expand Down Expand Up @@ -264,21 +267,21 @@ protected HttpHeaders getRequestHeaders(VariableContainer variableContainer) {

public static class ExecutionData {

protected HttpRequest request;
protected RequestData request;
protected HttpResponse response;
protected Throwable exception;

public ExecutionData(HttpRequest request, HttpResponse response) {
public ExecutionData(RequestData request, HttpResponse response) {
this(request, response, null);
}

public ExecutionData(HttpRequest request, HttpResponse response, Throwable exception) {
public ExecutionData(RequestData request, HttpResponse response, Throwable exception) {
this.request = request;
this.response = response;
this.exception = exception;
}

public HttpRequest getRequest() {
public RequestData getRequest() {
return request;
}

Expand All @@ -290,4 +293,93 @@ public Throwable getException() {
return exception;
}
}

public static class RequestData {

protected HttpRequest httpRequest;
protected Set<String> failCodes;
protected Set<String> handleCodes;
protected boolean ignoreErrors;
protected boolean saveRequest;
protected boolean saveResponse;
protected boolean saveResponseTransient;
protected boolean saveResponseAsJson;
protected String prefix;

public HttpRequest getHttpRequest() {
return httpRequest;
}

public void setHttpRequest(HttpRequest httpRequest) {
this.httpRequest = httpRequest;
}

public Set<String> getFailCodes() {
return failCodes;
}

public void setFailCodes(Set<String> failCodes) {
this.failCodes = failCodes;
}

public Set<String> getHandleCodes() {
return handleCodes;
}

public void setHandleCodes(Set<String> handleCodes) {
this.handleCodes = handleCodes;
}

public boolean isIgnoreErrors() {
return ignoreErrors;
}

public void setIgnoreErrors(boolean ignoreErrors) {
this.ignoreErrors = ignoreErrors;
}

public boolean isSaveRequest() {
return saveRequest;
}

public void setSaveRequest(boolean saveRequest) {
this.saveRequest = saveRequest;
}

public boolean isSaveResponse() {
return saveResponse;
}

public void setSaveResponse(boolean saveResponse) {
this.saveResponse = saveResponse;
}

public boolean isSaveResponseTransient() {
return saveResponseTransient;
}

public void setSaveResponseTransient(boolean saveResponseTransient) {
this.saveResponseTransient = saveResponseTransient;
}

public boolean isSaveResponseAsJson() {
return saveResponseAsJson;
}

public void setSaveResponseAsJson(boolean saveResponseAsJson) {
this.saveResponseAsJson = saveResponseAsJson;
}

public String getPrefix() {
return prefix;
}

public void setPrefix(String prefix) {
this.prefix = prefix;
}

public boolean isNoRedirects() {
return httpRequest.isNoRedirects();
}
}
}
Loading

0 comments on commit da277f6

Please sign in to comment.