0

I have an http POST request which I need to send from my JAVA webservice to a job queueing service. My request in the following CURL format works:

curl 
--cacert ca-cert.txt 
-u user:password 
-H "content-type:application/json" 
-X POST  
-d '{"properties":{"delivery_mode":2},"routing_key":"test","payload":"HI","payload_encoding":"string"}' 
https://testserver.com:15671/api/exchanges/%2f/amq.default/publish

I'm trying to translate this to JAVA code. I cannot seem to find any Java library that except a ca-cert variable/file as a parameter. I found some hints that I need to make some sort of "keystore" object, however am not sure what this means.

I found a source online which suggests to something like this:

String command = "enter curl command";
Process process = Runtime.getRuntime().exec(command);

however, when I try this it does not work! Any suggestions?

Uri Shapira
  • 369
  • 1
  • 2
  • 17
  • 1
    Java's SSL verification is working a bit differently. But basically [this question](https://stackoverflow.com/questions/4325263/how-to-import-a-cer-certificate-into-a-java-keystore) should answer it. A good tool to use here is btw the [KeyStore Explorer](https://keystore-explorer.org/) - since Spring is Java EE, you should take a look at the [javax.ws.rs.client](https://docs.oracle.com/javaee/7/api/javax/ws/rs/client/package-summary.html) or use [Spring's WebClient](https://www.baeldung.com/spring-5-webclient) – maio290 Apr 29 '21 at 12:47
  • Thanks for the response. There is lots of talk here of taking keys and such... I have in my hand the one and only ca-cert file that I need. What I can't seem to grasp is what I am supposed to do with it in Java. This question doesn't really help me understand that – Uri Shapira Apr 29 '21 at 14:30
  • It's not that hard. You add the cert file to your application server's trust store and you should be done with it. – maio290 Apr 29 '21 at 14:32

0 Answers0