Use Shifter with Java
Wire Shifter's residential and ISP proxies into Java applications in minutes. Works with the built-in HttpClient (Java 11+), OkHttp, Apache HttpClient, Selenium, and Jsoup — no SDK required.
Quick Start
Install
// Maven
// <dependency><groupId>com.squareup.okhttp3</groupId><artifactId>okhttp</artifactId><version>4.12.0</version></dependency> Basic Usage
import java.net.*;
import java.net.http.*;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Quickstart {
public static void main(String[] args) throws Exception {
Authenticator auth = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
"customer-USERNAME-country-us-sid-123ABC",
"PASSWORD".toCharArray());
}
};
HttpClient client = HttpClient.newBuilder()
.proxy(ProxySelector.of(new InetSocketAddress("p.shifter.io", 443)))
.authenticator(auth)
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://ipinfo.io/json"))
.GET()
.build();
HttpResponse<String> response =
client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
} Features
Examples
Built-in HttpClient (Java 11+)
The standard library since Java 11 — no third-party dependencies. Configure the proxy via ProxySelector and credentials via Authenticator. Same client is safe to share across threads.
import java.net.*;
import java.net.http.*;
import java.time.Duration;
public class HttpClientExample {
static final String PROXY_HOST = "p.shifter.io";
static final int PROXY_PORT = 443;
static HttpClient client(String country, String sid) {
Authenticator auth = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
String.format("customer-USERNAME-country-%s-sid-%s-ttl-300", country, sid),
"PASSWORD".toCharArray());
}
};
return HttpClient.newBuilder()
.proxy(ProxySelector.of(new InetSocketAddress(PROXY_HOST, PROXY_PORT)))
.authenticator(auth)
.connectTimeout(Duration.ofSeconds(10))
.build();
}
public static void main(String[] args) throws Exception {
HttpClient c = client("uk", "456DEF");
for (String path : new String[]{"/login", "/dashboard", "/orders"}) {
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create("https://example.co.uk" + path))
.header("User-Agent", "Mozilla/5.0 (Windows) AppleWebKit/537.36")
.timeout(Duration.ofSeconds(30))
.GET()
.build();
HttpResponse<String> r = c.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println(path + " " + r.statusCode() + " " + r.body().length());
}
}
} OkHttp
OkHttp is the most popular HTTP client in Java. Configure the proxy and credentials on the client builder — same client can be reused safely across threads and multiplexes connections.
import okhttp3.*;
import java.net.InetSocketAddress;
import java.net.Proxy;
public class OkHttpExample {
public static void main(String[] args) throws Exception {
Proxy proxy = new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("p.shifter.io", 443));
Authenticator proxyAuth = (route, response) -> {
String credential = Credentials.basic(
"customer-USERNAME-country-de-city-berlin-sid-789GHI", "PASSWORD");
return response.request().newBuilder()
.header("Proxy-Authorization", credential)
.build();
};
OkHttpClient client = new OkHttpClient.Builder()
.proxy(proxy)
.proxyAuthenticator(proxyAuth)
.build();
Request request = new Request.Builder()
.url("https://api.example.de/products")
.header("User-Agent", "Mozilla/5.0 (Linux) AppleWebKit/537.36")
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.code() + " " + response.body().string().length());
}
}
} Selenium WebDriver
Drive a real Chrome / Firefox instance through Shifter for JavaScript-rendered targets. Use selenium-wire (or a Chrome extension) to handle proxy authentication.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.Proxy;
public class SeleniumExample {
public static void main(String[] args) {
Proxy proxy = new Proxy();
proxy.setHttpProxy("p.shifter.io:443");
proxy.setSslProxy("p.shifter.io:443");
ChromeOptions options = new ChromeOptions();
options.setProxy(proxy);
options.addArguments("--headless=new");
options.addArguments(
"--user-agent=Mozilla/5.0 (Macintosh) AppleWebKit/537.36"
);
// For username-password proxy auth, pair this with Shifter's IP
// whitelist or use selenium-wire — Chrome ignores credentials in
// headless mode without a sidecar extension.
WebDriver driver = new ChromeDriver(options);
try {
driver.get("https://example.com");
System.out.println(driver.getTitle());
System.out.println(driver.getPageSource().length() + " bytes");
} finally {
driver.quit();
}
}
} Spring Boot RestTemplate / WebClient
Wrap Shifter in a Spring @Configuration so every RestTemplate or WebClient your app injects routes through the proxy. Works with Spring 5+ and Spring Boot 3.
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.client5.http.auth.*;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@Configuration
public class ShifterRestConfig {
@Bean
public RestTemplate shifterRestTemplate() {
HttpHost proxy = new HttpHost("http", "p.shifter.io", 443);
BasicCredentialsProvider creds = new BasicCredentialsProvider();
creds.setCredentials(
new AuthScope(proxy),
new UsernamePasswordCredentials(
"customer-USERNAME-country-fr-sid-ABC123",
"PASSWORD".toCharArray()));
CloseableHttpClient httpClient = HttpClients.custom()
.setProxy(proxy)
.setDefaultCredentialsProvider(creds)
.setDefaultRequestConfig(RequestConfig.custom().build())
.build();
HttpComponentsClientHttpRequestFactory factory =
new HttpComponentsClientHttpRequestFactory(httpClient);
return new RestTemplate(factory);
}
} Frequently asked questions
Common questions about using Shifter with Java.
Pass ProxySelector.of(new InetSocketAddress("p.shifter.io", 443)) to HttpClient.newBuilder().proxy(...) and supply credentials via an Authenticator that returns PasswordAuthentication for getPasswordAuthentication. Standard library only — no extra dependencies.
Set the proxy on OkHttpClient.Builder() with new Proxy(Proxy.Type.HTTP, address) and provide a proxyAuthenticator that adds a Proxy-Authorization header using Credentials.basic(user, pass). The same client can safely be reused across threads.
Yes. Set HTTP and SSL proxy host on a Selenium Proxy object, attach it to ChromeOptions, and launch ChromeDriver. For username-password auth in headless mode, pair with Shifter's IP whitelist or use selenium-wire — Chrome doesn't natively prompt for proxy credentials.
Add a session ID to the proxy username — for example `customer-USERNAME-country-us-sid-123ABC`. Every request that authenticates with the same sid will reuse the same residential IP. Add `ttl-N` to pin that IP for up to N seconds.
Yes. Configure a RestTemplate or WebClient @Bean that wraps an Apache HttpClient or Reactor Netty client with Shifter as the proxy. Inject that bean wherever you need to call external APIs — works with Spring Framework 5+ and Spring Boot 3.
No SDK is required. Shifter speaks plain HTTP / SOCKS5 — point your existing client at `p.shifter.io:443`. This keeps your pom.xml or build.gradle lean and works with Java 8 through Java 21.
Start Using Shifter with Java
Add Shifter's 205M+ residential and ISP proxies to your JVM stack in under 5 minutes. Works with HttpClient, OkHttp, Spring, and Selenium WebDriver.