Skip to content

Commit

Permalink
Merge pull request #193 from cognizone/fix/elastic-proxy-fixes-20230308
Browse files Browse the repository at this point in the history
elastic proxy fixes
  • Loading branch information
ssamarid authored Jul 4, 2023
2 parents 7f18d8e + 9343ae2 commit 459d782
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ public void setParamValuesValidator(Map<String, ParamValidator> paramValuesValid
this.paramValuesValidator = paramValuesValidator;
}

private String buildUrl(String path) {
return UriComponentsBuilder.fromPath(path).build(false).toUri().toString();
private String buildUrl(String path, MultiValueMap<String, String> params) {
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath(path).queryParams(params);
return uriComponentsBuilder.build(false).toUriString();
}

private Map<String, Object> mergeParams(MultiValueMap<String, String> urlParams, Map<String, Object> bodyParams) {
Expand Down Expand Up @@ -177,19 +178,17 @@ private boolean validateParams(String requestUUID, Map<String, Object> params) {
}

public ResponseEntity<Resource> process(MultiValueMap<String, String> urlParams, Map<String, Object> bodyParams) throws IOException {
String requestUUID = UUID.randomUUID().toString();
return executeRequest(UUID.randomUUID().toString(), httpMethod, urlTemplate, urlParams, bodyParams);
}

private ResponseEntity<Resource> executeRequest(String requestUUID, HttpMethod httpMethod, String url, MultiValueMap<String, String> urlParams, Map<String, Object> bodyParams) throws IOException {
Map<String, Object> params = mergeParams(urlParams, bodyParams);

if (!validateParams(requestUUID, params)) {
return ResponseEntity.badRequest().body(new InputStreamResource(IOUtils.toInputStream(requestUUID, StandardCharsets.UTF_8)));
}

return executeRequest(requestUUID, httpMethod, urlTemplate, params);
}

private ResponseEntity<Resource> executeRequest(String requestUUID, HttpMethod httpMethod, String url, Map<String, Object> params) throws IOException {
Request request = new Request(httpMethod.name(), buildUrl(spel(url, params)));
Request request = new Request(httpMethod.name(), buildUrl(spel(url, params), urlParams));

if (HttpMethod.POST.equals(httpMethod) || HttpMethod.PUT.equals(httpMethod)) {
request.setJsonEntity(thymeleaf(getTemplateContent(), params));
Expand Down

0 comments on commit 459d782

Please sign in to comment.