当前位置: 首页>>代码示例>>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;未经允许,请勿转载。