Example usage for javax.servlet.http HttpServletRequest getRemoteAddr

List of usage examples for javax.servlet.http HttpServletRequest getRemoteAddr

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getRemoteAddr.

Prototype

public String getRemoteAddr();

Source Link

Document

Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.

Usage

From source file:com.all.tracker.controllers.InstallerMetricsController.java

@RequestMapping(method = POST)
@ResponseBody// w  ww .  j  av  a  2  s  .c  o m
public String receiveMetricsByPost(@RequestBody String metrics, HttpServletRequest request) {
    try {
        saveMetrics(metrics, request.getRemoteAddr());
    } catch (InstantiationException e) {
        log.error(e, e);
    } catch (IllegalAccessException e) {
        log.error(e, e);
    }
    return "ok";
}

From source file:fr.scc.elo.controller.PlayerController.java

@GET
@Path("/setelo/name/{n}/elo/{e}/type/{t}/save/{s}")
@ApiOperation(value = "affecte un elo a un joueur", notes = "save=true -> cree le joueur au besoin", response = Player.class)
public Response setEloToPlayer(@BeanParam PlayerRequest request, @Context HttpServletRequest http)
        throws EloException {
    try {/*from  w ww .  j a  va 2s  . c  o  m*/
        if (!connectionService.acceptIPUpdate(http.getRemoteAddr())) {
            throw new EloException("Unauthorized IP: " + http.getRemoteAddr());
        }
        return Response
                .ok().entity(eloManager.setEloToPlayer(StringUtils.lowerCase(request.getName()),
                        request.getElo(), request.getTypeMatch(), request.getCreatePlayers()).toString())
                .build();
    } catch (Exception e) {
        return Response.serverError().entity(e.getMessage()).build();
    }
}

From source file:fr.scc.elo.controller.PlayerController.java

@GET
@Path("/setelo/name/{n}/elo/{e}/type/{t}")
@ApiOperation(value = "affecte un elo a un joueur", notes = "save=false si le joueur n'existe pas il y a une erreur", response = Player.class)
public Response setEloToPlayerNoSave(@BeanParam PlayerRequest request, @Context HttpServletRequest http)
        throws EloException {
    try {//from  w  w w  .  j  a v  a 2s  .co m
        if (!connectionService.acceptIPUpdate(http.getRemoteAddr())) {
            throw new EloException("Unauthorized IP: " + http.getRemoteAddr());
        }
        Player player = eloManager.setEloToPlayer(StringUtils.lowerCase(request.getName()), request.getElo(),
                request.getTypeMatch(), request.getCreatePlayers());

        return Response.ok().entity(player).build();
    } catch (Exception e) {
        return Response.serverError().entity(e.getMessage()).build();
    }
}

From source file:com.all.tracker.controllers.InstallerMetricsController.java

@RequestMapping(method = GET, value = "{metrics}")
@ResponseStatus(HttpStatus.OK)/*from w  w  w. j a va2  s.c  om*/
@ResponseBody
public String receiveMetricsByGet(@PathVariable String metrics, HttpServletRequest request) {
    try {
        saveMetrics(metrics, request.getRemoteAddr());
    } catch (InstantiationException e) {
        log.error(e, e);
    } catch (IllegalAccessException e) {
        log.error(e, e);
    }
    return "ok";
}

From source file:com.bluepandora.therap.donatelife.adminpanel.AdminServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  ww  .  ja va 2  s . c  o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, JSONException {
    response.setContentType("text/html;charset=UTF-8");
    Debug.debugLog("ADMIN SERVLET HITTED FROM: " + request.getRemoteAddr());

    if (request.getParameter("requestName") != null && request.getParameter("requestFrom") != null) {
        if (request.getParameter("requestFrom").equals("AdMiN")) {
            String requestName = request.getParameter("requestName");
            if (requestName.equals(AdminRequest.requestDonatorList)) {
                AdminService.getDonatorList(request, response);
            } else if (requestName.equals(AdminRequest.requestAdminList)) {
                AdminService.getAdminList(request, response);
            } else if (requestName.equals(AdminRequest.requestFeedBackList)) {
                AdminService.getFeedBackList(request, response);
            } else if (requestName.equals(AdminRequest.requestHospitalList)) {
                AdminService.getHospitalList(request, response);
            } else if (requestName.equals(AdminRequest.requestAdminLogin)) {
                AdminService.adminLogin(request, response);
            } else if (requestName.equals(AdminRequest.requestAddHospital)) {
                AdminService.addHospital(request, response);
            } else if (requestName.equals(AdminRequest.requestRemoveHospital)) {
                System.out.println("Remove Hospital");
                AdminService.removeHospital(request, response);
            } else if (requestName.equals(AdminRequest.requestRemoveFeedBack)) {
                System.out.println("Remove Feedback");
                AdminService.removeFeedBack(request, response);
            } else {
                JSONObject jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, "UNKNOWN SERVICE NAME!");
                SendJsonData.sendJsonData(request, response, jsonObject);
            }

        } else {
            JSONObject jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, "UNAUTHORIZE ACCESS!");
            SendJsonData.sendJsonData(request, response, jsonObject);
        }
    } else {
        JSONObject jsonObject = LogMessageJson.getLogMessageJson(Enum.ERROR, "UNAUTHORIZE ACCESS!");
        SendJsonData.sendJsonData(request, response, jsonObject);
    }

}

From source file:mitm.djigzo.web.services.security.BannedAuthenticationProcessingFilter.java

@Override
protected void onPreAuthentication(HttpServletRequest request, HttpServletResponse response)
        throws AuthenticationException, IOException {
    String email = EmailAddressUtils.canonicalize(obtainUsername(request));

    if (loginBanService != null) {
        if (loginBanService.isBanned(request.getRemoteAddr(), email)) {
            throw new BannedException(email, request.getRemoteAddr());
        }/*from  w  ww.j a  v a2  s.c o m*/
    }

    super.onPreAuthentication(request, response);
}

From source file:com.haulmont.cuba.core.sys.remoting.RemotingServlet.java

@Override
protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception {
    checkConfiguration(request);/*from   w  w w .  j  ava 2 s .c o  m*/

    RemoteClientInfo remoteClientInfo = new RemoteClientInfo();
    remoteClientInfo.setAddress(request.getRemoteAddr());
    remoteClientInfo.setHost(request.getRemoteHost());
    remoteClientInfo.setPort(request.getRemotePort());

    RemoteClientInfo.set(remoteClientInfo);
    try {
        super.doService(request, response);
    } finally {
        RemoteClientInfo.clear();
    }
}

From source file:com.surevine.alfresco.audit.listeners.AbstractAuditEventListener.java

/**
 * @param auditable//w  w  w  .  jav  a  2  s. c o m
 *            the event
 * @param request
 *            http
 */
public void setGenericAuditMetadata(final Auditable auditable, final HttpServletRequest request) {
    auditable.setAction(getAction());
    auditable.setUrl(request.getRequestURI());
    auditable.setRemoteAddress(request.getRemoteAddr());
}

From source file:net.sourceforge.subsonic.backend.controller.IPNController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {//from   w ww .j  a v  a2s .  c  o  m

        LOG.info("Incoming IPN from " + request.getRemoteAddr());

        String url = createValidationURL(request);
        if (validate(url)) {
            LOG.info("Verified payment. " + url);
        } else {
            LOG.warn("Failed to verify payment. " + url);
        }
        processIpnRequest(request);

        return null;
    } catch (Exception x) {
        LOG.error("Failed to process IPN.", x);
        throw x;
    }
}

From source file:psiprobe.controllers.logs.DownloadLogController.java

@Override
protected ModelAndView handleLogFile(HttpServletRequest request, HttpServletResponse response,
        LogDestination logDest) throws Exception {

    boolean compressed = "true".equals(ServletRequestUtils.getStringParameter(request, "compressed"));

    File file = logDest.getFile();
    logger.info("Sending {}{} to {} ({})", file, (compressed ? " compressed" : ""), request.getRemoteAddr(),
            request.getRemoteUser());//ww  w . j a  va 2s.co m
    if (compressed) {
        Utils.sendCompressedFile(request, response, file);
    } else {
        Utils.sendFile(request, response, file);
    }
    return null;
}