*
* @return The client-specific information.
*/
@Override
public ClientInfo getClientInfo() {
final ClientInfo result = super.getClientInfo();
if (!this.clientAdded) {
// Extract the header values
final String acceptCharset = getHttpCall().getRequestHeaders()
.getValues(HttpConstants.HEADER_ACCEPT_CHARSET);
final String acceptEncoding = getHttpCall().getRequestHeaders()
.getValues(HttpConstants.HEADER_ACCEPT_ENCODING);
final String acceptLanguage = getHttpCall().getRequestHeaders()
.getValues(HttpConstants.HEADER_ACCEPT_LANGUAGE);
final 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());
if (this.context != null) {
// Special handling for the non standard but common
// "X-Forwarded-For" header.
final 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.
final String header = getHttpCall().getRequestHeaders()
.getValues(HttpConstants.HEADER_X_FORWARDED_FOR);
if (header != null) {
final String[] addresses = header.split(",");
for (int i = addresses.length - 1; i >= 0; i--) {
result.getAddresses().add(addresses[i].trim());
}
}
}
}