📄 httpstate.java
字号:
* @deprecated Use * {@link org.apache.commons.httpclient.params.HttpClientParams#setAuthenticationPreemptive(boolean)}, * {@link HttpClient#getParams()}. */ public void setAuthenticationPreemptive(boolean value) { this.preemptive = value; } /** * Returns <tt>true</tt> if preemptive authentication should be * attempted, <tt>false</tt> otherwise. * * @return boolean flag. * * @deprecated Use * {@link org.apache.commons.httpclient.params.HttpClientParams#isAuthenticationPreemptive()}, * {@link HttpClient#getParams()}. */ public boolean isAuthenticationPreemptive() { return this.preemptive; } /** * Sets the current {@link CookiePolicy cookie policy} for this HTTP * state to one of the following supported policies: * {@link CookiePolicy#COMPATIBILITY}, * {@link CookiePolicy#NETSCAPE_DRAFT} or * {@link CookiePolicy#RFC2109}. * * @param policy new {@link CookiePolicy cookie policy} * * @deprecated * Use {@link org.apache.commons.httpclient.params.HttpMethodParams#setCookiePolicy(String)}, * {@link HttpMethod#getParams()}. */ public void setCookiePolicy(int policy) { this.cookiePolicy = policy; } /** * Sets the {@link Credentials credentials} for the given authentication * realm on the given host. The <code>null</code> realm signifies default * credentials for the given host, which should be used when no * {@link Credentials credentials} have been explictly supplied for the * challenging realm. The <code>null</code> host signifies default * credentials, which should be used when no {@link Credentials credentials} * have been explictly supplied for the challenging host. Any previous * credentials for the given realm on the given host will be overwritten. * * @param realm the authentication realm * @param host the host the realm belongs to * @param credentials the authentication {@link Credentials credentials} * for the given realm. * * @see #getCredentials(String, String) * @see #setProxyCredentials(String, String, Credentials) * * @deprecated use #setCredentials(AuthScope, Credentials) */ public synchronized void setCredentials(String realm, String host, Credentials credentials) { LOG.trace("enter HttpState.setCredentials(String, String, Credentials)"); credMap.put(new AuthScope(host, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME), credentials); } /** * Sets the {@link Credentials credentials} for the given authentication * scope. Any previous credentials for the given scope will be overwritten. * * @param authscope the {@link AuthScope authentication scope} * @param credentials the authentication {@link Credentials credentials} * for the given scope. * * @see #getCredentials(AuthScope) * @see #setProxyCredentials(AuthScope, Credentials) * * @since 3.0 */ public synchronized void setCredentials(final AuthScope authscope, final Credentials credentials) { if (authscope == null) { throw new IllegalArgumentException("Authentication scope may not be null"); } LOG.trace("enter HttpState.setCredentials(AuthScope, Credentials)"); credMap.put(authscope, credentials); } /** * Find matching {@link Credentials credentials} for the given authentication scope. * * @param map the credentials hash map * @param token the {@link AuthScope authentication scope} * @return the credentials * */ private static Credentials matchCredentials(final HashMap map, final AuthScope authscope) { // see if we get a direct hit Credentials creds = (Credentials)map.get(authscope); if (creds == null) { // Nope. // Do a full scan int bestMatchFactor = -1; AuthScope bestMatch = null; Iterator items = map.keySet().iterator(); while (items.hasNext()) { AuthScope current = (AuthScope)items.next(); int factor = authscope.match(current); if (factor > bestMatchFactor) { bestMatchFactor = factor; bestMatch = current; } } if (bestMatch != null) { creds = (Credentials)map.get(bestMatch); } } return creds; } /** * Get the {@link Credentials credentials} for the given authentication scope on the * given host. * * If the <i>realm</i> exists on <i>host</i>, return the coresponding credentials. * If the <i>host</i> exists with a <tt>null</tt> <i>realm</i>, return the corresponding * credentials. * If the <i>realm</i> exists with a <tt>null</tt> <i>host</i>, return the * corresponding credentials. If the <i>realm</i> does not exist, return * the default Credentials. If there are no default credentials, return * <code>null</code>. * * @param realm the authentication realm * @param host the host the realm is on * @return the credentials * * @see #setCredentials(String, String, Credentials) * * @deprecated use #getCredentials(AuthScope) */ public synchronized Credentials getCredentials(String realm, String host) { LOG.trace("enter HttpState.getCredentials(String, String"); return matchCredentials(this.credMap, new AuthScope(host, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME)); } /** * Get the {@link Credentials credentials} for the given authentication scope. * * @param authscope the {@link AuthScope authentication scope} * @return the credentials * * @see #setCredentials(AuthScope, Credentials) * * @since 3.0 */ public synchronized Credentials getCredentials(final AuthScope authscope) { if (authscope == null) { throw new IllegalArgumentException("Authentication scope may not be null"); } LOG.trace("enter HttpState.getCredentials(AuthScope)"); return matchCredentials(this.credMap, authscope); } /** * Sets the {@link Credentials credentials} for the given proxy authentication * realm on the given proxy host. The <code>null</code> proxy realm signifies * default credentials for the given proxy host, which should be used when no * {@link Credentials credentials} have been explictly supplied for the * challenging proxy realm. The <code>null</code> proxy host signifies default * credentials, which should be used when no {@link Credentials credentials} * have been explictly supplied for the challenging proxy host. Any previous * credentials for the given proxy realm on the given proxy host will be * overwritten. * * @param realm the authentication realm * @param proxyHost the proxy host * @param credentials the authentication credentials for the given realm * * @see #getProxyCredentials(AuthScope) * @see #setCredentials(AuthScope, Credentials) * * @deprecated use #setProxyCredentials(AuthScope, Credentials) */ public synchronized void setProxyCredentials( String realm, String proxyHost, Credentials credentials ) { LOG.trace("enter HttpState.setProxyCredentials(String, String, Credentials"); proxyCred.put(new AuthScope(proxyHost, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME), credentials); } /** * Sets the {@link Credentials proxy credentials} for the given authentication * realm. Any previous credentials for the given realm will be overwritten. * * @param authscope the {@link AuthScope authentication scope} * @param credentials the authentication {@link Credentials credentials} * for the given realm. * * @see #getProxyCredentials(AuthScope) * @see #setCredentials(AuthScope, Credentials) * * @since 3.0 */ public synchronized void setProxyCredentials(final AuthScope authscope, final Credentials credentials) { if (authscope == null) { throw new IllegalArgumentException("Authentication scope may not be null"); } LOG.trace("enter HttpState.setProxyCredentials(AuthScope, Credentials)"); proxyCred.put(authscope, credentials); } /** * Get the {@link Credentials credentials} for the proxy host with the given * authentication scope. * * If the <i>realm</i> exists on <i>host</i>, return the coresponding credentials. * If the <i>host</i> exists with a <tt>null</tt> <i>realm</i>, return the corresponding * credentials. * If the <i>realm</i> exists with a <tt>null</tt> <i>host</i>, return the * corresponding credentials. If the <i>realm</i> does not exist, return * the default Credentials. If there are no default credentials, return * <code>null</code>. * * @param realm the authentication realm * @param proxyHost the proxy host the realm is on * @return the credentials * @see #setProxyCredentials(String, String, Credentials) * * @deprecated use #getProxyCredentials(AuthScope) */ public synchronized Credentials getProxyCredentials(String realm, String proxyHost) { LOG.trace("enter HttpState.getCredentials(String, String"); return matchCredentials(this.proxyCred, new AuthScope(proxyHost, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME)); } /** * Get the {@link Credentials proxy credentials} for the given authentication scope. * * @param authscope the {@link AuthScope authentication scope} * @return the credentials * * @see #setProxyCredentials(AuthScope, Credentials) * * @since 3.0 */ public synchronized Credentials getProxyCredentials(final AuthScope authscope) { if (authscope == null) { throw new IllegalArgumentException("Authentication scope may not be null"); } LOG.trace("enter HttpState.getProxyCredentials(AuthScope)"); return matchCredentials(this.proxyCred, authscope); } /** * Returns a string representation of this HTTP state. * * @return The string representation of the HTTP state. * * @see java.lang.Object#toString() */ public synchronized String toString() { StringBuffer sbResult = new StringBuffer(); sbResult.append("["); sbResult.append(getCredentialsStringRepresentation(proxyCred)); sbResult.append(" | "); sbResult.append(getCredentialsStringRepresentation(credMap)); sbResult.append(" | "); sbResult.append(getCookiesStringRepresentation(cookiesMap.values())); sbResult.append("]"); String strResult = sbResult.toString(); return strResult; } /** * Returns a string representation of the credentials. * @param credMap The credentials. * @return The string representation. */ private static String getCredentialsStringRepresentation(final Map credMap) { StringBuffer sbResult = new StringBuffer(); Iterator iter = credMap.keySet().iterator(); while (iter.hasNext()) { Object key = iter.next(); Credentials cred = (Credentials) credMap.get(key); if (sbResult.length() > 0) { sbResult.append(", "); } sbResult.append(key); sbResult.append("#"); sbResult.append(cred.toString()); } return sbResult.toString(); } /** * Returns a string representation of the cookies. * @param cookies The cookies * @return The string representation. */ private static String getCookiesStringRepresentation(final Collection cookies) { StringBuffer sbResult = new StringBuffer(); Iterator iter = cookies.iterator(); while (iter.hasNext()) { Cookie ck = (Cookie) iter.next(); if (sbResult.length() > 0) { sbResult.append("#"); } sbResult.append(ck.toExternalForm()); } return sbResult.toString(); } /** * Clears all credentials. */ public void clearCredentials() { this.credMap.clear(); } /** * Clears all proxy credentials. */ public void clearProxyCredentials() { this.proxyCred.clear(); } /** * Clears all cookies. */ public void clearCookies() {// BEGIN IA CHANGES// this.cookiesArrayList.clear(); this.cookiesMap.clear();// END IA CHANGES } /** * Clears the state information (all cookies, credentials and proxy credentials). */ public void clear() { clearCookies(); clearCredentials(); clearProxyCredentials(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -