List of usage examples for javax.servlet.http HttpServletRequest getRemoteHost
public String getRemoteHost();
From source file:nl.nn.adapterframework.http.HttpUtils.java
public static String getCommandIssuedBy(HttpServletRequest request) { String commandIssuedBy = " remoteHost [" + request.getRemoteHost() + "]"; commandIssuedBy += " remoteAddress [" + request.getRemoteAddr() + "]"; commandIssuedBy += " remoteUser [" + request.getRemoteUser() + "]"; return commandIssuedBy; }
From source file:eu.eidas.node.logging.LoggingUtil.java
public static void logServletCall(HttpServletRequest request, final String className, final Logger logger) { if (!StringUtils.isEmpty(request.getRemoteHost())) { MDC.put(LoggingMarkerMDC.MDC_REMOTE_HOST, request.getRemoteHost()); }/* w w w. ja v a 2 s .c o m*/ MDC.put(LoggingMarkerMDC.MDC_SESSIONID, request.getSession().getId()); logger.info(LoggingMarkerMDC.WEB_EVENT, "**** CALL to servlet " + className + " FROM " + request.getRemoteAddr() + " HTTP " + request.getMethod() + " SESSIONID " + request.getSession().getId() + "****"); }
From source file:fi.hsl.parkandride.MDCFilter.java
private static void setValues(ServletRequest request) { HttpServletRequest httpReq = HttpServletRequest.class.cast(request); MDC.put(Key.REQUESTID, UUID.randomUUID().toString()); MDC.put(Key.SRCIP, httpReq.getRemoteHost()); // Authenticated username will be set in UserArgumentResolver iff authentication is required MDC.put(Key.USERNAME, "<ANONYMOUS>"); String appId = httpReq.getHeader(LIIPI_APPLICATION_ID); if (appId != null) { MDC.put(Key.APPID, appId); }//from www .j a v a 2 s.c o m }
From source file:com.cisco.oss.foundation.http.server.AbstractInfraHttpFilter.java
/** * Determine the original client. If there is an x-forwarded-for header, * take the first host/ip from the list. Else, take the value from the * Request object's remote host.// w ww. ja v a 2s . co m * * @param request * The HTTP Servlet request object being handled. * * @return The original client host or IP value. */ public static String getOriginalClient(final HttpServletRequest request) { return getOriginalClient(request.getRemoteHost(), request.getHeader(HttpServerFactory.X_FORWARD_FOR_HEADER)); }
From source file:com.asual.summer.core.RequestFilter.java
static String getRemoteHost(HttpServletRequest request) { String result = request.getHeader("X-Forwarded-For"); if (result == null) { result = request.getRemoteHost(); }//ww w. j a va2 s.c om try { result = java.net.InetAddress.getByName(result).getHostName(); } catch (NoClassDefFoundError e) { } catch (UnknownHostException e) { } return result; }
From source file:com.evolveum.midpoint.web.security.MidPointAuthenticationProvider.java
public static String getRemoteHost() { WebRequest req = (WebRequest) RequestCycle.get().getRequest(); HttpServletRequest httpReq = (HttpServletRequest) req.getContainerRequest(); String remoteIp = httpReq.getRemoteHost(); String localIp = httpReq.getLocalAddr(); if (remoteIp.equals(localIp)) { try {//www . j av a2 s .com InetAddress inetAddress = InetAddress.getLocalHost(); remoteIp = inetAddress.getHostAddress(); } catch (UnknownHostException ex) { LOGGER.error("Can't get local host: " + ex.getMessage()); } } return remoteIp; }
From source file:com.beginner.core.utils.ProjectUtil.java
/** * ?Host/*w ww . j a v a 2s . c o m*/ */ public static String remoteHost() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); return request.getRemoteHost(); }
From source file:it.geosolutions.geostore.services.rest.auditing.AuditInfoExtractorTest.java
private static HttpServletRequest getHttpServletRequest() { HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class); Mockito.when(httpServletRequest.getRemoteAddr()).thenReturn("127.0.0.1"); Mockito.when(httpServletRequest.getRemoteHost()).thenReturn("127.0.0.1"); Mockito.when(httpServletRequest.getRemoteUser()) .thenReturn("User[id=2, name=admin, group=[UserGroup[id=1, groupName=everyone]], role=ADMIN]"); Mockito.when(httpServletRequest.getServerName()).thenReturn("localhost"); UserGroup userGroup = Mockito.mock(UserGroup.class); Mockito.when(userGroup.getGroupName()).thenReturn("everyone"); User user = Mockito.mock(User.class); Mockito.when(user.getName()).thenReturn("admin"); Mockito.when(user.getRole()).thenReturn(Role.ADMIN); Mockito.when(user.getGroups()).thenReturn(Collections.singleton(userGroup)); Authentication authentication = Mockito.mock(Authentication.class); Mockito.when(authentication.getPrincipal()).thenReturn(user); Mockito.when(httpServletRequest.getUserPrincipal()).thenReturn(authentication); return httpServletRequest; }
From source file:net.sourceforge.vulcan.web.struts.actions.BaseDispatchAction.java
static AuditEvent createAuditEvent(Object source, HttpServletRequest request, String action, String type, String oldName, String newName) { final String user = getUsername(request); final String host = request.getRemoteHost(); String name = null;/*w w w . j a v a 2s . c o m*/ String oldName1 = null; String messageKey = "audit.without.name"; if (oldName != null || newName != null) { name = newName; messageKey = "audit.with.name"; if (!isBlank(oldName) && !oldName.equals(newName)) { oldName1 = oldName; messageKey = "audit.with.rename"; } } return new AuditEvent(source, messageKey, user, host, action, type, name, oldName1); }
From source file:net.sourceforge.vulcan.web.struts.actions.ManualBuildAction.java
static String getRequestUsernameOrHostname(HttpServletRequest request) { final Principal userPrincipal = request.getUserPrincipal(); if (userPrincipal != null) { return userPrincipal.getName(); }/*from ww w . j a v a 2s .co m*/ return request.getRemoteHost(); }