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


Java LaxRedirectStrategy類代碼示例

本文整理匯總了Java中org.apache.http.impl.client.LaxRedirectStrategy的典型用法代碼示例。如果您正苦於以下問題:Java LaxRedirectStrategy類的具體用法?Java LaxRedirectStrategy怎麽用?Java LaxRedirectStrategy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LaxRedirectStrategy類屬於org.apache.http.impl.client包,在下文中一共展示了LaxRedirectStrategy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: download

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
private static void download(String url, File destination)
        throws IOException {
    HttpUriRequest request = RequestBuilder
            .get()
            .setUri(url)
            .addParameter("hostname",
                    MinecraftServer.getServer().getHostname())
            .addParameter("port",
                    String.valueOf(MinecraftServer.getServer().getPort()))
            .build();
    CloseableHttpClient client = HttpClientBuilder.create()
            .setRedirectStrategy(new LaxRedirectStrategy())
            .setUserAgent("Uranium Updater").build();

    HttpResponse response = client.execute(request);
    if (response.getStatusLine().getStatusCode() != 200) {
        client.close();
        throw new IllegalStateException("Could not download " + url);
    }
    InputStream is = response.getEntity().getContent();
    OutputStream os = new FileOutputStream(destination);
    IOUtils.copy(is, os);
    is.close();
    os.close();
    client.close();
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:27,代碼來源:UraniumUpdater.java

示例2: constructHttpClient

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
protected CloseableHttpClient constructHttpClient() throws IOException {
  RequestConfig config = RequestConfig.custom()
                                      .setConnectTimeout(20 * 1000)
                                      .setConnectionRequestTimeout(20 * 1000)
                                      .setSocketTimeout(20 * 1000)
                                      .setMaxRedirects(20)
                                      .build();

  URL                 mmsc          = new URL(apn.getMmsc());
  CredentialsProvider credsProvider = new BasicCredentialsProvider();

  if (apn.hasAuthentication()) {
    credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
                                 new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
  }

  return HttpClients.custom()
                    .setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
                    .setRedirectStrategy(new LaxRedirectStrategy())
                    .setUserAgent(TextSecurePreferences.getMmsUserAgent(context, USER_AGENT))
                    .setConnectionManager(new BasicHttpClientConnectionManager())
                    .setDefaultRequestConfig(config)
                    .setDefaultCredentialsProvider(credsProvider)
                    .build();
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:26,代碼來源:LegacyMmsConnection.java

示例3: gen

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
@Override
public CrawlerHttpClient gen(CrawlerHttpClientBuilder proxyFeedBackDecorateHttpClientBuilder) {
    SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).setSoLinger(-1).setSoReuseAddress(false)
            .setSoTimeout(ProxyConstant.SOCKETSO_TIMEOUT).setTcpNoDelay(true).build();

    return proxyFeedBackDecorateHttpClientBuilder
            .setDefaultSocketConfig(socketConfig)
            // .setSSLSocketFactory(sslConnectionSocketFactory)
            // dungproxy0.0.6之後的版本,默認忽略https證書檢查
            .setRedirectStrategy(new LaxRedirectStrategy())
            //注意,這裏使用ua生產算法自動產生ua,如果是mobile,可以使用
            // com.virjar.vscrawler.core.net.useragent.UserAgentBuilder.randomAppUserAgent()
            .setUserAgent(UserAgentBuilder.randomUserAgent())
            //對於爬蟲來說,連接池沒啥卵用,直接禁止掉(因為我們可能創建大量HttpClient,每個HttpClient一個連接池,會把係統socket資源撐爆)
            //測試開80個httpClient抓數據大概一個小時係統就會宕機
            .setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE)
            .build();

}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:20,代碼來源:DefaultHttpClientGenerator.java

示例4: newClosableCachingHttpClient

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
private static CloseableHttpClient newClosableCachingHttpClient(EventStoreSettings settings) {
   final CacheConfig cacheConfig = CacheConfig.custom()
         .setMaxCacheEntries(Integer.MAX_VALUE)
         .setMaxObjectSize(Integer.MAX_VALUE)
         .build();

   settings.getCacheDirectory()
         .mkdirs();

   return CachingHttpClientBuilder.create()
         .setHttpCacheStorage(new FileCacheStorage(cacheConfig, settings.getCacheDirectory()))
         .setCacheConfig(cacheConfig)
         .setDefaultRequestConfig(requestConfig(settings))
         .setDefaultCredentialsProvider(credentialsProvider(settings))
         .setRedirectStrategy(new LaxRedirectStrategy())
         .setRetryHandler(new StandardHttpRequestRetryHandler())
         .setKeepAliveStrategy(new de.qyotta.eventstore.utils.DefaultConnectionKeepAliveStrategy())
         .setConnectionManagerShared(true)

         .build();
}
 
