Hi,
I am trying to implement a logger in my seam 1.2 + Icefaces 1.5.3 app. I would like to log the browser type that is accessing the site.
Code:
HttpServletRequest request = (HttpServletRequest)facesContext.getExternalContext().getRequest();
String ip = request.getRemoteAddr();
String browserType = ((HttpServletRequest)request).getHeader("user-agent");
This throws a nullpointer exception from com.icesoft.faces.env.ServletEnvironmentRequest..
Looking at the code from ServletEnvironmentRequest I noticed that the headers are initialized but then are set to null:
Code:
[b]headers = new Hashtable();
items = req.getHeaderNames();
name = null;
while (items.hasMoreElements()) {
name = (String) items.nextElement();
headers.put(name, req.getHeaders(name));
}[/b]
parameters = new Hashtable();
items = req.getParameterNames();
while (items.hasMoreElements()) {
name = (String) items.nextElement();
attributes.put(name, req.getParameterValues(name));
}
scheme = req.getScheme();
serverName = req.getServerName();
serverPort = req.getServerPort();
locale = req.getLocale();
locales = new Vector();
items = req.getLocales();
while (items.hasMoreElements()) {
locales.add(items.nextElement());
}
isSecure = req.isSecure();
//Copy servlet specific data
[b] headers = null;[/b]
I tried removing the headers=null; part but then I get nullpointer exceptions from
Code:
public String getHeader(String name) {
Enumeration allProps = (Enumeration) headers.get(name);
if (allProps.hasMoreElements()) {
return (String) allProps.nextElement();
}
return null;
}
Maybe I am doing something wrong, or is it a problem with the ServletEnvironmentRequest implementation?
thanks,
Dustin