本文整理匯總了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());
}
示例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;
}
示例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();
}
示例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));
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}
示例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();
}
示例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()));
}
示例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;
}
示例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;
}
示例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;
}