Created
May 26, 2016 17:43
-
-
Save ankushs92/26fe78553478a5c8d6d6a58d7c4c494f to your computer and use it in GitHub Desktop.
Some helper methods for HttpServletRequest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HttpServletRequestUtils { | |
public static String getIp(final HttpServletRequest request) { | |
PreConditions.checkNull(request, "request cannot be null"); | |
String ip = request.getHeader("X-FORWARDED-FOR"); | |
if (ip==null || ip.trim().length()==0)) { | |
ip = request.getRemoteAddr(); | |
} | |
return ip; | |
} | |
public static Integer getErrorCode(final HttpServletRequest request){ | |
PreConditions.checkNull(request, "request cannot be null"); | |
return (Integer) request.getAttribute("javax.servlet.error.status_code"); | |
} | |
public static Throwable getThrowable(final HttpServletRequest request){ | |
PreConditions.checkNull(request, "request cannot be null"); | |
return (Throwable)request.getAttribute("javax.servlet.error.exception"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment