我有一个支持URLConnection的AuthenticationHandler接口,但现在我正在使用Apache HTTP Client。我希望为两种连接类型(URLConnection和HTTP Client)都拥有通用的身份验证接口,但它们具有不同的参数并且功能不同。
我该如何设计这个接口?是否可以使用策略模式?
我的主要关注点是:
我该如何设计这个接口?是否可以使用策略模式?
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 conn,现在我们还想添加对 HTTP 客户端的支持。