* Returns the client-specific information.
*
* @return The client-specific information.
*/
public ClientInfo getClientInfo() {
ClientInfo result = super.getClientInfo();
if (!this.clientAdded) {
// Extract the header values
String acceptCharset = getHttpCall().getRequestHeaders().getValues(
HttpConstants.HEADER_ACCEPT_CHARSET);
String acceptEncoding = getHttpCall().getRequestHeaders()
.getValues(HttpConstants.HEADER_ACCEPT_ENCODING);
String acceptLanguage = getHttpCall().getRequestHeaders()
.getValues(HttpConstants.HEADER_ACCEPT_LANGUAGE);
String acceptMediaType = getHttpCall().getRequestHeaders()
.getValues(HttpConstants.HEADER_ACCEPT);
// Parse the headers and update the call preferences
// Parse the Accept* headers. If an error occurs during the parsing
// of each header, the error is traced and we keep on with the other
// headers.
try {
PreferenceUtils.parseCharacterSets(acceptCharset, result);
} catch (Exception e) {
this.context.getLogger().log(Level.INFO, e.getMessage());
}
try {
PreferenceUtils.parseEncodings(acceptEncoding, result);
} catch (Exception e) {
this.context.getLogger().log(Level.INFO, e.getMessage());
}
try {
PreferenceUtils.parseLanguages(acceptLanguage, result);
} catch (Exception e) {
this.context.getLogger().log(Level.INFO, e.getMessage());
}
try {
PreferenceUtils.parseMediaTypes(acceptMediaType, result);
} catch (Exception e) {
this.context.getLogger().log(Level.INFO, e.getMessage());
}
// Set other properties
result.setAgent(getHttpCall().getRequestHeaders().getValues(
HttpConstants.HEADER_USER_AGENT));
result.setAddress(getHttpCall().getClientAddress());
result.setPort(getHttpCall().getClientPort());
// Special handling for the non standard but common
// "X-Forwarded-For" header.
boolean useForwardedForHeader = Boolean.parseBoolean(this.context
.getParameters().getFirstValue("useForwardedForHeader",
false));
if (useForwardedForHeader) {
// Lookup the "X-Forwarded-For" header supported by popular
// proxies and caches.
// This information is only safe for intermediary components
// within your local network.
// Other addresses could easily be changed by setting a fake
// header and should not be trusted for serious security checks.
String header = getHttpCall().getRequestHeaders().getValues(
HttpConstants.HEADER_X_FORWARDED_FOR);
if (header != null) {
String[] addresses = header.split(",");
for (int i = addresses.length - 1; i >= 0; i--) {
result.getAddresses().add(addresses[i].trim());
}
}
}
this.clientAdded = true;