com.monarchapis.client.rest.RestConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-client Show documentation
Show all versions of rest-client Show documentation
A Fluent API wrapper around Apache HTTP Client that handles both synchronous and asynchronous REST calls.
The newest version!
/*
* Copyright (C) 2015 CapTech Ventures, Inc.
* (http://www.captechconsulting.com) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.monarchapis.client.rest;
public class RestConfig {
/** Default proxy to use, if any. */
private static String defaultProxyHost = null;
/** Default proxy port to use, if any. */
private static int defaultProxyPort = -1;
/** Default setting for accepting ssl certificates. */
private static boolean defaultTrustAllCerts = false;
/** Url to use for RESTFul request. */
private final String url;
/** Whether to trust all ssl certs, such as self-signed certs. */
private final boolean trustAllCerts;
/** Proxy host to use or null if none. */
private final String proxyHost;
/** Proxy port to use or -1 if none. */
private final int proxyPort;
/**
* Creates a RESTConfig object with the specified url.
*
*
* Default settings will be used for proxy and ssl certificate settings.
*
*
* @param url
* url
* @see #setDefaultProxy(String, int)
* @see #setDefaultTrustAllCerts(boolean)
*/
public RestConfig(final String url) {
this(url, defaultProxyHost, defaultProxyPort, defaultTrustAllCerts);
}
/**
* Creates a RESTConfig object with the specified url and ssl certificate
* settings.
*
*
* Default settings will be used for proxy settings.
*
*
* @param url
* url
* @param trustAllCerts
* whether to allow all ssl certificates
* @see #setDefaultProxy(String, int)
*/
public RestConfig(final String url, final boolean trustAllCerts) {
this(url, defaultProxyHost, defaultProxyPort, trustAllCerts);
}
/**
* Creates a RESTConfig object with the specified url and proxy settings.
*
*
* Default values will be used for ssl certificate settings.
*
*
* @param url
* url
* @param proxyHost
* proxy host
* @param proxyPort
* proxy port
* @see #setDefaultTrustAllCerts(boolean)
*/
public RestConfig(String url, String proxyHost, int proxyPort) {
this(url, proxyHost, proxyPort, defaultTrustAllCerts);
}
/**
* Creates a RESTConfig object with the specified url, proxy settings, and
* ssl certificate settings.
*
* @param url
* url
* @param proxyHost
* proxy host
* @param proxyPort
* proxy port
* @param trustAllCerts
* whether to allow all ssl certificates
*/
public RestConfig(String url, String proxyHost, int proxyPort, boolean trustAllCerts) {
this.url = url;
this.proxyHost = proxyHost;
this.proxyPort = proxyPort;
this.trustAllCerts = trustAllCerts;
}
/**
* Gets the url setting.
*
* @return url setting
*/
public String getURL() {
return this.url;
}
/**
* Gets whether to allow all certificates, such as self-signed certs.
*
* @return whether to trust all certs
*/
public boolean trustAllCerts() {
return this.trustAllCerts;
}
/**
* Gets proxy host to use or null if none.
*
* @return proxy host to use
*/
public String getProxyHost() {
return this.proxyHost;
}
/**
* Gets proxy port to use or -1 if none.
*
* @return proxy port to use
*/
public int getProxyPort() {
return this.proxyPort;
}
/**
* Sets the default proxy to use if none is specified during object
* creation.
*
* @param host
* proxy host
* @param port
* proxy port
*/
public static synchronized void setDefaultProxy(String host, int port) {
RestConfig.defaultProxyHost = host;
RestConfig.defaultProxyPort = port;
}
/**
* Sets the default ssl certificate setting to use if none is specified
* during object creation.
*
* @param trust
* whether to allow all ssl certificates
*/
public static synchronized void setDefaultTrustAllCerts(boolean trust) {
RestConfig.defaultTrustAllCerts = trust;
}
}