0

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.

ankit
  • 380
  • 4
  • 16
  • Possible duplicate of [How to import a .cer certificate into a java keystore?](https://stackoverflow.com/questions/4325263/how-to-import-a-cer-certificate-into-a-java-keystore) – Alan Hay Aug 02 '19 at 07:54
  • I had already checked that link. In that it has mentioned only 1 cer file is importing and I have 3. Also I need to pass json as input which is not mentioned there. – ankit Aug 02 '19 at 08:24

0 Answers0