本文整理了Java中org.apache.commons.httpclient.protocol.Protocol.registerProtocol()
方法的一些代码示例,展示了Protocol.registerProtocol()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Protocol.registerProtocol()
方法的具体详情如下:
包路径:org.apache.commons.httpclient.protocol.Protocol
类名称:Protocol
方法名:registerProtocol
[英]Registers a new protocol with the given identifier. If a protocol with the given ID already exists it will be overridden. This ID is the same one used to retrieve the protocol from getProtocol(String).
[中]使用给定的标识符注册新协议。如果具有给定ID的协议已经存在,它将被覆盖。该ID与用于从getProtocol(字符串)检索协议的ID相同。
代码示例来源:origin: commons-httpclient/commons-httpclient
/**
* Lazily registers the protocol with the given id.
*
* @param id the protocol ID
*
* @return the lazily registered protocol
*
* @throws IllegalStateException if the protocol with id is not recognized
*/
private static Protocol lazyRegisterProtocol(String id)
throws IllegalStateException {
if ("http".equals(id)) {
final Protocol http
= new Protocol("http", DefaultProtocolSocketFactory.getSocketFactory(), 80);
Protocol.registerProtocol("http", http);
return http;
}
if ("https".equals(id)) {
final Protocol https
= new Protocol("https", SSLProtocolSocketFactory.getSocketFactory(), 443);
Protocol.registerProtocol("https", https);
return https;
}
throw new IllegalStateException("unsupported protocol: '" + id + "'");
}
代码示例来源:origin: elastic/elasticsearch-hadoop
@After
public void reset() {
Protocol.registerProtocol("https", original);
}
代码示例来源:origin: elastic/elasticsearch-hadoop
static void replaceProtocol(ProtocolSocketFactory socketFactory, String schema, int defaultPort) {
//
// switch protocol
// due to how HttpCommons work internally this dance is best to be kept as is
//
Protocol directHttp = Protocol.getProtocol(schema);
if (directHttp instanceof DelegatedProtocol) {
// unwrap the original
directHttp = ((DelegatedProtocol)directHttp).getOriginal();
assert directHttp instanceof DelegatedProtocol == false;
}
Protocol proxiedHttp = new DelegatedProtocol(socketFactory, directHttp, schema, defaultPort);
// NB: register the new protocol since when using absolute URIs, HttpClient#executeMethod will override the configuration (#387)
// NB: hence why the original/direct http protocol is saved - as otherwise the connection is not closed since it is considered different
// NB: (as the protocol identities don't match)
// this is not really needed since it's being replaced later on
// hostConfig.setHost(proxyHost, proxyPort, proxiedHttp);
Protocol.registerProtocol(schema, proxiedHttp);
// end dance
}
代码示例来源:origin: apache/cloudstack
public UcsHttpClient(String ip) {
url = String.format("http://%s/nuova", ip);
Protocol.registerProtocol("https", ucsHttpsProtocol);
}
代码示例来源:origin: foxinmy/weixin4j
public HttpComponent3Factory() {
httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
httpClient.getParams().setHttpElementCharset(Consts.UTF_8.name());
httpClient.getParams().setParameter("http.protocol.uri-charset",
Consts.UTF_8.name());
// httpMethod.getParams().setUriCharset(Consts.UTF_8.name());
httpClient.getParams().setContentCharset(Consts.UTF_8.name());
Protocol.registerProtocol("https",
new Protocol("https", new SSLProtocolSocketFactory(
HttpClientFactory.allowSSLContext()), 443));
}
代码示例来源:origin: apache/cloudstack
protected NeutronRestApi(final Class<? extends HttpMethodBase> httpClazz, final String protocol, final int port) {
client = createHttpClient();
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
this.httpClazz = httpClazz;
try {
// Cast to ProtocolSocketFactory to avoid the deprecated constructor
// with the SecureProtocolSocketFactory parameter
Protocol.registerProtocol(protocol, new Protocol(protocol, (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), HTTPS_PORT));
} catch (IOException e) {
s_logger.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e);
}
}
代码示例来源:origin: apache/cloudstack
public BigSwitchBcfApi() {
_client = createHttpClient();
_client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
try {
// Cast to ProtocolSocketFactory to avoid the deprecated constructor with the SecureProtocolSocketFactory parameter
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), _port));
} catch (IOException e) {
S_LOGGER.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e);
}
}
代码示例来源:origin: KylinOLAP/Kylin
private static void registerEasyHttps() {
// by pass all https issue
if (EASY_HTTPS == null) {
EASY_HTTPS = new Protocol("https", (ProtocolSocketFactory) new DefaultSslProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", EASY_HTTPS);
}
}
代码示例来源:origin: KylinOLAP/Kylin
private void registerSsl() {
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new DefaultSslProtocolSocketFactory(), 443));
}
代码示例来源:origin: foxinmy/weixin4j
private void resolveHttpParams(HttpParams params) {
if (params != null) {
if (params.getProxy() != null) {
InetSocketAddress socketAddress = (InetSocketAddress) params
.getProxy().address();
httpClient.getHostConfiguration().setProxy(
socketAddress.getHostName(), socketAddress.getPort());
}
if (params.getSSLContext() != null) {
Protocol.registerProtocol("https", new Protocol("https",
new SSLProtocolSocketFactory(params.getSSLContext()),
443));
}
httpClient.getHttpConnectionManager().getParams()
.setConnectionTimeout(params.getConnectTimeout());
}
}
代码示例来源:origin: org.apache.abdera/abdera-client
/**
* Register the specified secure socket factory on the specified port
*/
public static void registerFactory(SecureProtocolSocketFactory factory, int port) {
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory)factory, port));
}
代码示例来源:origin: org.n52.security/52n-security-support-net
public void register() {
ProtocolSocketFactory socketFactory = new TrustAllSocketFactory();
Protocol easyhttps = new Protocol("https",
(ProtocolSocketFactory) socketFactory,
443);
Protocol.registerProtocol("https", easyhttps);
LOG.info("Registered " + TrustAllCertsEnvironment.class + " as default https handler.");
}
}
代码示例来源:origin: ngallagher/simpleframework
public void registerProtocol(String scheme, int port) {
SocketFactory factory = new SocketFactory();
Protocol protocol = new Protocol(scheme, factory, port);
Protocol.registerProtocol(scheme, protocol);
}
代码示例来源:origin: org.n52.security/52n-security-support-net
/**
* Method registers the EasySSLProtocolSocketFactory as default https handler.
*/
public void register() {
Protocol easyhttps = new Protocol("https",
(ProtocolSocketFactory) new EasySSLProtocolSocketFactory(),
443);
Protocol.registerProtocol("https", easyhttps);
LOG.info("Registered " + EasySSLEnvironment.class + " as default https handler.");
}
}
代码示例来源:origin: org.apache.kylin/kylin-job
private static void registerEasyHttps() {
// by pass all https issue
if (EASY_HTTPS == null) {
EASY_HTTPS = new Protocol("https", (ProtocolSocketFactory) new DefaultSslProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", EASY_HTTPS);
}
}
代码示例来源:origin: org.opensaml/opensaml
/**
* Initializes the Apache Commons HttpClient library.
*/
protected static void initializeHttpClient() {
if (!Boolean.getBoolean(SYSPROP_HTTPCLIENT_HTTPS_DISABLE_HOSTNAME_VERIFICATION)) {
ProtocolSocketFactory socketFactory =
new TLSProtocolSocketFactory(null, null, new StrictHostnameVerifier());
Protocol.registerProtocol("https", new Protocol("https", socketFactory, 443));
}
}
代码示例来源:origin: org.jenkins-ci.plugins/collabnet
/**
* Permantently damage the HTTP client by having it accept bogus certificates.
*/
public static void allowSelfSignedCertificate() {
Protocol.registerProtocol("https", new Protocol("https",
(ProtocolSocketFactory)new EasySSLProtocolSocketFactory(),
443));
}
代码示例来源:origin: iipc/openwayback
protected synchronized HttpClient initialValue() {
HttpClientParams params = new HttpClientParams();
params.setParameter(HttpClientParams.RETRY_HANDLER, noRetryHandler);
IPHttpConnectionManager manager = new IPHttpConnectionManager();
Protocol dnsTimedProtocol = new Protocol("http",
new DNSTimingProtocolSocketFactory(), 80);
Protocol.registerProtocol("http", dnsTimedProtocol);
manager.getParams().setConnectionTimeout(connectionTimeoutMS);
manager.getParams().setSoTimeout(socketTimeoutMS);
return new HttpClient(params, manager);
}
};
代码示例来源:origin: wmixvideo/nfe
public WSFacade(final CTeConfig config) throws IOException, KeyManagementException, UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, CertificateException {
Protocol.registerProtocol("https", new Protocol("https", new DFSocketFactory(config), 443));
this.wsStatusConsulta = new WSStatusConsulta(config);
this.wsRecepcaoLote = new WSRecepcaoLote(config);
this.wsRecepcaoLoteRetorno = new WSRecepcaoLoteRetorno(config);
this.wsNotaConsulta = new WSNotaConsulta(config);
this.wsCancelamento = new WSCancelamento(config);
}
代码示例来源:origin: wmixvideo/nfe
public WSFacade(final MDFeConfig config) throws IOException, KeyManagementException, UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, CertificateException {
Protocol.registerProtocol("https", new Protocol("https", new DFSocketFactory(config), 443));
this.wsStatusConsulta = new WSStatusConsulta(config);
this.wsRecepcaoLote = new WSRecepcaoLote(config);
// this.wsRecepcaoLoteRetorno = new WSRecepcaoLoteRetorno(config);
this.wsNotaConsulta = new WSNotaConsulta(config);
this.wsCancelamento = new WSCancelamento(config);
this.wsEncerramento = new WSEncerramento(config);
this.wsConsultaRecibo = new WSConsultaRecibo(config);
this.wsConsultaNaoEncerrados = new WSConsultaNaoEncerrados(config);
this.wsIncluirCondutor = new WSIncluirCondutor(config);
}
内容来源于网络,如有侵权,请联系作者删除!