開發者ID:Qyotta,項目名稱:axon-eventstore,代碼行數:22,代碼來源:HttpClientFactory.java

示例5: getGithubZipball

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
public static String getGithubZipball(String owner, String repo, String destFolder) throws IOException {
    CloseableHttpClient httpclient = HttpClients.custom()
            .setRedirectStrategy(new LaxRedirectStrategy())
            .build();
    String urlForGet = "https://api.github.com/repos/" + owner + "/" + repo + "/zipball/";

    HttpGet get = new HttpGet(urlForGet);

    HttpResponse response = httpclient.execute(get);

    InputStream is = response.getEntity().getContent();
    String filePath = destFolder + File.separator + repo + ".zip";
    FileOutputStream fos = new FileOutputStream(new File(filePath));

    int inByte;
    while ((inByte = is.read()) != -1)
        fos.write(inByte);
    is.close();
    fos.close();
    return filePath;
}
 
開發者ID:firm1,項目名稱:zest-writer,代碼行數:22,代碼來源:GithubHttp.java

示例6: createHttpClient

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
public static CloseableHttpClient createHttpClient(final int maxRedirects) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
    s_logger.info("Creating new HTTP connection pool and client");
    final Registry<ConnectionSocketFactory> socketFactoryRegistry = createSocketFactoryConfigration();
    final BasicCookieStore cookieStore = new BasicCookieStore();
    final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
    connManager.setDefaultMaxPerRoute(MAX_ALLOCATED_CONNECTIONS_PER_ROUTE);
    connManager.setMaxTotal(MAX_ALLOCATED_CONNECTIONS);
    final RequestConfig requestConfig = RequestConfig.custom()
                                                     .setCookieSpec(CookieSpecs.DEFAULT)
                                                     .setMaxRedirects(maxRedirects)
                                                     .setSocketTimeout(DEFAULT_SOCKET_TIMEOUT)
                                                     .setConnectionRequestTimeout(DEFAULT_CONNECTION_REQUEST_TIMEOUT)
                                                     .setConnectTimeout(DEFAULT_CONNECT_TIMEOUT)
                                                     .build();
    return HttpClientBuilder.create()
                            .setConnectionManager(connManager)
                            .setRedirectStrategy(new LaxRedirectStrategy())
                            .setDefaultRequestConfig(requestConfig)
                            .setDefaultCookieStore(cookieStore)
                            .setRetryHandler(new StandardHttpRequestRetryHandler())
                            .build();
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:23,代碼來源:HttpClientHelper.java

示例7: constructHttpClient

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
protected CloseableHttpClient constructHttpClient()
    throws IOException {
  RequestConfig config = RequestConfig.custom()
                                      .setConnectTimeout(20 * 1000)
                                      .setConnectionRequestTimeout(20 * 1000)
                                      .setSocketTimeout(20 * 1000)
                                      .setMaxRedirects(20)
                                      .build();

  URL mmsc = new URL(apn.getMmsc());
  CredentialsProvider credsProvider = new BasicCredentialsProvider();

  if (apn.hasAuthentication()) {
    credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
                                 new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
  }

  return HttpClients.custom()
                    .setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
                    .setRedirectStrategy(new LaxRedirectStrategy())
                    .setUserAgent("Android-Mms/2.0")
                    .setConnectionManager(new BasicHttpClientConnectionManager())
                    .setDefaultRequestConfig(config)
                    .setDefaultCredentialsProvider(credsProvider)
                    .build();
}
 
開發者ID:redcracker,項目名稱:TextSecure,代碼行數:27,代碼來源:MmsConnection.java

