List of usage examples for javax.servlet.http HttpServletRequest getRemoteAddr
public String getRemoteAddr();
From source file:io.apiman.gateway.platforms.servlet.GatewayServlet.java
/** * Reads a {@link ServiceRequest} from information found in the inbound * portion of the http request.//www .ja v a 2s .co m * @param request the undertow http server request * @return a valid {@link ServiceRequest} * @throws IOException */ protected ServiceRequest readRequest(HttpServletRequest request) throws Exception { String apiKey = getApiKey(request); if (apiKey == null) { throw new Exception(Messages.i18n.format("GatewayServlet.MissingAPIKey")); //$NON-NLS-1$ } ServiceRequest srequest = GatewayThreadContext.getServiceRequest(); srequest.setApiKey(apiKey); srequest.setDestination(getDestination(request)); readHeaders(srequest, request); srequest.setRawRequest(request); srequest.setRemoteAddr(request.getRemoteAddr()); return srequest; }
From source file:com.dp2345.interceptor.LogInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { List<LogConfig> logConfigs = logConfigService.getAll(); if (logConfigs != null) { String path = request.getServletPath(); for (LogConfig logConfig : logConfigs) { if (antPathMatcher.match(logConfig.getUrlPattern(), path)) { String username = adminService.getCurrentUsername(); String operation = logConfig.getOperation(); String operator = username; String content = (String) request.getAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME); String ip = request.getRemoteAddr(); request.removeAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME); StringBuffer parameter = new StringBuffer(); Map<String, String[]> parameterMap = request.getParameterMap(); if (parameterMap != null) { for (Entry<String, String[]> entry : parameterMap.entrySet()) { String parameterName = entry.getKey(); if (!ArrayUtils.contains(ignoreParameters, parameterName)) { String[] parameterValues = entry.getValue(); if (parameterValues != null) { for (String parameterValue : parameterValues) { parameter.append(parameterName + " = " + parameterValue + "\n"); }/*w w w. jav a 2s . c o m*/ } } } } Log log = new Log(); log.setOperation(operation); log.setOperator(operator); log.setContent(content); log.setParameter(parameter.toString()); log.setIp(ip); logService.save(log); break; } } } }
From source file:com.redhat.rhn.frontend.servlets.DumpFilter.java
/** {@inheritDoc} */ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { if (log.isDebugEnabled()) { // handle request HttpServletRequest request = (HttpServletRequest) req; log.debug("Entered doFilter() ==================================="); log.debug("AuthType: " + request.getAuthType()); log.debug("Method: " + request.getMethod()); log.debug("PathInfo: " + request.getPathInfo()); log.debug("Translated path: " + request.getPathTranslated()); log.debug("ContextPath: " + request.getContextPath()); log.debug("Query String: " + request.getQueryString()); log.debug("Remote User: " + request.getRemoteUser()); log.debug("Remote Host: " + request.getRemoteHost()); log.debug("Remote Addr: " + request.getRemoteAddr()); log.debug("SessionId: " + request.getRequestedSessionId()); log.debug("uri: " + request.getRequestURI()); log.debug("url: " + request.getRequestURL().toString()); log.debug("Servlet path: " + request.getServletPath()); log.debug("Server Name: " + request.getServerName()); log.debug("Server Port: " + request.getServerPort()); log.debug("RESPONSE encoding: " + resp.getCharacterEncoding()); log.debug("REQUEST encoding: " + request.getCharacterEncoding()); log.debug("JVM encoding: " + System.getProperty("file.encoding")); logSession(request.getSession()); logHeaders(request);//from w w w . jav a 2 s .c o m logCookies(request.getCookies()); logParameters(request); logAttributes(request); log.debug("Calling chain.doFilter() -----------------------------"); } chain.doFilter(req, resp); if (log.isDebugEnabled()) { log.debug("Returned from chain.doFilter() -----------------------"); log.debug("Handle Response, not much to print"); log.debug("Response: " + resp.toString()); log.debug("Leaving doFilter() ==================================="); } }
From source file:net.groupbuy.interceptor.LogInterceptor.java
@SuppressWarnings("unchecked") @Override/*from ww w.j a va2 s .c o m*/ public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { List<LogConfig> logConfigs = logConfigService.getAll(); if (logConfigs != null) { String path = request.getServletPath(); for (LogConfig logConfig : logConfigs) { if (antPathMatcher.match(logConfig.getUrlPattern(), path)) { String username = adminService.getCurrentUsername(); String operation = logConfig.getOperation(); String operator = username; String content = (String) request.getAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME); String ip = request.getRemoteAddr(); request.removeAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME); StringBuffer parameter = new StringBuffer(); Map<String, String[]> parameterMap = request.getParameterMap(); if (parameterMap != null) { for (Entry<String, String[]> entry : parameterMap.entrySet()) { String parameterName = entry.getKey(); if (!ArrayUtils.contains(ignoreParameters, parameterName)) { String[] parameterValues = entry.getValue(); if (parameterValues != null) { for (String parameterValue : parameterValues) { parameter.append(parameterName + " = " + parameterValue + "\n"); } } } } } Log log = new Log(); log.setOperation(operation); log.setOperator(operator); log.setContent(content); log.setParameter(parameter.toString()); log.setIp(ip); logService.save(log); break; } } } }
From source file:org.imsglobal.lti2.LTI2Servlet.java
@SuppressWarnings("unused") protected void doRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("getServiceURL=" + getServiceURL(request)); String ipAddress = request.getRemoteAddr(); System.out.println("LTI Service request from IP=" + ipAddress); String rpi = request.getPathInfo(); String uri = request.getRequestURI(); String[] parts = uri.split("/"); if (parts.length < 4) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); doErrorJSON(request, response, null, "Incorrect url format", null); return;//from www .j ava 2 s . c o m } String controller = parts[3]; if ("register".equals(controller)) { doRegister(request, response); return; } else if ("launch".equals(controller)) { doLaunch(request, response); return; } else if (SVC_tc_profile.equals(controller) && parts.length == 5) { String profile_id = parts[4]; getToolConsumerProfile(request, response, profile_id); return; } else if (SVC_tc_registration.equals(controller) && parts.length == 5) { String profile_id = parts[4]; registerToolProviderProfile(request, response, profile_id); return; } else if (SVC_Result.equals(controller) && parts.length == 5) { String sourcedid = parts[4]; handleResultRequest(request, response, sourcedid); return; } else if (SVC_Settings.equals(controller) && parts.length >= 6) { handleSettingsRequest(request, response, parts); return; } IMSJSONRequest jsonRequest = new IMSJSONRequest(request); if (jsonRequest.valid) { System.out.println(jsonRequest.getPostBody()); } response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); M_log.log(Level.WARNING, "Unknown request=" + uri); doErrorJSON(request, response, null, "Unknown request=" + uri, null); }
From source file:com.hyeb.back.log.LogInterceptor.java
@SuppressWarnings("unchecked") @Override/*from w w w .j av a 2s. co m*/ public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { List<LogConfig> logConfigs = logConfigService.getAll(); if (logConfigs != null) { String path = request.getServletPath(); for (LogConfig logConfig : logConfigs) { if (antPathMatcher.match(logConfig.getUrlPattern(), path)) { String username = sysUserService.getCurrentUsername(); String operation = logConfig.getOperation(); String operator = username; String content = (String) request.getAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME); String ip = request.getRemoteAddr(); request.removeAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME); StringBuffer parameter = new StringBuffer(); Map<String, String[]> parameterMap = request.getParameterMap(); if (parameterMap != null) { for (Entry<String, String[]> entry : parameterMap.entrySet()) { String parameterName = entry.getKey(); if (!ArrayUtils.contains(ignoreParameters, parameterName)) { String[] parameterValues = entry.getValue(); if (parameterValues != null) { for (String parameterValue : parameterValues) { parameter.append(parameterName + " = " + parameterValue + "\n"); } } } } } Log log = new Log(); log.setOperation(operation); log.setOperator(operator); log.setContent(content); log.setParameter(parameter.toString()); log.setIp(ip); logService.save(log); break; } } } }
From source file:org.piraso.web.base.PirasoFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { boolean requestIsWatched = getRegistry().isWatched(new PirasoHttpServletRequest(request)); HttpResponseEntry responseEntry = new HttpResponseEntry(); try {//from w w w . ja v a 2 s .c om if (requestIsWatched) { responseEntry.getElapseTime().start(); ReferenceRequestEntry ref = null; try { if (request.getHeader(REQUEST_ID_HEADER) != null && request.getHeader(GROUP_ID_HEADER) != null) { ref = new ReferenceRequestEntry(); ref.setRemoteAddress(request.getRemoteAddr()); ref.setRequestId(Long.valueOf(request.getHeader(REQUEST_ID_HEADER))); ref.setGroupId(request.getHeader(GROUP_ID_HEADER)); ref.setServerName(request.getRemoteHost()); } } catch (RuntimeException e) { ref = null; } response = new PirasoResponseWrapper(response, responseEntry); PirasoContext context = new PirasoContext(new PirasoHttpServletRequest(request), getRegistry(), ref); PirasoContextHolder.setContext(context); // forward a scoped context log for request entry point ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("request", request.hashCode()), WebEntryUtils.toEntry(request)); } } catch (Exception e) { LOG.warn(e.getMessage(), e); } try { chain.doFilter(request, response); } finally { if (requestIsWatched) { responseEntry.getElapseTime().stop(); // forward a scoped context log for response exit point ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("response", request.hashCode()), responseEntry); PirasoContextHolder.removeContext(); } } }
From source file:org.obiba.mica.web.rest.security.SessionsResource.java
@POST @Path("/sessions") public Response createSession(@SuppressWarnings("TypeMayBeWeakened") @Context HttpServletRequest servletRequest, @FormParam("username") String username, @FormParam("password") String password) { try {//w w w .j a v a2 s . c o m authenticationExecutor.login(new UsernamePasswordToken(username, password)); String sessionId = SecurityUtils.getSubject().getSession().getId().toString(); log.info("Successful session creation for user '{}' session ID is '{}'.", username, sessionId); return Response.created( UriBuilder.fromPath(JerseyConfiguration.WS_ROOT).path(SessionResource.class).build(sessionId)) .build(); } catch (AuthenticationException e) { log.info("Authentication failure of user '{}' at ip: '{}': {}", username, servletRequest.getRemoteAddr(), e.getMessage()); // When a request contains credentials and they are invalid, the a 403 (Forbidden) should be returned. return Response.status(Response.Status.FORBIDDEN).cookie().build(); } }
From source file:com.photon.phresco.service.rest.api.ProjectService.java
@ApiOperation(value = "Update Project ") @ApiErrors(value = { @ApiError(code = 500, reason = "Unable To update") }) @RequestMapping(value = ServiceConstants.REST_API_PROJECT_UPDATE, consumes = MediaType.APPLICATION_JSON_VALUE, produces = ServiceConstants.MEDIATYPE_ZIP, method = RequestMethod.POST) public @ResponseBody byte[] updateProject(HttpServletRequest request, @ApiParam(value = "ProjectInfo to update", name = "projectInfo") @RequestBody ProjectInfo projectInfo) throws PhrescoException, IOException { if (isDebugEnabled) { LOGGER.debug("ProjectService.updateProject : Entry"); }/*from www. j a va 2 s . com*/ if (projectInfo == null) { if (isDebugEnabled) { LOGGER.warn("ProjectService.updateProject", "status=\"Bad Request\"", "remoteAddress=" + request.getRemoteAddr(), "user=" + request.getParameter("userId")); } return null; } FileInputStream fis = null; try { buildUpdateLogMessage(request, projectInfo); String projectPathStr = ServerUtil.getTempFolderPath(); ProjectServiceManager projectService = PhrescoServerFactory.getProjectService(); projectService.updateProject(projectInfo, projectPathStr); ArchiveUtil.createArchive(projectPathStr, projectPathStr + ZIP, ArchiveType.ZIP); fis = new FileInputStream(new File(projectPathStr + ZIP)); return IOUtils.toByteArray(fis); } catch (Exception e) { LOGGER.error("ProjectService.updateProject", "remoteAddress=" + request.getRemoteAddr(), "user=" + request.getParameter("userId"), "status=\"Failure\"", "message=\"" + e.getLocalizedMessage() + "\""); throw new PhrescoException(e); } finally { Utility.closeStream(fis); } }