com.fivefaces.cloud.workflow.function.CallProcess Maven / Gradle / Ivy
package com.fivefaces.cloud.workflow.function;
import org.json.JSONObject;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponentsBuilder;
public class CallProcess extends Function{
public static final String FUNCTION_NAME = "CALL_PROCESS";
public CallProcess(RestTemplateBuilder restTemplateBuilder) {
super(restTemplateBuilder);
}
@Override
public void setup(JSONObject jsonParameters) {
}
@Override
public JSONObject process(JSONObject jsonParameters) {
JSONObject inputJson = (JSONObject) jsonParameters.get("process");
String url = inputJson.getString("url");
JSONObject jsonPayload = inputJson.getJSONObject("jsonPayload");
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
MultiValueMap requestMap = new LinkedMultiValueMap<>();
requestMap.add("jsonPayload", jsonPayload.toString());
HttpEntity> request = new HttpEntity<>(requestMap, headers);
ResponseEntity response = restTemplateBuilder.build().postForEntity( builder.build().encode().toUri(), request , String.class );
return new JSONObject(response.getBody());
}
@Override
public void cleanup(JSONObject jsonParameters) {
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy