List of usage examples for javax.servlet.http HttpServletRequest getRemoteAddr
public String getRemoteAddr();
From source file:com.glaf.core.util.RequestUtils.java
/** * ?WebIP?// w ww .j ava2 s .c o m * * @param request * @return */ public static String getIPAddress(HttpServletRequest request) { String ipAddress = null; ipAddress = request.getRemoteAddr(); ipAddress = request.getHeader("x-forwarded-for"); if (StringUtils.isEmpty(ipAddress) || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getHeader("Proxy-Client-IP"); } if (StringUtils.isEmpty(ipAddress) || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getHeader("WL-Proxy-Client-IP"); } if (StringUtils.isEmpty(ipAddress) || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getRemoteAddr(); } if (ipAddress != null && ipAddress.length() > 15) { if (ipAddress.indexOf(",") > 0) { ipAddress = ipAddress.substring(0, ipAddress.indexOf(",")); } } return ipAddress; }
From source file:com.livgrhm.kansas.resources.UserResource.java
@GET @Path("/{userId}") @Timed/*from w w w. ja va2s . com*/ public Response getUserById(@PathParam("userId") int userId, @QueryParam("auth") String auth, @Context HttpServletRequest req) { if (!authMap.isAuthorised(auth, req.getRemoteAddr())) { System.out.println("getUserById Unauthorised " + userId + " " + auth); SimpleResponse resp = new SimpleResponse(401, "Unauthorized", "Authorization is required."); return Response.status(Response.Status.UNAUTHORIZED).entity(resp).build(); } try { User u = this.dao.getUserById(userId); System.out.println("USER CREATED: " + u.getDatetimeCreated()); System.out.println("USER UPDATED: " + u.getDatetimeUpdated()); if (u != null) { return Response.ok(u).build(); } return Response.status(Response.Status.NOT_FOUND).build(); } catch (Exception e) { System.out.println("Exception getting user by ID: " + e.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }
From source file:cherry.foundation.springmvc.OperationLogHandlerInterceptor.java
private StringBuilder createBasicInfo(HttpServletRequest request) { StringBuilder builder = new StringBuilder(); return builder.append(request.getRemoteAddr()).append(" ").append(request.getMethod()).append(" ") .append(request.getRequestURI()); }
From source file:cz.muni.fi.webmias.ProcessServlet.java
private void logQuery(HttpServletRequest request, String query) { String logMessage = "Searching query from IP:" + request.getRemoteAddr() + ":\n" + query; LOG.log(Level.INFO, logMessage); try {/*from w ww . j a v a2 s. c om*/ try (BufferedWriter out = new BufferedWriter( new FileWriterWithEncoding(queryLog, StandardCharsets.UTF_8, true))) { String log = new Date().toString() + "\n" + logMessage + "\n\n"; out.write(log); } } catch (IOException e) { LOG.log(Level.SEVERE, "Cannot write to query logging file in {0}", queryLog.getAbsolutePath()); } }
From source file:nl.ctrlaltdev.harbinger.evidence.Evidence.java
public Evidence(Evidence src, HttpServletRequest req) { this(src);/* ww w . ja v a2 s . c om*/ this.ip = req.getRemoteAddr(); this.forwardedFor = req.getHeader("X-Forwarded-For"); HttpSession session = req.getSession(false); this.session = session == null ? null : session.getId(); this.url = req.getRequestURI(); }
From source file:org.italiangrid.storm.webdav.server.LogRequestFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { chain.doFilter(request, response);/*from ww w .j a v a 2 s .c o m*/ SecurityContext ctxt = SecurityContextHolder.getContext(); HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; String resMsg = String.format("%s %s %s %d [user:<%s>, authorities:<%s>]", req.getRemoteAddr(), req.getMethod(), req.getRequestURI(), res.getStatus(), ctxt.getAuthentication().getName(), ctxt.getAuthentication().getAuthorities()); log.info(resMsg); }
From source file:com.wmanual.web.controller.ManualHomeController.java
@RequestMapping("/types/{name}") public String types(HttpServletRequest request, @PathVariable("name") String name) throws Exception { logger.info("[{}] visit wmanual for {} page", request.getRemoteAddr(), "index"); return "types/" + name; }
From source file:com.wmanual.web.controller.ManualHomeController.java
@RequestMapping("/brands/{name}") public String brands(HttpServletRequest request, @PathVariable("name") String name) throws Exception { logger.info("[{}] visit wmanual for {} page", request.getRemoteAddr(), "index"); return "brands/" + name; }
From source file:com.ecyrd.jspwiki.filters.SpamFilter.java
/** * This method is used to calculate an unique code when submitting the page * to detect edit conflicts. It currently incorporates the last-modified * date of the page, and the IP address of the submitter. * * @param page The WikiPage under edit/* www .j a v a 2 s . co m*/ * @param request The HTTP Request * @since 2.6 * @return A hash value for this page and session */ public static final String getSpamHash(WikiPage page, HttpServletRequest request) { long lastModified = 0; if (page.getLastModified() != null) lastModified = page.getLastModified().getTime(); long remote = request.getRemoteAddr().hashCode(); return Long.toString(lastModified ^ remote); }
From source file:com.mirth.connect.server.servlets.MirthServlet.java
protected String getRequestIpAddress(HttpServletRequest request) { String address = request.getHeader("x-forwarded-for"); if (address == null) { address = request.getRemoteAddr(); }//from w w w. j a v a2 s . co m return address; }