All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.jsonrpc4j.spring.rest.SslClientHttpRequestFactory Maven / Gradle / Ivy

Go to download

This project aims to provide the facility to easily implement JSON-RPC for the java programming language.

There is a newer version: 1.6
Show newest version
package com.googlecode.jsonrpc4j.spring.rest;

import org.springframework.http.client.SimpleClientHttpRequestFactory;

import java.io.IOException;
import java.net.HttpURLConnection;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;

/**
 * Implementation of {@link org.springframework.http.client.ClientHttpRequestFactory} that creates HTTPS connection
 * with specified settings.
 */
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