本文整理匯總了Java中org.apache.http.client.params.CookiePolicy類的典型用法代碼示例。如果您正苦於以下問題:Java CookiePolicy類的具體用法?Java CookiePolicy怎麽用?Java CookiePolicy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CookiePolicy類屬於org.apache.http.client.params包,在下文中一共展示了CookiePolicy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createCookieSpecRegistry
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
protected CookieSpecRegistry createCookieSpecRegistry() {
CookieSpecRegistry registry = new CookieSpecRegistry();
registry.register(
CookiePolicy.BEST_MATCH,
new BestMatchSpecFactory());
registry.register(
CookiePolicy.BROWSER_COMPATIBILITY,
new BrowserCompatSpecFactory());
registry.register(
CookiePolicy.NETSCAPE,
new NetscapeDraftSpecFactory());
registry.register(
CookiePolicy.RFC_2109,
new RFC2109SpecFactory());
registry.register(
CookiePolicy.RFC_2965,
new RFC2965SpecFactory());
registry.register(
CookiePolicy.IGNORE_COOKIES,
new IgnoreSpecFactory());
return registry;
}
示例2: createCookieSpecRegistry
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
protected CookieSpecRegistry createCookieSpecRegistry() {
final CookieSpecRegistry registry = new CookieSpecRegistry();
registry.register(
CookieSpecs.DEFAULT,
new BestMatchSpecFactory());
registry.register(
CookiePolicy.BEST_MATCH,
new BestMatchSpecFactory());
registry.register(
CookiePolicy.BROWSER_COMPATIBILITY,
new BrowserCompatSpecFactory());
registry.register(
CookiePolicy.NETSCAPE,
new NetscapeDraftSpecFactory());
registry.register(
CookiePolicy.RFC_2109,
new RFC2109SpecFactory());
registry.register(
CookiePolicy.RFC_2965,
new RFC2965SpecFactory());
registry.register(
CookiePolicy.IGNORE_COOKIES,
new IgnoreSpecFactory());
return registry;
}
示例3: init
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
@Override
public void init() throws ServletException {
String doLogStr = getConfigParam(P_LOG);
if (doLogStr != null) {
this.doLog = Boolean.parseBoolean(doLogStr);
}
String doForwardIPString = getConfigParam(P_FORWARDEDFOR);
if (doForwardIPString != null) {
this.doForwardIP = Boolean.parseBoolean(doForwardIPString);
}
initTarget();//sets target*
HttpParams hcParams = new BasicHttpParams();
hcParams.setParameter(ClientPNames.COOKIE_POLICY,
CookiePolicy.IGNORE_COOKIES);
readConfigParam(hcParams, ClientPNames.HANDLE_REDIRECTS, Boolean.class);
proxyClient = createHttpClient(hcParams);
}
示例4: init
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
@Override
public void init() throws ServletException {
String doLogStr = getConfigParam(P_LOG);
if (doLogStr != null) {
this.doLog = Boolean.parseBoolean(doLogStr);
}
String doForwardIPString = getConfigParam(P_FORWARDEDFOR);
if (doForwardIPString != null) {
this.doForwardIP = Boolean.parseBoolean(doForwardIPString);
}
initTarget();// sets target*
HttpParams hcParams = new BasicHttpParams();
hcParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
readConfigParam(hcParams, ClientPNames.HANDLE_REDIRECTS, Boolean.class);
proxyClient = createHttpClient(hcParams);
}
示例5: getDefaultHttpClient
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
/**
* 獲取DefaultHttpClient對象
*
* @param charset
* 字符編碼
* @return DefaultHttpClient對象
*/
private static DefaultHttpClient getDefaultHttpClient(final String charset) {
DefaultHttpClient httpclient = new DefaultHttpClient();
// 模擬瀏覽器,解決一些服務器程序隻允許瀏覽器訪問的問題
httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT,
USER_AGENT);
httpclient.getParams().setParameter(
CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);
httpclient.getParams().setParameter(
CoreProtocolPNames.HTTP_CONTENT_CHARSET,
charset == null ? CHARSET_ENCODING : charset);
// 瀏覽器兼容性
httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY,
CookiePolicy.BROWSER_COMPATIBILITY);
// 定義重試策略
httpclient.setHttpRequestRetryHandler(requestRetryHandler);
return httpclient;
}
示例6: createCookieSpecRegistry
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
@Override
protected CookieSpecRegistry createCookieSpecRegistry() {
CookieSpecRegistry registry = new CookieSpecRegistry();
registry.register(
CookiePolicy.BEST_MATCH,
new BestMatchSpecFactory());
registry.register(
CookiePolicy.BROWSER_COMPATIBILITY,
new BrowserCompatSpecFactory());
registry.register(
CookiePolicy.NETSCAPE,
new NetscapeDraftSpecFactory());
registry.register(
CookiePolicy.RFC_2109,
new RFC2109SpecFactory());
registry.register(
CookiePolicy.RFC_2965,
new RFC2965SpecFactory());
return registry;
}
示例7: testCookiePolicy
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Test
public void testCookiePolicy() {
SpringClientFactory factory = new SpringClientFactory();
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
addEnvironment(parent, "ribbon.restclient.enabled=true");
parent.register(RibbonAutoConfiguration.class, ArchaiusAutoConfiguration.class);
parent.refresh();
factory.setApplicationContext(parent);
RestClient client = factory.getClient("foo", RestClient.class);
ApacheHttpClient4 jerseyClient = (ApacheHttpClient4) client.getJerseyClient();
assertEquals(CookiePolicy.IGNORE_COOKIES, jerseyClient.getClientHandler()
.getHttpClient().getParams().getParameter(ClientPNames.COOKIE_POLICY));
parent.close();
factory.destroy();
}
示例8: getClient
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
public synchronized HttpClient getClient() {
if (m_client == null) {
m_client = new DefaultHttpClient();
HttpParams clientParams = m_client.getParams();
clientParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, m_timeout);
clientParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, m_timeout);
clientParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
m_client.setParams(clientParams);
m_client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(m_retries, false));
}
return m_client;
}
示例9: buildParams
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
private static HttpParams buildParams(final HttpCollectionSet collectionSet) {
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, computeVersion(collectionSet.getUriDef()));
params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Integer.parseInt(ParameterMap.getKeyedString(collectionSet.getParameters(), "timeout", DEFAULT_SO_TIMEOUT)));
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, Integer.parseInt(ParameterMap.getKeyedString(collectionSet.getParameters(), "timeout", DEFAULT_SO_TIMEOUT)));
params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
//review the httpclient code, looks like virtual host is checked for null
//and if true, sets Host to the connection's host property
String virtualHost = collectionSet.getUriDef().getUrl().getVirtualHost();
if (virtualHost != null) {
params.setParameter(
ClientPNames.VIRTUAL_HOST,
new HttpHost(virtualHost, collectionSet.getPort())
);
}
return params;
}
示例10: ConnectionHelper
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
private ConnectionHelper() {
HttpParams httpParams = new BasicHttpParams();
ConnManagerParams.setMaxTotalConnections(httpParams,
MAX_TOTAL_CONNECTIONS);
ConnPerRouteBean connPerRoute = new ConnPerRouteBean(
MAX_CONNECTIONS_PER_HOST);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute);
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setUseExpectContinue(httpParams, false);
SchemeRegistry reg = new SchemeRegistry();
reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(),
80));
reg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(),
443));
ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(
httpParams, reg);
HttpConnectionParams.setConnectionTimeout(httpParams, CON_TIME_OUT_MS);
HttpConnectionParams.setSoTimeout(httpParams, SO_TIME_OUT_MS);
HttpClientParams.setCookiePolicy(httpParams,
CookiePolicy.BROWSER_COMPATIBILITY);
httpClient = new DefaultHttpClient(connectionManager, httpParams);
}
示例11: the_approval_will_be_remembered
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
@Test
@DatabaseSetup("/database_seed.xml")
public void the_approval_will_be_remembered() throws IOException {
givenValidAuthCode("marissa", "koala", "internal");
givenAuthCode();
givenAccessTokenUsingAuthCode();
{
HttpGet httpGet = new HttpGet(loginUri);
httpGet.getParams().setParameter(ClientPNames.COOKIE_POLICY,
CookiePolicy.NETSCAPE);
httpGet.getParams().setBooleanParameter("http.protocol.handle-redirects", false);
authCodeResponse = httpClient.execute(httpGet);
httpGet.releaseConnection();
}
givenAuthCode();
givenAccessTokenUsingAuthCode();
assertTrue(accessToken != null);
assertNotNull(accessToken.getRefreshToken());
}
示例12: the_approval_will_not_be_remembered_if_validity_is_zero
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
@Test
@DatabaseSetup("/database_seeds/LoginOAuth2IT/database_seed_zero_validity.xml")
public void the_approval_will_not_be_remembered_if_validity_is_zero() throws IOException {
givenValidAuthCode("marissa", "koala", "internal");
givenAuthCode();
givenAccessTokenUsingAuthCode();
HttpGet httpGet = new HttpGet(loginUri);
httpGet.getParams().setParameter(ClientPNames.COOKIE_POLICY,
CookiePolicy.NETSCAPE);
httpGet.getParams().setBooleanParameter("http.protocol.handle-redirects", false);
authCodeResponse = httpClient.execute(httpGet);
String response = IOUtils.toString(authCodeResponse.getEntity().getContent());
httpGet.releaseConnection();
assertThat(response, containsString("<title>Access confirmation</title>"));
}
示例13: HttpStoreClientFactory
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
public HttpStoreClientFactory(ClientConfig config) {
super(config);
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
config.getConnectionTimeout(TimeUnit.MILLISECONDS),
TimeUnit.MILLISECONDS);
mgr.setMaxTotal(config.getMaxTotalConnections());
mgr.setDefaultMaxPerRoute(config.getMaxConnectionsPerNode());
this.httpClient = new DefaultHttpClient(mgr);
HttpParams clientParams = this.httpClient.getParams();
HttpProtocolParams.setUserAgent(clientParams, VOLDEMORT_USER_AGENT);
HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);
HttpConnectionParams.setConnectionTimeout(clientParams,
config.getConnectionTimeout(TimeUnit.MILLISECONDS));
HttpConnectionParams.setSoTimeout(clientParams,
config.getSocketTimeout(TimeUnit.MILLISECONDS));
HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
this.httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
this.reroute = config.getRoutingTier().equals(RoutingTier.SERVER);
this.requestFormatFactory = new RequestFormatFactory();
}
示例14: createClient
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
private DefaultHttpClient createClient(boolean https)
{
final DefaultHttpClient client = (https ? new DefaultHttpClient(conMan) : new DefaultHttpClient());
// Allows a slightly lenient cookie acceptance
client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
// Allows follow of redirects on POST
client.setRedirectStrategy(new LaxRedirectStrategy());
return client;
}
示例15: setup
import org.apache.http.client.params.CookiePolicy; //導入依賴的package包/類
/**
* Setup some variables
*/
public void setup() {
log.info("Setup...");
if (StringUtils.isEmpty(this.username)) {
throw new IllegalArgumentException("Username is mandatory.");
}
if (StringUtils.isEmpty(this.password)) {
throw new IllegalArgumentException("Password is mandatory.");
}
this.deviceId = InstagramHashUtil.generateDeviceId(this.username, this.password);
if (StringUtils.isEmpty(this.uuid)) {
this.uuid = InstagramGenericUtil.generateUuid(true);
}
if (this.cookieStore == null) {
this.cookieStore = new BasicCookieStore();
}
log.info("Device ID is: " + this.deviceId + ", random id: " + this.uuid);
this.client = new DefaultHttpClient();
this.client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
this.client.setCookieStore(this.cookieStore);
}