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


Java DefaultRedirectStrategy類代碼示例

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


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

示例1: RequestEntityRestStorageService

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
public RequestEntityRestStorageService(final S3Session session,
                                       final Jets3tProperties properties,
                                       final HttpClientBuilder configuration) {
    super(session.getHost().getCredentials().isAnonymousLogin() ? null :
                    new AWSCredentials(null, null) {
                        @Override
                        public String getAccessKey() {
                            return session.getHost().getCredentials().getUsername();
                        }

                        @Override
                        public String getSecretKey() {
                            return session.getHost().getCredentials().getPassword();
                        }
                    },
            new PreferencesUseragentProvider().get(), null, properties);
    this.session = session;
    configuration.disableContentCompression();
    configuration.setRetryHandler(new S3HttpRequestRetryHandler(this, preferences.getInteger("http.connections.retry")));
    configuration.setRedirectStrategy(new DefaultRedirectStrategy() {
        @Override
        public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException {
            if(response.containsHeader("x-amz-bucket-region")) {
                final String host = ((HttpUriRequest) request).getURI().getHost();
                if(!StringUtils.equals(session.getHost().getHostname(), host)) {
                    regionEndpointCache.putRegionForBucketName(
                            StringUtils.split(StringUtils.removeEnd(((HttpUriRequest) request).getURI().getHost(), session.getHost().getHostname()), ".")[0],
                            response.getFirstHeader("x-amz-bucket-region").getValue());
                }
            }
            return super.getRedirect(request, response, context);
        }
    });
    this.setHttpClient(configuration.build());
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:36,代碼來源:RequestEntityRestStorageService.java

示例2: setRedirects

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
private HttpAsyncClientBuilder setRedirects(HttpAsyncClientBuilder clientBuilder) {
  clientBuilder.setRedirectStrategy(new DefaultRedirectStrategy() {
    /** Redirectable methods. */
    private String[] REDIRECT_METHODS = new String[] { 
      HttpGet.METHOD_NAME, HttpPost.METHOD_NAME, 
      HttpPut.METHOD_NAME, HttpDelete.METHOD_NAME, HttpHead.METHOD_NAME 
    };

    @Override
    protected boolean isRedirectable(String method) {
      for (String m : REDIRECT_METHODS) {
        if (m.equalsIgnoreCase(method)) {
          return true;
        }
      }
      return false;
    }
  });
  return clientBuilder;
}
 
開發者ID:apache,項目名稱:zeppelin,代碼行數:21,代碼來源:HttpProxyClient.java

示例3: createHttpClient

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
/**
 * Returns a new HTTP client by the specified repository configuration.
 *
 * @return a new HTTP client by the specified repository configuration
 */
private HttpClient createHttpClient() {
    RequestConfig.Builder requestBuilder = RequestConfig.custom().setSocketTimeout(10 * 1000);

    if (repoConfig.getProxy() != null) {
        requestBuilder.setProxy(HttpHost.create(repoConfig.getProxy()));
    }

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setDefaultRequestConfig(requestBuilder.build());
    httpClientBuilder = httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(3, false));
    httpClientBuilder = httpClientBuilder.setRedirectStrategy(new DefaultRedirectStrategy());

    if (repoConfig.getUsername() != null) {
        final Credentials creds = new UsernamePasswordCredentials(repoConfig.getUsername(), repoConfig.getPassword());
        final CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY, creds);
        httpClientBuilder = httpClientBuilder.setDefaultCredentialsProvider(credsProvider);
    }
    return httpClientBuilder.build();
}
 
開發者ID:1and1,項目名稱:go-maven-poller,代碼行數:25,代碼來源:RepositoryConnector.java

示例4: _invoke

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
private static HTTPResponse _invoke(URL url,HttpUriRequest request,String username,String password, long timeout, boolean redirect,
          String charset, String useragent,
          ProxyData proxy, lucee.commons.net.http.Header[] headers, Map<String,String> formfields) throws IOException {
  	
HttpClientBuilder builder = HttpClients.custom();
  	
  	// redirect
  	if(redirect)  builder.setRedirectStrategy(new DefaultRedirectStrategy());
  	else builder.disableRedirectHandling();
  	
  	HttpHost hh=new HttpHost(url.getHost(),url.getPort());
  	setHeader(request,headers);
  	if(CollectionUtil.isEmpty(formfields))setContentType(request,charset);
  	setFormFields(request,formfields,charset);
  	setUserAgent(request,useragent);
  	if(timeout>0)Http41.setTimeout(builder,TimeSpanImpl.fromMillis(timeout));
  	HttpContext context=setCredentials(builder,hh, username, password,false);  
  	setProxy(builder,request,proxy);
  	CloseableHttpClient client = builder.build();
      if(context==null)context = new BasicHttpContext();
      return new HTTPResponse4Impl(url,context,request,client.execute(request,context));
  }
 
開發者ID:lucee,項目名稱:Lucee4,代碼行數:23,代碼來源:HTTPEngineImpl.java

示例5: newClient

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
@Override
   protected Client newClient() {
ResteasyClientBuilder resteasyClientBuilder = new ResteasyClientBuilder();
ResteasyClient client = resteasyClientBuilder.establishConnectionTimeout(getTimeout(), TimeUnit.MILLISECONDS).socketTimeout(getTimeout(), TimeUnit.MILLISECONDS).build();
AbstractHttpClient httpClient = (AbstractHttpClient) ((ApacheHttpClient4Engine) client.httpEngine()).getHttpClient();
httpClient.setRedirectStrategy(new DefaultRedirectStrategy() {

    @Override
    protected boolean isRedirectable(String method) {
	return true;
    }
});
httpClient.addRequestInterceptor(new HttpRequestInterceptor() {

    @Override
    public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
	request.setParams(new AllowRedirectHttpParams(request.getParams()));
    }
});
return client;
   }
 
開發者ID:CurrentContinuation,項目名稱:gigasetelements,代碼行數:22,代碼來源:GigasetElementsRestEasy.java

示例6: getWithoutAutoRedirect

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
/**
 * HTTP GET Without Handling HTTP redirects automatically
 * 
 * @param url
 * @param headers
 * @return CloseableHttpResponse
 */
public static CloseableHttpResponse getWithoutAutoRedirect(String url, Map<String, String> headers) {
	if (url == null) {
		return null;
	}
	HttpGet get = new HttpGet(url);
	addHeaders(get, headers);
	CloseableHttpResponse response = null;
	try {
		client = HttpClients.custom().disableRedirectHandling().build();
		response = visit(get);
		RedirectStrategy rs = DefaultRedirectStrategy.INSTANCE;
		client = HttpClients.custom().setRedirectStrategy(rs).build();
	} catch (Exception e) {
		logger.error(e.getMessage());
		e.printStackTrace();
	}
	return response;
}
 
開發者ID:gitzhou,項目名稱:yunti-speed-test,代碼行數:26,代碼來源:HttpUtils.java

示例7: _invoke

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
private static HTTPResponse _invoke(URL url,HttpUriRequest request,String username,String password, long timeout, boolean redirect,
          String charset, String useragent,
          ProxyData proxy, lucee.commons.net.http.Header[] headers, Map<String,String> formfields) throws IOException {

HttpClientBuilder builder = getHttpClientBuilder();

  	// redirect
  	if(redirect)  builder.setRedirectStrategy(new DefaultRedirectStrategy());
  	else builder.disableRedirectHandling();

  	HttpHost hh=new HttpHost(url.getHost(),url.getPort());
  	setHeader(request,headers);
  	if(CollectionUtil.isEmpty(formfields))setContentType(request,charset);
  	setFormFields(request,formfields,charset);
  	setUserAgent(request,useragent);
  	if(timeout>0)Http.setTimeout(builder,TimeSpanImpl.fromMillis(timeout));
  	HttpContext context=setCredentials(builder,hh, username, password,false);
  	setProxy(builder,request,proxy);
  	CloseableHttpClient client = builder.build();
      if(context==null)context = new BasicHttpContext();
      return new HTTPResponse4Impl(url,context,request,client.execute(request,context));
  }
 
