com.googlecode.jsonrpc4j.spring.rest.SslClientHttpRequestFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsonrpc4j Show documentation
Show all versions of jsonrpc4j Show documentation
This project aims to provide the facility to easily implement JSON-RPC for the java programming language.
package com.googlecode.jsonrpc4j.spring.rest;
import java.io.IOException;
import java.net.HttpURLConnection;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
/**
* Implementation of {@link org.springframework.http.client.ClientHttpRequestFactory} that creates HTTPS connection
* with specified settings.
*/
public class SslClientHttpRequestFactory
extends SimpleClientHttpRequestFactory {
private SSLContext sslContext;
private HostnameVerifier hostNameVerifier;
@Override
protected void prepareConnection(HttpURLConnection connection, String httpMethod)
throws IOException {
if (connection instanceof HttpsURLConnection) {
final HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
if (hostNameVerifier != null) {
httpsConnection.setHostnameVerifier(hostNameVerifier);
}
if (sslContext != null) {
httpsConnection.setSSLSocketFactory(sslContext.getSocketFactory());
}
}
super.prepareConnection(connection, httpMethod);
}
public void setSslContext(SSLContext sslContext) {
this.sslContext = sslContext;
}
public void setHostNameVerifier(HostnameVerifier hostNameVerifier) {
this.hostNameVerifier = hostNameVerifier;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy