@Override protected HttpParams createHttpParams() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); /* * Android note: Send each request body without first asking the server * whether it will be accepted. Asking first slows down the common case * and results in "417 expectation failed" errors when a HTTP/1.0 server * is behind a proxy. http://b/2471595 */ HttpProtocolParams.setUseExpectContinue(params, false); // android-changed // 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.4)"); return params; }
clsldrstr = clsldr.toString(); return new VersionInfo(pckg, module, release, timestamp, clsldrstr);
result = fromMap(pckg, vip, clsldr);
@VisibleForTesting public static String httpClientVersion() { return VersionInfo.getUserAgent( "Apache-HttpClient", "org.apache.http.client", HttpClientBuilder.class); } }
/** * Loads version information for a list of packages. * * @param pckgs the packages for which to load version info * @param clsldr the classloader to load from, or * <code>null</code> for the thread context classloader * * @return the version information for all packages found, * never <code>null</code> */ public final static VersionInfo[] loadVersionInfo(String[] pckgs, ClassLoader clsldr) { if (pckgs == null) { throw new IllegalArgumentException ("Package identifier list must not be null."); } ArrayList vil = new ArrayList(pckgs.length); for (int i=0; i<pckgs.length; i++) { VersionInfo vi = loadVersionInfo(pckgs[i], clsldr); if (vi != null) vil.add(vi); } return (VersionInfo[]) vil.toArray(new VersionInfo[vil.size()]); }
VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client",getClass().getClassLoader()); String version = vi.getRelease(); Log.d("apache http client version", version);
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 + ")"; }
/** * Loads version information for a list of packages. * * @param pckgs the packages for which to load version info * @param clsldr the classloader to load from, or * <code>null</code> for the thread context classloader * * @return the version information for all packages found, * never <code>null</code> */ public final static VersionInfo[] loadVersionInfo(String[] pckgs, ClassLoader clsldr) { if (pckgs == null) { throw new IllegalArgumentException ("Package identifier list must not be null."); } ArrayList vil = new ArrayList(pckgs.length); for (int i=0; i<pckgs.length; i++) { VersionInfo vi = loadVersionInfo(pckgs[i], clsldr); if (vi != null) vil.add(vi); } return (VersionInfo[]) vil.toArray(new VersionInfo[vil.size()]); }
private String getVersionInfo() { // determine the release version from packaged version info final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader()); return (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE; }
/** * 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)); }
/** * Loads version information for a list of packages. * * @param pckgs the packages for which to load version info * @param clsldr the classloader to load from, or * <code>null</code> for the thread context classloader * * @return the version information for all packages found, * never <code>null</code> */ public final static VersionInfo[] loadVersionInfo(String[] pckgs, ClassLoader clsldr) { if (pckgs == null) { throw new IllegalArgumentException ("Package identifier list must not be null."); } ArrayList vil = new ArrayList(pckgs.length); for (int i=0; i<pckgs.length; i++) { VersionInfo vi = loadVersionInfo(pckgs[i], clsldr); if (vi != null) vil.add(vi); } return (VersionInfo[]) vil.toArray(new VersionInfo[vil.size()]); }
clsldrstr = clsldr.toString(); return new VersionInfo(pckg, module, release, timestamp, clsldrstr);
result = fromMap(pckg, vip, clsldr);
/** * Sets the user agent to {@code "<name>/<release> (Java 1.5 minimum; Java/<java.version>)"}. * <p/> * For example: * <pre>"Apache-HttpClient/4.3 (Java 1.5 minimum; Java/1.6.0_35)"</pre> * * @param name the component name, like "Apache-HttpClient". * @param pkg * the package for which to load version information, for example "org.apache.http". The package name * should NOT end with a dot. * @param cls * the class' class loader to load from, or <code>null</code> for the thread context class loader * @since 4.3 */ public static String getUserAgent(final String name, final String pkg, final Class<?> cls) { // determine the release version from packaged version info final VersionInfo vi = VersionInfo.loadVersionInfo(pkg, cls.getClassLoader()); final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE; final String javaVersion = System.getProperty("java.version"); return name + "/" + release + " (Java 1.5 minimum; Java/" + javaVersion + ")"; }
/** * 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)); }
/** * Loads version information for a list of packages. * * @param pckgs the packages for which to load version info * @param clsldr the classloader to load from, or * <code>null</code> for the thread context classloader * * @return the version information for all packages found, * never <code>null</code> */ public final static VersionInfo[] loadVersionInfo(String[] pckgs, ClassLoader clsldr) { if (pckgs == null) { throw new IllegalArgumentException ("Package identifier list must not be null."); } ArrayList vil = new ArrayList(pckgs.length); for (int i=0; i<pckgs.length; i++) { VersionInfo vi = loadVersionInfo(pckgs[i], clsldr); if (vi != null) vil.add(vi); } return (VersionInfo[]) vil.toArray(new VersionInfo[vil.size()]); }
clsldrstr = clsldr.toString(); return new VersionInfo(pckg, module, release, timestamp, clsldrstr);
result = fromMap(pckg, vip, clsldr);
/** * Sets the user agent to {@code "<name>/<release> (Java/<java.version>)"}. * <p> * For example: * <pre>"Apache-HttpClient/4.3 (Java/1.6.0_35)"</pre> * * @param name the component name, like "Apache-HttpClient". * @param pkg * the package for which to load version information, for example "org.apache.http". The package name * should NOT end with a dot. * @param cls * the class' class loader to load from, or {@code null} for the thread context class loader * @since 4.3 */ public static String getUserAgent(final String name, final String pkg, final Class<?> cls) { // determine the release version from packaged version info final VersionInfo vi = VersionInfo.loadVersionInfo(pkg, cls.getClassLoader()); final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE; final String javaVersion = System.getProperty("java.version"); return String.format("%s/%s (Java/%s)", name, release, javaVersion); }
/** * 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)); }