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

项目:PhET    文件:PrintVersionInfo.java   
/**
 * Prints version information.
 *
 * @param args      command line arguments. Leave empty to print version
 *                  information for the default packages. Otherwise, pass
 *                  a list of packages for which to get version info.
 */
public static void main(String args[]) {
    String[]    pckgs = (args.length > 0) ? args : MODULE_LIST;
    VersionInfo[] via = VersionInfo.loadVersionInfo(pckgs, null);
    System.out.println("version info for thread context classloader:");
    for (int i=0; i<via.length; i++)
        System.out.println(via[i]);

    System.out.println();

    // if the version information for the classloader of this class
    // is different from that for the thread context classloader,
    // there may be a problem with multiple versions in the classpath

    via = VersionInfo.loadVersionInfo
        (pckgs, PrintVersionInfo.class.getClassLoader());
    System.out.println("version info for static classloader:");
    for (int i=0; i<via.length; i++)
        System.out.println(via[i]);
}
项目:navi    文件:NaviHttpBasicConfig.java   
/**
 * Saves the default set of HttpParams in the provided parameter. These are:
 * <ul>
 * <li>{@link CoreProtocolPNames#PROTOCOL_VERSION}: 1.1</li>
 * <li>{@link CoreProtocolPNames#HTTP_CONTENT_CHARSET}: ISO-8859-1</li>
 * <li>{@link CoreConnectionPNames#TCP_NODELAY}: true</li>
 * <li>{@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}: 8192</li>
 * <li>{@link CoreProtocolPNames#USER_AGENT}: Apache-HttpClient/<release>
 * (java 1.5)</li>
 * </ul>
 */
public void setDefaultHttpParams(HttpParams params) {
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    if (charset == null)
        HttpProtocolParams.setContentCharset(params,
            HTTP.DEF_CONTENT_CHARSET.name());
    else
        HttpProtocolParams.setContentCharset(params, charset);
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // determine the release version from packaged version info
    final VersionInfo vi = VersionInfo.loadVersionInfo(
        "org.apache.http.client",
        DefaultHttpClient.class.getClassLoader());
    final String release = (vi != null) ? vi.getRelease()
        : VersionInfo.UNAVAILABLE;
    if (getUserAgent() == null)
        HttpProtocolParams.setUserAgent(params, "Navi-HttpClient/"
            + release + " (java 1.5, navi 2.x)");
    else
        HttpProtocolParams.setUserAgent(params, getUserAgent());
    HttpConnectionParams.setConnectionTimeout(params, getConnectTimeout());
    HttpConnectionParams.setSoTimeout(params, getSocketTimeout());
}
项目:purecloud-iot    文件:CachingHttpClient.java   
private String generateViaHeader(final HttpMessage msg) {

        final ProtocolVersion pv = msg.getProtocolVersion();
        final String existingEntry = viaHeaders.get(pv);
        if (existingEntry != null) {
            return existingEntry;
        }

        final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
        final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;

        String value;
        if ("http".equalsIgnoreCase(pv.getProtocol())) {
            value = String.format("%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getMajor(), pv.getMinor(),
                    release);
        } else {
            value = String.format("%s/%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getProtocol(), pv.getMajor(),
                    pv.getMinor(), release);
        }
        viaHeaders.put(pv, value);

        return value;
    }
项目:purecloud-iot    文件:CachingExec.java   
private String generateViaHeader(final HttpMessage msg) {

        final ProtocolVersion pv = msg.getProtocolVersion();
        final String existingEntry = viaHeaders.get(pv);
        if (existingEntry != null) {
            return existingEntry;
        }

        final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
        final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;

        String value;
        final int major = pv.getMajor();
        final int minor = pv.getMinor();
        if ("http".equalsIgnoreCase(pv.getProtocol())) {
            value = String.format("%d.%d localhost (Apache-HttpClient/%s (cache))", major, minor,
                    release);
        } else {
            value = String.format("%s/%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getProtocol(), major,
                    minor, release);
        }
        viaHeaders.put(pv, value);

        return value;
    }
项目:purecloud-iot    文件:MinimalClientExec.java   
public MinimalClientExec(
        final HttpRequestExecutor requestExecutor,
        final HttpClientConnectionManager connManager,
        final ConnectionReuseStrategy reuseStrategy,
        final ConnectionKeepAliveStrategy keepAliveStrategy) {
    Args.notNull(requestExecutor, "HTTP request executor");
    Args.notNull(connManager, "Client connection manager");
    Args.notNull(reuseStrategy, "Connection reuse strategy");
    Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
    this.httpProcessor = new ImmutableHttpProcessor(
            new RequestContent(),
            new RequestTargetHost(),
            new RequestClientConnControl(),
            new RequestUserAgent(VersionInfo.getUserAgent(
                    "Apache-HttpClient", "org.apache.http.client", getClass())));
    this.requestExecutor    = requestExecutor;
    this.connManager        = connManager;
    this.reuseStrategy      = reuseStrategy;
    this.keepAliveStrategy  = keepAliveStrategy;
}
项目:cJUnit-mc626    文件:DefaultHttpClient.java   
@Override
protected HttpParams createHttpParams() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, 
            HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, 
            HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(params, 
            true);
    HttpConnectionParams.setTcpNoDelay(params, 
            true);
    HttpConnectionParams.setSocketBufferSize(params, 
            8192);

    // determine the release version from packaged version info
    final VersionInfo vi = VersionInfo.loadVersionInfo
        ("org.apache.http.client", getClass().getClassLoader());
    final String release = (vi != null) ?
        vi.getRelease() : VersionInfo.UNAVAILABLE;
    HttpProtocolParams.setUserAgent(params, 
            "Apache-HttpClient/" + release + " (java 1.5)");

    return params;
}
项目:jets3t-aws-roles    文件:RestUtils.java   
/**
 * Default Http parameters got from the DefaultHttpClient implementation.
 *
 * @return
 * Default HTTP connection parameters
 */
public static HttpParams createDefaultHttpParams() {
    HttpParams params = new SyncBasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params,
            HTTP.DEFAULT_CONTENT_CHARSET);
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // determine the release version from packaged version info
    final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client",
            HttpClient.class.getClassLoader());
    final String release = (vi != null)
            ? vi.getRelease()
            : VersionInfo.UNAVAILABLE;
    HttpProtocolParams.setUserAgent(params, "Apache-HttpClient/" + release
            + " (java 1.5)");

    return params;
}
项目: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);
    }
}
项目: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() {
  String version = System.getProperty("java.version");
  int pos = version.indexOf('.');
  pos = version.indexOf('.', pos + 1);
  boolean javaHasSNI = Double.parseDouble(version.substring(0, pos)) >= 1.7;

  final VersionInfo vi = VersionInfo.loadVersionInfo
    ("org.apache.http.client", APIClient.class.getClassLoader());
  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";
  }
}
项目:lams    文件:DefaultHttpClient.java   
/**
 * Saves the default set of HttpParams in the provided parameter.
 * These are:
 * <ul>
 * <li>{@link CoreProtocolPNames#PROTOCOL_VERSION}: 1.1</li>
 * <li>{@link CoreProtocolPNames#HTTP_CONTENT_CHARSET}: ISO-8859-1</li>
 * <li>{@link CoreConnectionPNames#TCP_NODELAY}: true</li>
 * <li>{@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}: 8192</li>
 * <li>{@link CoreProtocolPNames#USER_AGENT}: Apache-HttpClient/<release> (java 1.5)</li>
 * </ul>
 */
