List of usage examples for javax.servlet.http HttpServletRequest getRemoteAddr
public String getRemoteAddr();
From source file:net.siegmar.japtproxy.JaptProxyServlet.java
/** * Check the requested data and forward the request to internal sender. * * @param req the HttpServletRequest object * @param res the HttpServletResponse object * @throws ServletException {@inheritDoc} * @throws IOException {@inheritDoc} *//*from w ww . j a v a 2 s. c o m*/ @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException { res.setBufferSize(Util.DEFAULT_BUFFER_SIZE); MDC.put("REQUEST_ID", DigestUtils.md5Hex(Long.toString(System.currentTimeMillis()))); LOG.debug("Incoming request from IP '{}', " + "User-Agent '{}'", req.getRemoteAddr(), req.getHeader(HttpHeaderConstants.USER_AGENT)); if (LOG.isDebugEnabled()) { logHeader(req); } try { japtProxy.handleRequest(req, res); } catch (final InvalidRequestException e) { LOG.warn(e.getMessage()); res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request"); return; } catch (final UnknownBackendException e) { LOG.info(e.getMessage()); res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unknown backend"); return; } catch (final ResourceUnavailableException e) { LOG.debug(e.getMessage(), e); res.sendError(HttpServletResponse.SC_NOT_FOUND); return; } catch (final HandlingException e) { LOG.error("HandlingException", e); res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } finally { MDC.clear(); } res.flushBuffer(); }
From source file:net.navasoft.madcoin.backend.services.controller.SessionController.java
/** * Signup.// ww w .ja v a 2 s.c o m * * @param request * the request * @param fromSystem * the from system * @param fromToken * the from token * @param userAgent * the user agent * @param signer * the signer * @return the success response vo * @since 18/08/2014, 08:00:20 PM */ @RequestMapping(value = { newUser }, method = { RequestMethod.PUT, RequestMethod.POST }) @ResponseStatus(value = HttpStatus.OK) public @ResponseBody SuccessResponseVO signup(HttpServletRequest request, @RequestHeader("X-Origin-OS") String fromSystem, @RequestHeader("X-Origin-Token") String fromToken, @RequestHeader("User-Agent") String userAgent, @RequestBody(required = true) AppSignupSuccessRequestVO signer) { String ipAddress = request.getRemoteAddr(); System.out.println(request.getRemoteAddr() + "/" + request.getRemoteHost()); signer.setIpAddress(ipAddress); signer.setGadget(userAgent); signer.setOs(fromSystem); signer.setSerial(fromToken); signer.setVersion(userAgent); return service.signUpUser(buildWrapper(signer)); }
From source file:com.github.wnameless.spring.papertrail.PaperTrailService.java
@Transactional @SuppressWarnings({ "unchecked", "deprecation" }) public void audit(HttpServletRequest request, HttpServletResponse response) { if (!targetMethods.contains(HttpMethod.valueOf(request.getMethod()))) return;//from w w w.j a va 2 s . com final PaperTrail paperTrail = newPaperTrail(); paperTrail.setUserId(userIdStrategy == null ? getUserTypedId(request) : userIdStrategy.getUserId(request)); paperTrail.setRemoteAddr(request.getRemoteAddr()); paperTrail.setHttpMethod(HttpMethod.valueOf(request.getMethod())); paperTrail.setRequestUri(request.getRequestURI()); paperTrail.setHttpStatus(response.getStatus()); // Before callbacks if (beforeCallback != null) { beforeCallback.beforePaperTrail(paperTrail, request, response); } // Around callback if (aroundCallback != null) { aroundCallback.aroundPaperTrail(paperTrailRepo, paperTrail, request, response); } else { paperTrailRepo.save(paperTrail); } // After callbacks if (afterCallback != null) { afterCallback.afterPaperTrail(paperTrail, request, response); } // Legacy after callbacks if (!callbacks.isEmpty()) { for (@SuppressWarnings("rawtypes") PaperTrailCallback callback : callbacks.values()) { callback.doWithPaperTrail(paperTrail, request, response); } } }
From source file:com.music.web.MusicController.java
@RequestMapping("/music/evaluate/{id}") @ResponseBody//from www . ja va 2s . c o m public void evaluate(@PathVariable long id, @RequestParam boolean positive, HttpServletRequest request) throws IOException { Long userId = null; if (userContext.getUser() != null) { userId = userContext.getUser().getId(); } pieceService.evaluate(id, userId, positive, request.getRemoteAddr()); }
From source file:com.taobao.diamond.server.controller.BaseStoneController.java
private String getRemoteIp(HttpServletRequest request) { String remoteIp = request.getHeader("X-Real-IP"); if (remoteIp == null || remoteIp.isEmpty()) { remoteIp = request.getRemoteAddr(); }/* w w w .j av a 2s.c om*/ return remoteIp; }
From source file:cc.unlimitedbladeworks.web.home.module.screen.Index.java
public String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); }//from w w w .j a va 2s . c o m if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; }
From source file:com.trendmicro.hdfs.webdav.HDFSWebDAVServlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (LOG.isDebugEnabled()) { LOG.debug(request.getMethod() + " for '" + request.getRequestURI() + "' from " + request.getRemoteUser() + " at " + request.getRemoteAddr()); }//from ww w.j a va2 s . co m try { super.service(request, response); } catch (Exception e) { if (e instanceof AccessControlException || e.getCause() instanceof AccessControlException) { LOG.info("Insufficient permissions for request for '" + request.getRequestURI() + "' from " + request.getRemoteUser() + " at " + request.getRemoteAddr()); if (request.getMethod().equalsIgnoreCase("GET")) { // Provide a plain 401 response for GETs new WebdavResponseImpl(response).sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { // Otherwise send a multistatus response MultiStatus ms = new MultiStatus(); ms.addResponse(new MultiStatusResponse(request.getRequestURL().toString(), 401, "You do not have permission to access this resource.")); new WebdavResponseImpl(response).sendMultiStatus(ms); } } else { LOG.warn("Exception processing request for '" + request.getRequestURI() + "' from " + request.getRemoteUser() + " at " + request.getRemoteAddr() + " authType " + request.getAuthType(), e); new WebdavResponseImpl(response).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } }
From source file:nl.surfnet.coin.shared.log.ApiCallLogContextListener.java
@Override public void requestInitialized(ServletRequestEvent requestEvent) { ApiCallLog apiCallLog = new ApiCallLog(); HttpServletRequest request = (HttpServletRequest) requestEvent.getServletRequest(); String queryString = request.getQueryString(); StringBuffer requestURL = request.getRequestURL(); if (StringUtils.hasText(queryString)) { requestURL.append("?").append(queryString); }//from w w w .j a va2 s . co m try { apiCallLog.setResourceUrl(URLEncoder.encode(requestURL.toString(), "utf-8")); apiCallLog.setIpAddress(request.getRemoteAddr()); } catch (UnsupportedEncodingException e) { // will never happen as utf-8 is the encoding } apiCallLogHolder.set(apiCallLog); }
From source file:ru.mystamps.web.controller.ErrorController.java
@RequestMapping(Url.NOT_FOUND_PAGE) public void notFound(HttpServletRequest request, @CurrentUser Integer currentUserId, // CheckStyle: ignore LineLength for next 1 line @RequestAttribute(name = RequestDispatcher.ERROR_REQUEST_URI, required = false) String page, @RequestHeader(name = "referer", required = false) String referer, @RequestHeader(name = "user-agent", required = false) String agent) { // TODO: sanitize all user's values (#60) String ip = request.getRemoteAddr(); String method = request.getMethod(); siteService.logAboutAbsentPage(page, method, currentUserId, ip, referer, agent); }
From source file:com.javiermoreno.springboot.rest.CredentialsController.java
@RequestMapping(value = "/token", method = RequestMethod.GET) @ApiOperation(value = "Generacin token", notes = "Retorna un token en Base64 con una duracin marcada por TOKEN_TTL.") public Token createNewAuthToken(HttpServletRequest request) { long ttl = System.currentTimeMillis() + 1000 * TOKEN_TTL; Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Object principal = authentication.getPrincipal(); String username = principal instanceof UserDetails ? ((UserDetails) principal).getUsername() : principal.toString();/*from w w w .j a v a 2 s . c om*/ String ip = request.getHeader("X-Forwarded-For"); if (ip == null) { ip = request.getRemoteAddr(); } Token token = new Token(cryptoService, username, ip, ttl); return token; }