Skip to content

Instantly share code, notes, and snippets.

@ehdez73
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save ehdez73/9474983 to your computer and use it in GitHub Desktop.

Select an option

Save ehdez73/9474983 to your computer and use it in GitHub Desktop.
SSL with RestTemplate to external Host
import org.springframework.web.client.RestTemplate;
public class Application {
static {
System.setProperty("javax.net.ssl.trustStore", "/opt/cert/trustStore");
System.setProperty("javax.net.ssl.trustStorePassword", "s3cret");
}
public static void main(String[] args) throws Exception {
/**
* Previamente hay que importar el certificado de Google
* $ wget http://pki.google.com/GIAG2.crt
* $ keytool -keystore tomcat.keystore -alias google -import -file GIAG2.crt
*/
RestTemplate restTemplate = new RestTemplate();
String message = restTemplate.getForObject("https://www.google.es", String.class);
System.out.println(message); // output HTML
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment