org.apache.http.util.VersionInfo Java Examples

The following examples show how to use org.apache.http.util.VersionInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CachingHttpClient.java    From apigee-android-sdk with Apache License 2.0 6 votes vote down vote up
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);
	}
}
 
Example #2
Source File: APIClient.java    From algoliasearch-client-java with MIT License 6 votes vote down vote up
/**
 * 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";
  }
}
 
Example #3
Source File: CurlFakeTest.java    From curl with The Unlicense 5 votes vote down vote up
@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 ()));
}
 
Example #4
Source File: RestClientHelper.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
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;
}
 
Example #5
Source File: ApacheTest.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void testVersion() {
    VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
    String version = vi.getRelease();
    Log.d("apache http client version", version);
}