try { if(request.getCharacterEncoding()==null) request.setCharacterEncoding(Constants.DEFAULT_ENCODING); } catch(Exception e) { log.error("Unable to set encoding to UTF-8.", e); }
    public static Context obtainContext(HttpServletRequest request)            throws SQLException    {        Context c = (Context) request.getAttribute("dspace.context");        if (c == null)        {            // No context for this request yet            c = new Context();            // See if a user has authentication            HttpSession session = request.getSession();            Integer userID = (Integer) session.getAttribute(                    "dspace.current.user.id");            if (userID != null)            {                String remAddr = (String)session.getAttribute("dspace.current.remote.addr");                if (remAddr != null && remAddr.equals(request.getRemoteAddr()))                {                EPerson e = EPerson.find(c, userID.intValue());                Authenticate.loggedIn(c, request, e);            }                else                {                    log.warn("POSSIBLE HIJACKED SESSION: request from "+                             request.getRemoteAddr()+" does not match original "+                             "session address: "+remAddr+". Authentication rejected.");                }            }            // Set any special groups - invoke the authentication mgr.            int[] groupIDs = AuthenticationManager.getSpecialGroups(c, request);            for (int i = 0; i < groupIDs.length; i++)            {                c.setSpecialGroup(groupIDs[i]);                log.debug("Adding Special Group id="+String.valueOf(groupIDs[i]));            }            // Set the session ID and IP address            c.setExtraLogInfo("session_id=" + request.getSession().getId() + ":ip_addr=" + request.getRemoteAddr());            // Store the context in the request            request.setAttribute("dspace.context", c);        }        return c;    }