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.seguriboxltv.backing.BeanBase.java

public String GetIp() {

    HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
            .getRequest();/*  w  ww  .j a  va  2s .  co  m*/
    String ipAddress = request.getHeader("X-FORWARDED-FOR");
    if (ipAddress == null) {
        ipAddress = request.getRemoteAddr();
    }

    return ipAddress;
}

From source file:cn.leancloud.diamond.server.controller.ConfigController.java

/**
 * IP?//from ww  w  . j  av a  2 s.  c  om
 * 
 * @param request
 * @return
 */
public String getRemortIP(HttpServletRequest request) {
    if (request.getHeader("x-forwarded-for") == null) {
        return request.getRemoteAddr();
    }
    return request.getHeader("x-forwarded-for");
}

From source file:csns.security.AuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws ServletException, IOException {
    User user = (User) authentication.getPrincipal();
    logger.info(user.getUsername() + " signed in from " + request.getRemoteAddr());

    RequestCache requestCache = new HttpSessionRequestCache();
    SavedRequest savedRequest = requestCache.getRequest(request, response);
    if (savedRequest != null) {
        super.onAuthenticationSuccess(request, response, authentication);
        return;//from w w w .  j  av  a 2s . c  o m
    }

    getRedirectStrategy().sendRedirect(request, response, defaultUrls.userHomeUrl(request));
}

From source file:org.hifivault.geo.location.GeoLocationManager.java

public GeoInfo resolve(HttpSession session, HttpServletRequest httpServletRequest,
        HashMap<String, String> override) {
    if (session == null)
        throw new NullPointerException("session");

    String ip = httpServletRequest.getRemoteAddr();
    String code = geoLocationService.getCountryCode(ip);
    String target = code;//from  w  w  w .j a v a 2 s .com

    if (code != null) {
        if (code.equalsIgnoreCase("--")) {
            code = notfound;
            target = notfound;
            if (log.isDebugEnabled()) {
                log.error("unable to resolve ip to location '" + ip + "' using '" + notfound + "'");
            }
        }
        if (override != null) {
            String manual = override.get(code);
            if (manual != null) {
                target = manual;
            }
        }
        GeoInfo gi = new GeoInfo(ip, code, target);
        session.setAttribute(getGeoInfoAttribute(), gi);
        return gi;
    } else {
        log.error("could not resolve ip to location '" + ip + "'");
    }

    return null;
}

From source file:com.googlecode.psiprobe.controllers.apps.AjaxToggleContextController.java

protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    if (!request.getContextPath().equals(contextName) && context != null) {
        try {// ww w.  j a v  a2  s  .c  o m
            if (context.getAvailable()) {
                logger.info(request.getRemoteAddr() + " requested STOP of " + contextName);
                getContainerWrapper().getTomcatContainer().stop(contextName);
            } else {
                logger.info(request.getRemoteAddr() + " requested START of " + contextName);
                getContainerWrapper().getTomcatContainer().start(contextName);
            }
        } catch (Throwable e) {
            logger.error(e);
            //
            // make sure we always re-throw ThreadDeath
            //
            if (e instanceof ThreadDeath) {
                throw (ThreadDeath) e;
            }
        }
    }
    return new ModelAndView(getViewName(), "available", Boolean
            .valueOf(context != null && getContainerWrapper().getTomcatContainer().getAvailable(context)));
}

From source file:eu.europeana.core.util.web.ClickStreamLoggerImpl.java

