當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpHost.toHostString方法代碼示例

本文整理匯總了Java中org.apache.http.HttpHost.toHostString方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHost.toHostString方法的具體用法?Java HttpHost.toHostString怎麽用?Java HttpHost.toHostString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.HttpHost的用法示例。


在下文中一共展示了HttpHost.toHostString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: authenticate

import org.apache.http.HttpHost; //導入方法依賴的package包/類
@Override
public Header authenticate(
        final Credentials credentials,
        final HttpRequest request,
        final HttpContext context) throws AuthenticationException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    switch (state) {
    case UNINITIATED:
        throw new AuthenticationException(getSchemeName() + " authentication has not been initiated");
    case FAILED:
        throw new AuthenticationException(getSchemeName() + " authentication has failed");
    case CHALLENGE_RECEIVED:
        try {
            String key = null;
            if (isProxy()) {
                key = ExecutionContext.HTTP_PROXY_HOST;
            } else {
                key = ExecutionContext.HTTP_TARGET_HOST;
            }
            HttpHost host = (HttpHost) context.getAttribute(key);
            if (host == null) {
                throw new AuthenticationException("Authentication host is not set " +
                        "in the execution context");
            }
            String authServer;
            if (!this.stripPort && host.getPort() > 0) {
                authServer = host.toHostString();
            } else {
                authServer = host.getHostName();
            }

            if (log.isDebugEnabled()) {
                log.debug("init " + authServer);
            }
            token = generateToken(token, authServer);
            state = State.TOKEN_GENERATED;
        } catch (GSSException gsse) {
            state = State.FAILED;
            if (gsse.getMajor() == GSSException.DEFECTIVE_CREDENTIAL
                    || gsse.getMajor() == GSSException.CREDENTIALS_EXPIRED)
                throw new InvalidCredentialsException(gsse.getMessage(), gsse);
            if (gsse.getMajor() == GSSException.NO_CRED )
                throw new InvalidCredentialsException(gsse.getMessage(), gsse);
            if (gsse.getMajor() == GSSException.DEFECTIVE_TOKEN
                    || gsse.getMajor() == GSSException.DUPLICATE_TOKEN
                    || gsse.getMajor() == GSSException.OLD_TOKEN)
                throw new AuthenticationException(gsse.getMessage(), gsse);
            // other error
            throw new AuthenticationException(gsse.getMessage());
        }
    case TOKEN_GENERATED:
        String tokenstr = new String(base64codec.encode(token));
        if (log.isDebugEnabled()) {
            log.debug("Sending response '" + tokenstr + "' back to the auth server");
        }
        return new BasicHeader("Authorization", "Negotiate " + tokenstr);
    default:
        throw new IllegalStateException("Illegal state: " + state);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:63,代碼來源:GGSSchemeBase.java


注:本文中的org.apache.http.HttpHost.toHostString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。