org.apache.commons.httpclient.protocol.Protocol.getProtocol()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中org.apache.commons.httpclient.protocol.Protocol.getProtocol()方法的一些代码示例,展示了Protocol.getProtocol()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Protocol.getProtocol()方法的具体详情如下:
包路径:org.apache.commons.httpclient.protocol.Protocol
类名称:Protocol
方法名:getProtocol

Protocol.getProtocol介绍

[英]Gets the protocol with the given ID.
[中]获取具有给定ID的协议。

代码示例

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Constructor for ProxyHost.
 *   
 * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
 * @param port the port. Value <code>-1</code> can be used to set default protocol port
 */
public ProxyHost(final String hostname, int port) {
  super(hostname, port, Protocol.getProtocol("http"));
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Constructor for HttpHost.
 *   
 * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
 */
public HttpHost(final String hostname) {
  this(hostname, -1, Protocol.getProtocol("http"));
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Creates a new HTTP connection for the given host and port.
 *
 * @param host the host to connect to
 * @param port the port to connect to
 */
public HttpConnection(String host, int port) {
  this(null, -1, host, null, port, Protocol.getProtocol("http"));
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Constructor for HttpHost.
 *   
 * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
 * @param port the port. Value <code>-1</code> can be used to set default protocol port
 */
public HttpHost(final String hostname, int port) {
  this(hostname, port, Protocol.getProtocol("http"));
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Creates a new HTTP connection for the given host and port via the 
 * given proxy host and port using the default protocol.
 *
 * @param proxyHost the host to proxy via
 * @param proxyPort the port to proxy via
 * @param host the host to connect to
 * @param port the port to connect to
 */
public HttpConnection(
  String proxyHost,
  int proxyPort,
  String host,
  int port) {
  this(proxyHost, proxyPort, host, null, port, Protocol.getProtocol("http"));
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Sets the given host, port and protocol
 * 
 * @param host the host(IP or DNS name)
 * @param port The port
 * @param protocol The protocol.
 */
public synchronized void setHost(final String host, int port, final String protocol) {
  this.host = new HttpHost(host, port, Protocol.getProtocol(protocol));
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Sets the given host and port.  Uses the default protocol "http".
 * 
 * @param host the host(IP or DNS name)
 * @param port The port
 */
public synchronized void setHost(final String host, int port) {
  setHost(host, port, Protocol.getProtocol("http"));
}

代码示例来源:origin: elastic/elasticsearch-hadoop

protected Protocol keepProtocol(String host, int port, String scheme) {
    final Protocol oldProtocol = getProtocol();
    if (oldProtocol != null) {
      final String oldScheme = oldProtocol.getScheme();
      if (oldScheme == scheme || (oldScheme != null && oldScheme.equalsIgnoreCase(scheme))) {
        return oldProtocol;
      }
    }
    return Protocol.getProtocol(scheme);
  }
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Set the given host. Uses the default protocol("http") and its port.
 * 
 * @param host The host(IP or DNS name).
 */
public synchronized void setHost(final String host) {
  Protocol defaultProtocol = Protocol.getProtocol("http"); 
  setHost(host, defaultProtocol.getDefaultPort(), defaultProtocol);
}

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * URI constructor for HttpHost.
 *   
 * @param uri the URI.
 */
public  HttpHost(final URI uri) throws URIException {
  this(uri.getHost(), uri.getPort(), Protocol.getProtocol(uri.getScheme()));
}

代码示例来源:origin: elastic/elasticsearch-hadoop

@Before
public void setup() {
  original = Protocol.getProtocol("https");
}

代码示例来源: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: commons-httpclient/commons-httpclient

Protocol defaultprotocol = Protocol.getProtocol("http");
  socketFactory = defaultprotocol.getSocketFactory();
} else {

代码示例来源:origin: elastic/elasticsearch-hadoop

@Test
public void testProtocolReplacement() throws Exception {
  final ProtocolSocketFactory socketFactory = getSocketFactory();
  CommonsHttpTransport.replaceProtocol(socketFactory, "https", 443);
  Protocol protocol = Protocol.getProtocol("https");
  assertThat(protocol, instanceOf(DelegatedProtocol.class));
  DelegatedProtocol delegatedProtocol = (DelegatedProtocol) protocol;
  assertThat(delegatedProtocol.getSocketFactory(), sameInstance(socketFactory));
  assertThat(delegatedProtocol.getOriginal(), sameInstance(original));
  // ensure we do not re-wrap a delegated protocol
  CommonsHttpTransport.replaceProtocol(socketFactory, "https", 443);
  protocol = Protocol.getProtocol("https");
  assertThat(protocol, instanceOf(DelegatedProtocol.class));
  delegatedProtocol = (DelegatedProtocol) protocol;
  assertThat(delegatedProtocol.getSocketFactory(), sameInstance(socketFactory));
  assertThat(delegatedProtocol.getOriginal(), sameInstance(original));
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * Constructor for ProxyHost.
 *   
 * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
 * @param port the port. Value <code>-1</code> can be used to set default protocol port
 */
public ProxyHost(final String hostname, int port) {
  super(hostname, port, Protocol.getProtocol("http"));
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * Constructor for HttpHost.
 *   
 * @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
 */
public HttpHost(final String hostname) {
  this(hostname, -1, Protocol.getProtocol("http"));
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * Creates a new HTTP connection for the given host and port.
 *
 * @param host the host to connect to
 * @param port the port to connect to
 */
public HttpConnection(String host, int port) {
  this(null, -1, host, null, port, Protocol.getProtocol("http"));
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * Sets the given host and port.  Uses the default protocol "http".
 * 
 * @param host the host(IP or DNS name)
 * @param port The port
 */
public synchronized void setHost(final String host, int port) {
  setHost(host, port, Protocol.getProtocol("http"));
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * Sets the given host, port and protocol
 * 
 * @param host the host(IP or DNS name)
 * @param port The port
 * @param protocol The protocol.
 */
public synchronized void setHost(final String host, int port, final String protocol) {
  this.host = new HttpHost(host, port, Protocol.getProtocol(protocol));
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * URI constructor for HttpHost.
 *   
 * @param uri the URI.
 */
public  HttpHost(final URI uri) throws URIException {
  this(uri.getHost(), uri.getPort(), Protocol.getProtocol(uri.getScheme()));
}

相关文章