@@ -17,7 +17,7 @@ To do this, add the dependency to your pom.xml:
1717 <dependency >
1818 <groupId >com.maxmind.geoip2</groupId >
1919 <artifactId >geoip2</artifactId >
20- <version >4.3.1 </version >
20+ <version >4.3.2 </version >
2121 </dependency >
2222```
2323
@@ -30,7 +30,7 @@ repositories {
3030 mavenCentral()
3131}
3232dependencies {
33- compile 'com.maxmind.geoip2:geoip2:4.3.1 '
33+ compile 'com.maxmind.geoip2:geoip2:4.3.2 '
3434}
3535```
3636
@@ -72,6 +72,187 @@ are not created for each request.
7272See the [ API documentation] ( https://maxmind.github.io/GeoIP2-java/ ) for
7373more details.
7474
75+ ## HTTP Protocol Configuration ##
76+
77+ The ` WebServiceClient ` provides extensive HTTP protocol configuration options
78+ through the ` WebServiceClient.Builder ` :
79+
80+ ### HTTP Version ###
81+
82+ You can specify the HTTP protocol version to use:
83+
84+ ``` java
85+ import java.net.http.HttpClient ;
86+
87+ // Force HTTP/1.1
88+ WebServiceClient client = new WebServiceClient .Builder (42 , " license_key" )
89+ .httpVersion(HttpClient . Version . HTTP_1_1 )
90+ .build();
91+
92+ // Force HTTP/2
93+ WebServiceClient client = new WebServiceClient .Builder (42 , " license_key" )
94+ .httpVersion(HttpClient . Version . HTTP_2 )
95+ .build();
96+
97+ // Default behavior: prefer HTTP/2 but negotiate down to HTTP/1.1 if needed
98+ WebServiceClient client = new WebServiceClient .Builder (42 , " license_key" )
99+ .build();
100+ ```
101+
102+ ### HTTPS/HTTP Protocol ###
103+
104+ By default, the client uses HTTPS. You can disable HTTPS for testing or proxy scenarios:
105+
106+ ``` java
107+ // Disable HTTPS (use HTTP instead)
108+ WebServiceClient client = new WebServiceClient .Builder (42 , " license_key" )
109+ .disableHttps()
110+ .build();
111+ ```
112+
113+ ** Note:** The minFraud Score and Insights web services require HTTPS.
114+
115+ ### Timeouts ###
116+
117+ Configure connection and request timeouts:
118+
119+ ``` java
120+ import java.time.Duration ;
121+
122+ WebServiceClient client = new WebServiceClient .Builder (42 , " license_key" )
123+ .connectTimeout(Duration . ofSeconds(5 )) // Connection timeout (default: 3 seconds)
124+ .requestTimeout(Duration . ofSeconds(30 )) // Request timeout (default: 20 seconds)
125+ .build();
126+ ```
127+
128+ ### Proxy Configuration ###
129+
130+ Configure HTTP proxy settings:
131+
132+ ``` java
133+ import java.net.InetSocketAddress ;
134+ import java.net.ProxySelector ;
135+
136+ // Using ProxySelector (recommended)
137+ ProxySelector proxy = ProxySelector . of(new InetSocketAddress (" proxy.example.com" , 8080 ));
138+ WebServiceClient client = new WebServiceClient .Builder (42 , " license_key" )
139+ .proxy(proxy)
140+ .build();
141+
142+ // Using system default proxy
143+ WebServiceClient client = new WebServiceClient .Builder (42 , " license_key" )
144+ .proxy(ProxySelector . getDefault())
145+ .build();
146+ ```
147+
148+ ### Custom Host and Port ###
149+
150+ Configure custom host and port:
151+
152+ ``` java
153+ WebServiceClient client = new WebServiceClient .Builder (42 , " license_key" )
154+ .host(" custom.geoip.server.com" )
155+ .port(8443 )
156+ .build();
157+ ```
158+
159+ ### Complete HTTP Configuration Example ###
160+
161+ ``` java
162+ import java.net.InetSocketAddress ;
163+ import java.net.ProxySelector ;
164+ import java.net.http.HttpClient ;
165+ import java.time.Duration ;
166+ import java.util.Arrays ;
167+
168+ WebServiceClient client = new WebServiceClient .Builder (42 , " license_key" )
169+ .host(" geoip.maxmind.com" )
170+ .port(443 )
171+ .httpVersion(HttpClient . Version . HTTP_2 )
172+ .connectTimeout(Duration . ofSeconds(5 ))
173+ .requestTimeout(Duration . ofSeconds(30 ))
174+ .proxy(ProxySelector . of(new InetSocketAddress (" proxy.example.com" , 8080 )))
175+ .locales(Arrays . asList(" en" , " fr" , " es" ))
176+ .build();
177+ ```
178+
179+ ### HTTP Headers ###
180+
181+ The client automatically sets the following HTTP headers:
182+ - ` Accept: application/json `
183+ - ` Authorization: Basic <base64-encoded-credentials> `
184+ - ` User-Agent: GeoIP2/<version> (Java/<java-version>) `
185+
186+ ### HTTP Error Handling ###
187+
188+ The client handles various HTTP status codes:
189+ - ** 200** : Success - response is parsed and returned
190+ - ** 4xx** : Client errors - throws specific exceptions like ` AddressNotFoundException ` , ` AuthenticationException ` , etc.
191+ - ** 5xx** : Server errors - throws ` HttpException `
192+ - ** Other status codes** : Throws ` HttpException `
193+
194+ HTTP transport errors (network issues, timeouts, etc.) are thrown as ` HttpException ` , which extends ` IOException ` .
195+
196+ ### HTTP Client Implementation ###
197+
198+ The GeoIP2 Java library uses Java's built-in ` java.net.http.HttpClient ` (available since Java 11) for HTTP communication. This provides:
199+
200+ - ** Connection pooling** : Connections are automatically reused across requests
201+ - ** HTTP/2 support** : Modern HTTP/2 protocol with fallback to HTTP/1.1
202+ - ** Asynchronous capabilities** : Though the GeoIP2 client uses synchronous calls
203+ - ** Built-in proxy support** : System proxy settings are respected by default
204+ - ** TLS/SSL support** : Secure HTTPS connections with modern cipher suites
205+
206+ ### Authentication ###
207+
208+ The client uses HTTP Basic Authentication with your MaxMind account credentials:
209+
210+ - Credentials are Base64-encoded and sent in the ` Authorization ` header
211+ - Authentication is sent with every request (no challenge-response)
212+ - Credentials are never logged or exposed in error messages
213+
214+ ### Connection Management ###
215+
216+ - ** Thread-safe** : The ` WebServiceClient ` can be safely shared across multiple threads
217+ - ** Connection reuse** : The underlying HTTP client maintains a connection pool
218+ - ** Resource cleanup** : The client automatically manages connection lifecycle
219+ - ** No explicit cleanup needed** : The ` close() ` method is deprecated and no longer required
220+
221+ ### HTTP API Endpoints ###
222+
223+ The client makes HTTP GET requests to the following endpoint pattern:
224+ ```
225+ https://geoip.maxmind.com/geoip/v2.1/{service}/{ip_address}
226+ ```
227+
228+ Where:
229+ - ` {service} ` is one of: ` country ` , ` city ` , ` insights `
230+ - ` {ip_address} ` is the IP address to look up, or ` me ` for the client's IP
231+
232+ Examples:
233+ - ` https://geoip.maxmind.com/geoip/v2.1/country/128.101.101.101 `
234+ - ` https://geoip.maxmind.com/geoip/v2.1/city/me `
235+ - ` https://geolite.info/geoip/v2.1/country/192.168.1.1 ` (GeoLite2)
236+ - ` https://sandbox.maxmind.com/geoip/v2.1/insights/8.8.8.8 ` (Sandbox)
237+
238+ ### Request Format ###
239+
240+ All requests are HTTP GET requests with:
241+ - ** Method** : GET
242+ - ** Content-Type** : Not applicable (no request body)
243+ - ** Accept** : ` application/json `
244+ - ** Authorization** : ` Basic <base64-credentials> `
245+ - ** User-Agent** : ` GeoIP2/<version> (Java/<java-version>) `
246+
247+ ### Response Format ###
248+
249+ All successful responses return JSON with HTTP 200 status. The JSON structure varies by service but typically includes:
250+ - IP address information
251+ - Geographic location data (country, city, subdivisions)
252+ - ISP and organization data
253+ - Confidence scores (for paid services)
254+ - Additional metadata
255+
75256## Web Service Example ##
76257
77258### Country Service ###
0 commit comments