本文整理汇总了Java中org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory类的典型用法代码示例。如果您正苦于以下问题:Java EasySSLProtocolSocketFactory类的具体用法?Java EasySSLProtocolSocketFactory怎么用?Java EasySSLProtocolSocketFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EasySSLProtocolSocketFactory类属于org.apache.commons.httpclient.contrib.ssl包,在下文中一共展示了EasySSLProtocolSocketFactory类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleCertificateExceptionAndRetry
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; //导入依赖的package包/类
@Nullable
private static HttpMethod handleCertificateExceptionAndRetry(@NotNull IOException e, @NotNull String host,
@NotNull HttpClient client, @NotNull URI uri,
@NotNull ThrowableConvertor<String, HttpMethod, IOException> methodCreator)
throws IOException {
if (!isCertificateException(e)) {
throw e;
}
if (isTrusted(host)) {
// creating a special configuration that allows connections to non-trusted HTTPS hosts
// see the javadoc to EasySSLProtocolSocketFactory for details
Protocol easyHttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
HostConfiguration hc = new HostConfiguration();
hc.setHost(host, 443, easyHttps);
String relativeUri = new URI(uri.getPathQuery(), false).getURI();
// it is important to use relative URI here, otherwise our custom protocol won't work.
// we have to recreate the method, because HttpMethod#setUri won't overwrite the host,
// and changing host by hands (HttpMethodBase#setHostConfiguration) is deprecated.
HttpMethod method = methodCreator.convert(relativeUri);
client.executeMethod(hc, method);
return method;
}
throw e;
}
示例2: sendRequest
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; //导入依赖的package包/类
private String sendRequest(String service, String xmlRequest) throws ExecutionException {
HttpClient client = new HttpClient();
String response = null;
PostMethod method = new PostMethod("/xmlIM/" + service);
method.setRequestBody(xmlRequest);
try {
org.apache.commons.httpclient.protocol.Protocol myhttps = new org.apache.commons.httpclient.protocol.Protocol("https", new EasySSLProtocolSocketFactory(), 443);
client.getHostConfiguration().setHost(_ip, 443, myhttps);
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
throw new Exception("Error code : " + statusCode);
}
response = method.getResponseBodyAsString();
} catch (Exception e) {
System.out.println(e.getMessage());
throw new ExecutionException(e.getMessage());
}
System.out.println(response);
return response;
}
示例3: loadLifecycles
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; //导入依赖的package包/类
@Override
public List<Lifecycle> loadLifecycles() throws Exception {
List<Lifecycle> lifecycles = new LinkedList<Lifecycle>();
// this validation of our service list needs to happen after we've
// loaded our configs so it's a lifecycle
lifecycles.add(new BaseLifecycle() {
@Override
public void start() throws Exception {
// first check if we want to allow self-signed certificates for SSL communication
if (Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.KSB_ALLOW_SELF_SIGNED_SSL)).booleanValue()) {
Protocol.registerProtocol("https", new Protocol("https",
(ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443));
}
super.start();
}
});
return lifecycles;
}
示例4: easySSL
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; //导入依赖的package包/类
protected void easySSL()
{
ProtocolSocketFactory easySSLProtocolSocketFactory = new EasySSLProtocolSocketFactory();
Protocol.unregisterProtocol("https");
Protocol.registerProtocol("https", new Protocol("https",
easySSLProtocolSocketFactory,
getUrl().getPort() == -1 ? 443 : getUrl().getPort()));
}
示例5: createAndInitHttpClient
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; //导入依赖的package包/类
private HttpClient createAndInitHttpClient(String characterEncoding,
boolean selfSignedSSL) {
if (selfSignedSSL) {
Protocol.registerProtocol("https", new Protocol("https",
new EasySSLProtocolSocketFactory(), 443));
}
HttpClient httpClient = new HttpClient();
WebUtil.configureHttpClient(httpClient, "Mylyn");
httpClient.getParams().setContentCharset(characterEncoding);
return httpClient;
}
示例6: initSSLCertPolicy
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory; //导入依赖的package包/类
private void initSSLCertPolicy() {
EasySSLProtocolSocketFactory secureProtocolSocketFactory = new EasySSLProtocolSocketFactory();
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory)secureProtocolSocketFactory, 443));
}