public static void setDefaultHttpParams(HttpParams params) {
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name());
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // determine the release version from packaged version info
    final VersionInfo vi = VersionInfo.loadVersionInfo
        ("org.apache.http.client", DefaultHttpClient.class.getClassLoader());
    final String release = (vi != null) ?
        vi.getRelease() : VersionInfo.UNAVAILABLE;
    HttpProtocolParams.setUserAgent(params,
            "Apache-HttpClient/" + release + " (java 1.5)");
}
项目:navi    文件:NaviHttpClientDriver.java   
private HttpParams getNaviHttpParams(NaviHttpPoolConfig httpPoolConfig) {
    params = new SyncBasicHttpParams();

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    if (httpPoolConfig.getCharset() == null) {
        HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name());
    } else {
        HttpProtocolParams.setContentCharset(params, httpPoolConfig.getCharset());
    }

    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // determine the release version from packaged version info
    final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", DefaultHttpClient.class.getClassLoader());
    final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;
    if (httpPoolConfig.getUserAgent() == null) {
        HttpProtocolParams.setUserAgent(params, "Navi-HttpClient/" + release + " (java 1.5, navi 2.x)");
    } else {
        HttpProtocolParams.setUserAgent(params, httpPoolConfig.getUserAgent());
    }

    HttpConnectionParams.setConnectionTimeout(params, httpPoolConfig.getConnectTimeout());
    HttpConnectionParams.setSoTimeout(params, httpPoolConfig.getSocketTimeout());

    if (httpPoolConfig.getProxy() != null) {
        try {
            String[] connectionString = httpPoolConfig.getProxy().split(":");
            HttpHost proxy = new HttpHost(connectionString[0], Integer.valueOf(connectionString[1]));
            // Integer.getInteger(connectionString[1]));
            params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        } catch (Exception e) {
            log.info(e.getMessage());
        }
    }
    return params;
}
项目:gooddata-java    文件:GoodData.java   
private String getUserAgent() {
    final Package pkg = Package.getPackage("com.gooddata");
    final String clientVersion = pkg != null && pkg.getImplementationVersion() != null
            ? pkg.getImplementationVersion() : UNKNOWN_VERSION;

    final VersionInfo vi = loadVersionInfo("org.apache.http.client", HttpClientBuilder.class.getClassLoader());
    final String apacheVersion = vi != null ? vi.getRelease() : UNKNOWN_VERSION;

    return String.format("%s/%s (%s; %s) %s/%s", "GoodData-Java-SDK", clientVersion,
            System.getProperty("os.name"), System.getProperty("java.specification.version"),
            "Apache-HttpClient", apacheVersion);
}
项目:http-client-essentials-suite    文件:ApacheProduct.java   
@Override
public void appendTo(StringBuilder sb)
{
    sb.append(VersionInfo.getUserAgent("Apache-HttpClient",
            "org.apache.http.client", HttpClient.class));
}
项目:vso-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()));
        }
    }

    // if this is a onPrem server and the uri starts with https, we need to setup ssl
    if (isSSLEnabledOnPrem(type, serverUri)) {
        clientConfig.property(ApacheClientProperties.SSL_CONFIG, getSslConfigurator());
    }

    // 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 defaultUserAgent = VersionInfo.getUserAgent("Apache-HttpClient", "org.apache.http.client", HttpClientBuilder.class);
            // We get the user agent string from the Telemetry context
            final String userAgent = PluginServiceProvider.getInstance().getTelemetryContextInitializer().getUserAgent(defaultUserAgent);
            // Finally, we can add the header
            requestContext.getHeaders().add(HttpHeaders.USER_AGENT, userAgent);
        }
    });

    return clientConfig;
}
项目:incubator-taverna-osgi    文件:DownloadManagerImpl.java   
public String getUserAgent() {
    Package pack = getClass().getPackage();
    String httpClientVersion = VersionInfo.getUserAgent("Apache-HttpClient", "org.apache.http.client",
            Request.class);
    return "Apache-Taverna-OSGi" + "/" + pack.getImplementationVersion() + " (" + httpClientVersion + ")";
}
项目: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);
}
项目:purecloud-iot    文件:DefaultHttpClient.java   
/**
 * Saves the default set of HttpParams in the provided parameter.
 * These are:
 * <ul>
 * <li>{@link org.apache.http.params.CoreProtocolPNames#PROTOCOL_VERSION}:
 *   1.1</li>
 * <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_CONTENT_CHARSET}:
 *   ISO-8859-1</li>
 * <li>{@link org.apache.http.params.CoreConnectionPNames#TCP_NODELAY}:
 *   true</li>
 * <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}:
 *   8192</li>
 * <li>{@link org.apache.http.params.CoreProtocolPNames#USER_AGENT}:
 *   Apache-HttpClient (Java 1.5)</li>
 * </ul>
 */
public static void setDefaultHttpParams(final HttpParams params) {
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.DEF_CONTENT_CHARSET.name());
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    HttpProtocolParams.setUserAgent(params, VersionInfo.getUserAgent("Apache-HttpClient",
            "org.apache.http.client", DefaultHttpClient.class));
}