Apache HTTP コンポーネント 4 クラス org.apache.http.impl.auth.BasicScheme で、次のメソッドに気付きました。
public static Header authenticate(
final Credentials credentials,
final String charset,
final boolean proxy)
次の情報で廃止されました。
/**
* Returns a basic <tt>Authorization</tt> header value for the given
* {@link Credentials} and charset.
*
* @param credentials The credentials to encode.
* @param charset The charset to use for encoding the credentials
*
* @return a basic authorization header
*
* @deprecated (4.3) use {@link #authenticate(Credentials, HttpRequest, HttpContext)}.
*/
@Deprecated
ただし、廃止された関数から新しい関数に移行する方法を説明するドキュメントはありません。廃止された機能は機能しますが、私はむしろ「正しい」方法で物事を行いたいと考えています。非推奨の関数を使用する方法は次のとおりです。
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("admin", "admin");
URI uriLogin = URI.create("http://localhost:8161/hawtio/auth/login/");
HttpPost hpLogin = new HttpPost(uriLogin);
hpLogin.setHeader(BasicScheme.authenticate(creds, "US-ASCII", false));
この同じ概念を BasicScheme.authenticate の「正しい」メソッドに適用するにはどうすればよいでしょうか?