我有一个支持 URLConnection 的 AuthenticationHandler 接口,但现在我使用的是 Apache HTTP 客户端。我想为两种连接类型(URLConnection 和 HTTP 客户端)提供一个通用的身份验证接口,但它们都有不同的参数和不同的功能。
我将如何设计这个?策略模式是要走的路吗?
import java.net.URLConnection;
import java.util.List;
public interface AuthenticationHandler {
/**
* this needs to be called by everyone that needs direct access to a link which may have
* security access rules.
*/
void trustAll();
/**
*
* @param URLconnection where you set access state parameters or anything access related
* @param slice where you could get access config
* @param initializeSlice is true if you want the proxy to hibernate initialize all hibernated objects
* @return
* @throws ConnectionException
*/
void authenticate(URLConnection conn) throws ConnectionException;
List<String> getSingleCookie();
void setSingleCookie(List<String> singleCookies);
CookieManager getCookieManager();
void setCookieManager(CookieManager cookieManager);
boolean isKeepGeneratedCookie();
void setKeepGeneratedCookie(boolean keepGeneratedCookie);
}
我主要担心的是
void authenticate(URLConnection conn) throws ConnectionException;
它最初采用 URLConnection 连接,但现在我们也想添加对 HTTP 客户端的支持。