private String printLogAffix(HttpServletRequest request) {
    String ip = request.getRemoteAddr();
    String reqUrl = getRequestUrl(request);
    final User user = ControllerUtil.getUser();
    String userId;/*from   w  ww.  j ava 2s . c o m*/
    if (user != null) {
        userId = user.getEmail(); // todo: is this desirable?  was id.toString()
    } else {
        userId = "";
    }
    String language = ControllerUtil.getLocale(request).toString();
    String userAgent = request.getHeader("User-Agent");
    String referer = request.getHeader("referer");
    Cookie[] cookies = request.getCookies();
    String utma = "";
    String utmb = "";
    String utmc = "";
    String utmz = "";
    String languageCookie = "";
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equalsIgnoreCase("__utma")) {
                utma = cookie.getValue();
            } else if (cookie.getName().equalsIgnoreCase("__utmb")) {
                utmb = cookie.getValue();
            } else if (cookie.getName().equalsIgnoreCase("__utmc")) {
                utmc = cookie.getValue();
            } else if (cookie.getName().equalsIgnoreCase("__utmz")) {
                utmz = cookie.getValue();
            } else if (cookie.getName()
                    .equalsIgnoreCase("org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE")) {
                languageCookie = cookie.getValue();
            }
        }
    }
    PortalTheme theme = themeHandler.getByRequest(request);
    return MessageFormat.format(
            "userId={0}, lang={1}, req={4}, date={2}, ip={3}, user-agent={5}, referer={6}, utma={8}, "
                    + "utmb={9}, utmc={10}, utmz={13}, v={7}, duration={11}, langCookie={12}, defaultLanguage={14}",
            userId, language, new DateTime(), ip, reqUrl, userAgent, referer, VERSION, utma, utmb, utmc,
            ClickStreamLoggerInterceptor.getTimeElapsed(), languageCookie, utmz, theme.getDefaultLanguage());
}

From source file:net.testdriven.psiprobe.controllers.apps.AjaxToggleContextController.java

protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    if (!request.getContextPath().equals(contextName) && context != null) {
        try {//w  w w .  ja v a2s.  c  o m
            if (context.getAvailable()) {
                logger.info(request.getRemoteAddr() + " requested STOP of " + contextName);
                getContainerWrapper().getTomcatContainer().stop(contextName);
            } else {
                logger.info(request.getRemoteAddr() + " requested START of " + contextName);
                getContainerWrapper().getTomcatContainer().start(contextName);
            }
        } catch (Throwable e) {
            logger.error(e);
            //
            // make sure we always re-throw ThreadDeath
            //
            if (e instanceof ThreadDeath) {
                throw (ThreadDeath) e;
            }
        }
    }
    return new ModelAndView(getViewName(), "available",
            Boolean.valueOf(context != null && context.getAvailable()));
}

From source file:psiprobe.controllers.wrapper.StopJvmController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    boolean done = false;
    try {//from   w w  w.  ja v  a  2  s  . c o m
        Class.forName("org.tanukisoftware.wrapper.WrapperManager");
        logger.info("JVM is STOPPED by {}", request.getRemoteAddr());
        WrapperManager.stop(stopExitCode);
        done = true;
    } catch (ClassNotFoundException e) {
        logger.info("WrapperManager not found. Do you have wrapper.jar in the classpath?");
        logger.trace("", e);
    }
    return new ModelAndView(getViewName(), "done", done);
}

From source file:com.webtide.jetty.load.generator.web.MonitorServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    if (_restrictToLocalhost) {
        if (!isLoopbackAddress(req.getRemoteAddr())) {
            resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
            return;
        }//from w w  w. j a v  a 2 s.  co m
    }

    if (Boolean.valueOf(req.getParameter("start"))) {
        start = platformMonitor.start();
        return;
    }

    if (Boolean.valueOf(req.getParameter("stop"))) {
        stop = platformMonitor.stop();
        return;
    }

    if (Boolean.valueOf(req.getParameter("stats"))) {
        if (start == null) {
            resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }

        if (stop == null) {
            stop = platformMonitor.stop();
        }
        sendResponse(resp);
    }
}

From source file:ee.ria.xroad.common.request.DummyCentralServiceHandler.java

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.info("Received request from {}", request.getRemoteAddr());
    try {//from   ww w  . j  av  a  2  s.  c om
        SoapMessageImpl requestMessage = ManagementRequestHandler.readRequest(request.getContentType(),
                request.getInputStream());

        log.info("Got request message: {}", requestMessage.getXml());

        String service = requestMessage.getService().getServiceCode();
        switch (service) {
        case "authCertRegRequest":
            handleAuthCertRegRequest(requestMessage, response);
            break;
        case "authCertDeletionRequest":
            handleAuthCertDeletionRequest(requestMessage, response);
            break;
        case "clientRegRequest":
            handleClientRegRequest(requestMessage, response);
            break;
        case "clientDeletionRequest":
            handleClientDeletionRequest(requestMessage, response);
            break;
        default:
            throw new RuntimeException("Unknown service " + service);
        }
    } catch (Exception e) {
        sendErrorResponse(response, translateException(e));
    } finally {
        baseRequest.setHandled(true);
    }
}