開發者ID:lucee,項目名稱:Lucee,代碼行數:23,代碼來源:HTTPEngine4Impl.java

示例8: buildClient

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
private static HttpClient buildClient(final String fedoraUsername,
                                      final String fedoraPassword,
                                      final String repositoryURL) {
    final PoolingClientConnectionManager connMann = new PoolingClientConnectionManager();
    connMann.setMaxTotal(MAX_VALUE);
    connMann.setDefaultMaxPerRoute(MAX_VALUE);

    final DefaultHttpClient httpClient = new DefaultHttpClient(connMann);
    httpClient.setRedirectStrategy(new DefaultRedirectStrategy());
    httpClient.setHttpRequestRetryHandler(new StandardHttpRequestRetryHandler(0, false));

    // If the Fedora instance requires authentication, set it up here
    if (!isBlank(fedoraUsername) && !isBlank(fedoraPassword)) {
        LOGGER.debug("Adding BASIC credentials to client for repo requests.");

        final URI fedoraUri = URI.create(repositoryURL);
        final CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(fedoraUri.getHost(), fedoraUri.getPort()),
                                     new UsernamePasswordCredentials(fedoraUsername, fedoraPassword));

        httpClient.setCredentialsProvider(credsProvider);
    }
    return httpClient;
}
 
開發者ID:fcrepo4-labs,項目名稱:fcrepo4-client,代碼行數:25,代碼來源:HttpHelper.java

示例9: newHttpClient

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
/**
 * Allows you do override the HTTP Client used to execute the requests.
 * By default, it used a custom client without cookies.
 *
 * @return the HTTP Client instance
 */
protected HttpClient newHttpClient() {
    return HttpClients.custom()
            // Do not manage redirection.
            .setRedirectStrategy(new DefaultRedirectStrategy() {
                @Override
                protected boolean isRedirectable(String method) {
                    return followRedirect(method);
                }
            })
            .setDefaultCookieStore(new BasicCookieStore() {
                @Override
                public synchronized List<Cookie> getCookies() {
                    return Collections.emptyList();
                }
            })
            .build();
}
 
開發者ID:wisdom-framework,項目名稱:wisdom,代碼行數:24,代碼來源:ProxyFilter.java

示例10: TracingHttpClientBuilder

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
/**
 * When using this constructor tracer should be registered via
 * {@link GlobalTracer#register(Tracer)}.
 */
public TracingHttpClientBuilder() {
    this(DefaultRedirectStrategy.INSTANCE,
        false,
        GlobalTracer.get(),
        Collections.<ApacheClientSpanDecorator>singletonList(new ApacheClientSpanDecorator.StandardTags()));
}
 
開發者ID:opentracing-contrib,項目名稱:java-apache-httpclient,代碼行數:11,代碼來源:TracingHttpClientBuilder.java

示例11: setUp

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    super.setUp();
    this.clientBuilder = new TracingHttpClientBuilder(DefaultRedirectStrategy.INSTANCE, false, mockTracer,
            Collections.<ApacheClientSpanDecorator>singletonList(new ApacheClientSpanDecorator.StandardTags()));

    this.serverBootstrap.registerHandler(RedirectHandler.MAPPING, new RedirectHandler())
            .registerHandler(PropagationHandler.MAPPING, new PropagationHandler());
    this.serverHost = super.start();
}
 
開發者ID:opentracing-contrib,項目名稱:java-apache-httpclient,代碼行數:11,代碼來源:TracingHttpClientBuilderTest.java

