类org.apache.http.util.VersionInfo源码实例Demo

下面列出了怎么用org.apache.http.util.VersionInfo的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: apigee-android-sdk   文件: CachingHttpClient.java
private String generateViaHeader(HttpMessage msg) {
	final VersionInfo vi = VersionInfo.loadVersionInfo(
			"org.apache.http.client", getClass().getClassLoader());
	final String release = (vi != null) ? vi.getRelease()
			: VersionInfo.UNAVAILABLE;
	final ProtocolVersion pv = msg.getProtocolVersion();
	if ("http".equalsIgnoreCase(pv.getProtocol())) {
		return String.format(
				"%d.%d localhost (Apache-HttpClient/%s (cache))",
				pv.getMajor(), pv.getMinor(), release);
	} else {
		return String.format(
				"%s/%d.%d localhost (Apache-HttpClient/%s (cache))",
				pv.getProtocol(), pv.getMajor(), pv.getMinor(), release);
	}
}
 
源代码2 项目: algoliasearch-client-java   文件: APIClient.java
/**
 * Get the appropriate fallback domain depending on the current SNI support.
 * Checks Java version and Apache HTTP Client's version.
 *
 * @return algolianet.com if the current setup supports SNI, else algolia.net.
 */
static String getFallbackDomain() {
  int javaVersion = getJavaVersion();
  boolean javaHasSNI = javaVersion >= 7;

  final VersionInfo vi = VersionInfo.loadVersionInfo
    ("org.apache.http.client", APIClient.class.getClassLoader());
  String version = vi.getRelease();
  String[] split = version.split("\\.");
  int major = Integer.parseInt(split[0]);
  int minor = Integer.parseInt(split[1]);
  int patch = Integer.parseInt(split[2]);
  boolean apacheClientHasSNI = major > 4 ||
    major == 4 && minor > 3 ||
    major == 4 && minor == 3 && patch >= 2; // if version >= 4.3.2

  if (apacheClientHasSNI && javaHasSNI) {
    return "algolianet.com";
  } else {
    return "algolia.net";
  }
}
 
源代码3 项目: curl   文件: CurlFakeTest.java
@Test
public void curlWithDefaultUserAgent () {
    this.curl ("https://put.anything.in.this.url:1337",
            context ->
                    assertEquals (Curl.class.getPackage ().getName () + "/" + Curl.getVersion () +
                                    VersionInfo.getUserAgent (", Apache-HttpClient",
                                            "org.apache.http.client", CurlFakeTest.class),
                            ((HttpRequestWrapper)
                                    context.getAttribute ("http.request"))
                                    .getLastHeader ("User-Agent").getValue ()));
}
 
源代码4 项目: azure-devops-intellij   文件: RestClientHelper.java
public static ClientConfig getClientConfig(final ServerContext.Type type,
                                           final Credentials credentials,
                                           final String serverUri,
                                           final boolean includeProxySettings) {

    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, credentials);

    final ConnectorProvider connectorProvider = new ApacheConnectorProvider();
    // custom json provider ignores new fields that aren't recognized
    final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    final ClientConfig clientConfig = new ClientConfig(jacksonJsonProvider).connectorProvider(connectorProvider);
    clientConfig.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
    clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);

    // For TFS OnPrem we only support NTLM authentication right now. Since 2016 servers support Basic as well,
    // we need to let the server and client negotiate the protocol instead of preemptively assuming Basic.
    // TODO: This prevents PATs from being used OnPrem. We need to fix this soon to support PATs onPrem.
    clientConfig.property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, type != ServerContext.Type.TFS);

    //Define a local HTTP proxy
    if (includeProxySettings) {
        final HttpProxyService proxyService = PluginServiceProvider.getInstance().getHttpProxyService();
        final String proxyUrl = proxyService.getProxyURL();
        clientConfig.property(ClientProperties.PROXY_URI, proxyUrl);
        if (proxyService.isAuthenticationRequired()) {
            // To work with authenticated proxies and TFS, we provide the proxy credentials if they are registered
            final AuthScope ntlmAuthScope =
                    new AuthScope(proxyService.getProxyHost(), proxyService.getProxyPort(),
                            AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
            credentialsProvider.setCredentials(ntlmAuthScope,
                    new UsernamePasswordCredentials(proxyService.getUserName(), proxyService.getPassword()));
        }
    }

    // register a filter to set the User Agent header
    clientConfig.register(new ClientRequestFilter() {
        @Override
        public void filter(final ClientRequestContext requestContext) throws IOException {
            // The default user agent is something like "Jersey/2.6"
            final String userAgent = VersionInfo.getUserAgent("Apache-HttpClient", "org.apache.http.client", HttpClientBuilder.class);
            // Finally, we can add the header
            requestContext.getHeaders().add(HttpHeaders.USER_AGENT, userAgent);
        }
    });

    return clientConfig;
}
 
源代码5 项目: sana.mobile   文件: ApacheTest.java
public void testVersion() {
    VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
    String version = vi.getRelease();
    Log.d("apache http client version", version);
}
 
 类所在包
 类方法
 同包方法