java.net.http.HttpClient.Redirect Java Examples

The following examples show how to use java.net.http.HttpClient.Redirect. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaRequestProcessor.java    From milkman with MIT License 5 votes vote down vote up
@SneakyThrows
	private HttpClient buildClient() {
		Builder builder = HttpClient.newBuilder();
		if (!HttpOptionsPluginProvider.options().isHttp2Support()){
			builder.version(Version.HTTP_1_1);
		}

		if (HttpOptionsPluginProvider.options().isUseProxy()) {
			URL url = new URL(HttpOptionsPluginProvider.options().getProxyUrl());
			builder.proxy(new ProxyExclusionRoutePlanner(url, HttpOptionsPluginProvider.options().getProxyExclusion()).java());
			
			//we dont use Authenticator because it might result in an exception if there is a 401 response
			// see https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.net.http/share/classes/jdk/internal/net/http/AuthenticationFilter.java#L263
			//we manually add Proxy-Authorization header instead
//			if (proxyCredentials != null) {
//				builder.authenticator(new Authenticator() {
//					@Override
//					protected PasswordAuthentication getPasswordAuthentication() {
//						return proxyCredentials;
//					}
//				});
//			}
		}

		if (!HttpOptionsPluginProvider.options().isCertificateValidation()) {
			disableSsl(builder);
		}
		
		if (HttpOptionsPluginProvider.options().isFollowRedirects()) {
			builder.followRedirects(Redirect.ALWAYS);
		}

		setupSslLegacyProtocolSupport(builder);

		return builder
				.build();
	}
 
Example #2
Source File: OreKitDataClient.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
public OreKitDataClient(List<String> urls) {
	if (urls == null || urls.isEmpty()) {
		throw new IllegalArgumentException("urls are blank. at least 1 is expected");
	}
	this.urls = urls;
	this.httpclient = HttpClient.newBuilder().version(Version.HTTP_2).followRedirects(Redirect.NORMAL).connectTimeout(Duration.ofMillis(TIMEOUT)).build();
}
 
Example #3
Source File: RestClient.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
public RestClient(String baseUrl) throws Exception {
	if (baseUrl == null) {
		this.baseUrl = "http://localhost:8097";
	} else {
		this.baseUrl = baseUrl;
	}
	this.httpclient = HttpClient.newBuilder().version(Version.HTTP_2).followRedirects(Redirect.NORMAL).connectTimeout(Duration.ofMinutes(1L)).build();
}
 
Example #4
Source File: R2ServerClient.java    From r2cloud with Apache License 2.0 4 votes vote down vote up
public R2ServerClient(Configuration config) {
	this.config = config;
	this.hostname = config.getProperty("r2server.hostname");
	this.httpclient = HttpClient.newBuilder().version(Version.HTTP_2).followRedirects(Redirect.NORMAL).connectTimeout(Duration.ofMillis(config.getInteger("r2server.connectionTimeout"))).build();
}
 
Example #5
Source File: NoIpClient.java    From r2cloud with Apache License 2.0 4 votes vote down vote up
public NoIpClient(String hostname, String username, String password) {
	this.hostname = hostname;
	this.username = username;
	this.password = password;
	this.httpclient = HttpClient.newBuilder().version(Version.HTTP_2).followRedirects(Redirect.NORMAL).connectTimeout(Duration.ofMinutes(1L)).build();
}
 
Example #6
Source File: ExternalIpClient.java    From r2cloud with Apache License 2.0 4 votes vote down vote up
public ExternalIpClient(String host) {
	this.host = host;
	this.httpclient = HttpClient.newBuilder().version(Version.HTTP_2).followRedirects(Redirect.NORMAL).connectTimeout(Duration.ofMinutes(1L)).build();
}
 
Example #7
Source File: Http2Client.java    From feign with Apache License 2.0 4 votes vote down vote up
public Http2Client() {
  this(HttpClient.newBuilder()
      .followRedirects(Redirect.ALWAYS)
      .version(Version.HTTP_2)
      .build());
}