示例12: testDisableRedirectHandling

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
@Test
public void testDisableRedirectHandling() throws URISyntaxException, IOException {
    {
        HttpClient client = new TracingHttpClientBuilder(DefaultRedirectStrategy.INSTANCE, true, mockTracer,
                Collections.<ApacheClientSpanDecorator>singletonList(new ApacheClientSpanDecorator.StandardTags()))
                .build();

        client.execute(new HttpGet(serverUrl(RedirectHandler.MAPPING)));
    }

    List<MockSpan> mockSpans = mockTracer.finishedSpans();
    Assert.assertEquals(2, mockSpans.size());

    MockSpan mockSpan = mockSpans.get(0);
    Assert.assertEquals("GET", mockSpan.operationName());

    Assert.assertEquals(6, mockSpan.tags().size());
    Assert.assertEquals(Tags.SPAN_KIND_CLIENT, mockSpan.tags().get(Tags.SPAN_KIND.getKey()));
    Assert.assertEquals("GET", mockSpan.tags().get(Tags.HTTP_METHOD.getKey()));
    Assert.assertEquals(serverUrl("/redirect"), mockSpan.tags().get(Tags.HTTP_URL.getKey()));
    Assert.assertEquals(301, mockSpan.tags().get(Tags.HTTP_STATUS.getKey()));
    Assert.assertEquals(serverHost.getPort(), mockSpan.tags().get(Tags.PEER_PORT.getKey()));
    Assert.assertEquals(serverHost.getHostName(), mockSpan.tags().get(Tags.PEER_HOSTNAME.getKey()));
    Assert.assertEquals(0, mockSpan.logEntries().size());

    assertLocalSpan(mockSpans.get(1));
}
 
開發者ID:opentracing-contrib,項目名稱:java-apache-httpclient,代碼行數:28,代碼來源:TracingHttpClientBuilderTest.java

示例13: createContainer

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
private static Container createContainer(int uiPort, File testDir) throws Exception {
    File adminFile = new File(testDir, "admin.json");
    Files.asCharSink(adminFile, Charsets.UTF_8).write("{\"web\":{\"port\":" + uiPort + "}}");
    Container container;
    if (Containers.useJavaagent()) {
        container = new JavaagentContainer(testDir, true, ImmutableList.of());
    } else {
        container = new LocalContainer(testDir, true, ImmutableMap.of());
    }
    // wait for UI to be available (UI starts asynchronously in order to not block startup)
    CloseableHttpClient httpClient = HttpClients.custom()
            .setRedirectStrategy(new DefaultRedirectStrategy())
            .build();
    Stopwatch stopwatch = Stopwatch.createStarted();
    Exception lastException = null;
    while (stopwatch.elapsed(SECONDS) < 10) {
        HttpGet request = new HttpGet("http://localhost:" + uiPort);
        try (CloseableHttpResponse response = httpClient.execute(request);
                InputStream content = response.getEntity().getContent()) {
            ByteStreams.exhaust(content);
            lastException = null;
            break;
        } catch (Exception e) {
            lastException = e;
        }
    }
    httpClient.close();
    if (lastException != null) {
        throw new IllegalStateException("Timed out waiting for Glowroot UI", lastException);
    }
    return container;
}
 
開發者ID:glowroot,項目名稱:glowroot,代碼行數:33,代碼來源:WebDriverSetup.java

示例14: buildHttpClient

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
public HttpClientBuilder buildHttpClient() {
    final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    final List<Header> headers = Lists.newArrayList(new BasicHeader("Accept", "*/*"),new BasicHeader("User-Agent", USER_AGENT));
    httpClientBuilder.setDefaultHeaders(headers);
    httpClientBuilder.setRedirectStrategy(new DefaultRedirectStrategy());
    return httpClientBuilder;
}
 
開發者ID:tarjeir,項目名稱:vitus-elasticsearch-webintegration,代碼行數:8,代碼來源:HttpClientFactory.java

示例15: getHttpClient

import org.apache.http.impl.client.DefaultRedirectStrategy; //導入依賴的package包/類
public static DefaultHttpClient getHttpClient() {
    DefaultHttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,5*1000);
    client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, false));
    client.setRedirectStrategy(new DefaultRedirectStrategy());
    return client;
}
 
開發者ID:ThoughtWorksInc,項目名稱:go-plugin-util,代碼行數:8,代碼來源:HttpRepoURL.java


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