示例8: doGet

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
@Override
   public void doGet(IHTTPSession session, Response response) {
try {
    CloseableHttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
    String url = session.getParms().get("image");
    HttpGet httpGet = new HttpGet(url);
    httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0.3");
    httpGet.addHeader("Accept-Encoding", "gzip");
    CloseableHttpResponse imdbResponse = httpClient.execute(httpGet);
    HttpEntity httpEntity = imdbResponse.getEntity();

    response.setChunkedTransfer(true);
    response.setMimeType("image/jpeg");
    response.setData(httpEntity.getContent());
} catch (Exception e) {
    e.printStackTrace();
}
   }
 
開發者ID:crsmoro,項目名稱:vntscraper,代碼行數:19,代碼來源:LoadImageImdb.java

示例9: fetchResult

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
public OmdbResponse fetchResult() {
	OmdbResponse omdbResponse = null;
	try {
		CloseableHttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();

		List<NameValuePair> nameValuePairs = buildNameValuePair();

		String url = "http://www.omdbapi.com/?" + URLEncodedUtils.format(nameValuePairs, "UTF-8");
		log.debug("URL : " + url);
		HttpGet httpGet = new HttpGet(url);
		httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0.3");
		httpGet.addHeader("Accept-Encoding", "gzip");
		CloseableHttpResponse imdbResponse = httpClient.execute(httpGet);

		HttpEntity httpEntity = imdbResponse.getEntity();

		String content = EntityUtils.toString(httpEntity);
		log.debug("content : " + content);
		//FIXME to use jackson objectmapper
		Gson gson = new GsonBuilder().serializeNulls().create();
		omdbResponse = gson.fromJson(content, OmdbResponse.class);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return omdbResponse;
}
 
開發者ID:crsmoro,項目名稱:vntscraper,代碼行數:27,代碼來源:OmdbAPI.java

示例10: download

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
private static void download(String url, File destination)
        throws IOException {
    HttpUriRequest request = RequestBuilder
            .get()
            .setUri(url)
            .addParameter("hostname",
                    MinecraftServer.getServer().getHostname())
            .addParameter("port",
                    String.valueOf(MinecraftServer.getServer().getPort()))
            .build();
    CloseableHttpClient client = HttpClientBuilder.create()
            .setRedirectStrategy(new LaxRedirectStrategy())
            .setUserAgent("KCauldron Updater").build();

    HttpResponse response = client.execute(request);
    if (response.getStatusLine().getStatusCode() != 200) {
        client.close();
        throw new IllegalStateException("Could not download " + url);
    }
    InputStream is = response.getEntity().getContent();
    OutputStream os = new FileOutputStream(destination);
    IOUtils.copy(is, os);
    is.close();
    os.close();
    client.close();
}
 
開發者ID:djoveryde,項目名稱:KCauldron,代碼行數:27,代碼來源:KCauldronUpdater.java

示例11: constructHttpClient

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
protected CloseableHttpClient constructHttpClient() throws IOException {
  RequestConfig config = RequestConfig.custom()
                                      .setConnectTimeout(20 * 1000)
                                      .setConnectionRequestTimeout(20 * 1000)
                                      .setSocketTimeout(20 * 1000)
                                      .setMaxRedirects(20)
                                      .build();

  URL                 mmsc          = new URL(apn.getMmsc());
  CredentialsProvider credsProvider = new BasicCredentialsProvider();

  if (apn.hasAuthentication()) {
    credsProvider.setCredentials(new AuthScope(mmsc.getHost(), mmsc.getPort() > -1 ? mmsc.getPort() : mmsc.getDefaultPort()),
                                 new UsernamePasswordCredentials(apn.getUsername(), apn.getPassword()));
  }

  return HttpClients.custom()
                    .setConnectionReuseStrategy(new NoConnectionReuseStrategyHC4())
                    .setRedirectStrategy(new LaxRedirectStrategy())
                    .setUserAgent(SilencePreferences.getMmsUserAgent(context, USER_AGENT))
                    .setConnectionManager(new BasicHttpClientConnectionManager())
                    .setDefaultRequestConfig(config)
                    .setDefaultCredentialsProvider(credsProvider)
                    .build();
}
 
開發者ID:SilenceIM,項目名稱:Silence,代碼行數:26,代碼來源:LegacyMmsConnection.java

示例12: testSessionIdentityCache

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
@Test
public void testSessionIdentityCache() throws Exception {
    HttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
    HttpPost httpAuthenticate = new HttpPost(server.createUri("/j_security_check"));
    List<NameValuePair> parameters = new ArrayList<>(2);

    parameters.add(new BasicNameValuePair("j_username", "ladybird"));
    parameters.add(new BasicNameValuePair("j_password", "Coleoptera"));

    httpAuthenticate.setEntity(new UrlEncodedFormEntity(parameters));

    assertSuccessfulResponse(httpClient.execute(httpAuthenticate), "ladybird");

    for (int i = 0; i < 10; i++) {
        assertSuccessfulResponse(httpClient.execute(new HttpGet(server.createUri())), "ladybird");
    }

    assertEquals(1, realmIdentityInvocationCount.get());
}
 
開發者ID:wildfly-security,項目名稱:elytron-web,代碼行數:20,代碼來源:FormAuthenticationTest.java

示例13: createClient

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
/**
 * Creates asynchronous Apache HTTP client.
 *
 * @param settings
 *         settings to use to create client.
 * @param conf
 *         configuration related to async connection.
 * @return Instance of {@link CloseableHttpAsyncClient}.
 */
private CloseableHttpAsyncClient createClient(HttpSettings settings, ApacheHttpClientConfiguration conf) {
    IOReactorConfig ioReactor = IOReactorConfig.custom().setIoThreadCount(conf.getMaxThreadCount()).build();
    HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClients.custom()
            .useSystemProperties()
                    // allow POST redirects
            .setRedirectStrategy(new LaxRedirectStrategy()).setMaxConnTotal(conf.getMaxTotalConnectionCount()).setMaxConnPerRoute(conf.getMaxRouteConnectionCount()).setDefaultIOReactorConfig(ioReactor)
            .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()).setDefaultRequestConfig(createDefaultRequestConfig(settings));
    if (settings.getProxyUrl() != null) {
        DefaultProxyRoutePlanner routePlanner = createProxyRoutePlanner(settings, httpClientBuilder);
        httpClientBuilder.setRoutePlanner(routePlanner);
    }
    CloseableHttpAsyncClient httpClient = httpClientBuilder.build();
    httpClient.start();
    return httpClient;
}
 
