I want to hit remote API which authenticate using client certificates, also it takes 1 json parameter as input and based on that it returns json output.
I am able to get the response using curl command :
curl -vvv -H "Content-Type: application/json" -H --request POST --cert "$deploy_dir"/client.crt --key "$deploy_dir"/client.key --cacert "$deploy_dir"/ca.client.crt --data "@$deploy_dir/test_data.json" https://XXXX:8443/convert
In the above command I am passing 4 things : client.crt, ca.client.crt, client.key and json input.
Now I want to get response using Java sprint boot application.
I tried below program in spring boot application :
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class TestApplication {
private static final Logger log = LoggerFactory.getLogger(TestApplication.class);
public static void main(String[] args) {
SpringApplication.run(TestApplication.class);
}
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
@Bean
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
return args -> {
try {
String result = restTemplate.getForObject(
"https://XXXX:8443/convert", String.class);
log.info(result);
}
catch(Exception e)
{
e.printStackTrace();
}
};
}
}
Can anyone help me how to use or pass these certificates using java program and input json to the API.