開發者ID:guardtime,項目名稱:ksi-java-sdk,代碼行數:25,代碼來源:AbstractApacheHttpClient.java

示例14: createClient

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
private CloseableHttpClient createClient() {
	final HttpClientBuilder builder = HttpClientBuilder.create();

	// Provide username and password if specified
	if (username != null) {
		final BasicCredentialsProvider credProvider = new BasicCredentialsProvider();
		credProvider.setCredentials(new AuthScope(new HttpHost(repositoryURL.getHost())),
				new UsernamePasswordCredentials(username, password));
		builder.setDefaultCredentialsProvider(credProvider);
	}

	// Follow redirects
	builder.setRedirectStrategy(new LaxRedirectStrategy());

	return builder.build();
}
 
開發者ID:mondo-project,項目名稱:mondo-hawk,代碼行數:17,代碼來源:HTTPManager.java

示例15: HttpBuilder

import org.apache.http.impl.client.LaxRedirectStrategy; //導入依賴的package包/類
/**
 * Creates a new {@link HttpBuilder}. Without additional input, the builder
 * is set up to build {@link Http} instances with the following properties:
 * <ul>
 * <li>default connection timeout and socket timeout: 20 seconds</li>
 * <li>server authentication/verification (on SSL): none</li>
 * <li>client authentication: none</li>
 * <li>default request content type: application/json</li>
 * </ul>
 * All of these settings can be modified through the builder's methods.
 */
public HttpBuilder() {
    this.clientBuilder = HttpClients.custom();
    this.clientBuilder.setRedirectStrategy(new LaxRedirectStrategy());

    this.requestConfigBuilder = RequestConfig.copy(RequestConfig.DEFAULT);
    this.requestConfigBuilder.setConnectTimeout(DEFAULT_CONNECTION_TIMEOUT);
    this.requestConfigBuilder.setSocketTimeout(DEFAULT_SOCKET_TIMEOUT);

    this.sslContextBuilder = SslContextBuilder.newBuilder();
    verifyHostCert(false);
    verifyHostname(false);

    this.defaultHeaders = new HashMap<>();
    contentType(ContentType.APPLICATION_JSON);

    this.logger = Http.LOG;
}
 
開發者ID:elastisys,項目名稱:scale.commons,代碼行數:29,代碼來源:HttpBuilder.java


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