List of usage examples for javax.servlet.http HttpServletRequest getRemoteHost
public String getRemoteHost();
From source file:org.n52.iceland.service.Service.java
private long logRequest(HttpServletRequest request) { long count = counter.incrementAndGet(); this.serviceEventBus.submit(new IncomingRequestEvent(request, count)); if (LOGGER.isDebugEnabled()) { Enumeration<?> headerNames = request.getHeaderNames(); StringBuilder headers = new StringBuilder(); while (headerNames.hasMoreElements()) { String name = (String) headerNames.nextElement(); headers.append("> ").append(name).append(": ").append(request.getHeader(name)).append("\n"); }/*from w w w . j av a2 s. c o m*/ LOGGER.debug("Incoming request No. {}:\n> [{} {} {}] from {} {}\n{}", count, request.getMethod(), request.getRequestURI(), request.getProtocol(), request.getRemoteAddr(), request.getRemoteHost(), headers); } return count; }
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 . j av a2 s .c o m 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:com.imagelake.android.signin.Servlet_signin.java
protected void doPost(HttpServletRequest request, HttpServletResponse respose) throws IOException, ServletException { PrintWriter out = respose.getWriter(); try {/*from w w w .j a va 2s . co m*/ Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String date = sdf.format(d); SimpleDateFormat sdf2 = new SimpleDateFormat("hh:mm:ss"); String loginTime = sdf2.format(d); HttpSession ses = request.getSession(); un = request.getParameter("un"); pw = request.getParameter("pw"); if (un != null && pw != null) { User u = udi.searchSignIn(un, pw); if (u != null) { if (u.getState() == 1) { Userlogin userlogin = new Userlogin(); userlogin.setBrowser("Android"); userlogin.setIp_address(request.getRemoteHost()); userlogin.setSession_id(ses.getId()); userlogin.setStart_date(sdf.format(d)); userlogin.setStart_time(loginTime); userlogin.setCountry("Sri Lanka"); userlogin.setCode("LK"); userlogin.setUser_user_id(u.getUser_id()); userlogin.setState(1); int ok = uldi.insertLogin(userlogin); System.out.println("okkk " + ok); if (ok > 0) { JSONObject jo = new JSONObject(); jo.put("id", u.getUser_id()); jo.put("un", u.getUser_name()); jo.put("pw", u.getPassword()); jo.put("fn", u.getFirst_name()); jo.put("ln", u.getLast_name()); jo.put("em", u.getEmail()); jo.put("user_type", u.getUser_type()); jo.put("state", u.getState()); out.write("json=" + jo.toJSONString()); System.out.println("json" + jo.toJSONString()); } else { out.write("msg=Internal server error,Please try again later."); } } else { out.write("msg=Blocked by the admin"); } } else { out.write("msg=Incorrect user name or password"); } } else { out.write("msg=Please enter user details"); } } catch (Exception e) { e.printStackTrace(); out.write("msg=Internal server error,Please try again later."); } }
From source file:org.openiam.selfsrvc.pswd.UnlockUserWizardController.java
@Override protected ModelAndView processFinish(HttpServletRequest request, HttpServletResponse response, Object command, BindException arg3) throws Exception { UnlockUserCommand cmd = (UnlockUserCommand) command; // get objects from the command object String password = cmd.getPassword(); // update the password in the openiam repository of the primary id String managedSysId = configuration.getDefaultManagedSysId(); String secDomainId = configuration.getDefaultSecurityDomain(); //String encPassword = loginManager.encryptPassword(password); //this.loginManager.resetPassword(secDomainId, cmd.getPrincipal(), managedSysId, encPassword); log.info("-Sync password start"); PasswordSync passwordSync = new PasswordSync("RESET PASSWORD", managedSysId, password, cmd.getPrincipal(), null, secDomainId, "SELFSERVICE", false); passwordSync.setRequestClientIP(request.getRemoteHost()); passwordSync.setRequestorLogin(cmd.getPrincipal()); passwordSync.setRequestorDomain(secDomainId); provisionService.setPassword(passwordSync); log.info("-Sync password complete"); Map model = new HashMap(); model.put("message", "Job done!"); return new ModelAndView("pub/confirm"); }
From source file:org.freeeed.search.web.interceptors.SessionInterceptor.java
public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handle) throws Exception { HttpSession session = req.getSession(); SiteVisitor siteVisitor = null;//w w w.j a v a2s . co m LoggedSiteVisitor loggedSiteVisitor = (LoggedSiteVisitor) session .getAttribute(WebConstants.LOGGED_SITE_VISITOR_SESSION_KEY); if (!isFreePage(handle)) { log.debug("The page is NOT free for not logged users!"); if (loggedSiteVisitor == null) { log.debug("The user is not logged in, will redirect the login required page!"); redirectToLoginRequired(res); return false; } } log.debug("The page is free for not logged users!"); if (handle instanceof SiteVisitorAware) { siteVisitor = (SiteVisitor) session.getAttribute(WebConstants.SITE_VISITOR_SESSION_KEY); if (siteVisitor == null) { siteVisitor = new SiteVisitor(); siteVisitor.setVisitorIP(req.getRemoteHost()); session.setAttribute(WebConstants.SITE_VISITOR_SESSION_KEY, siteVisitor); } ((SiteVisitorAware) handle).setSiteVisitor(siteVisitor); } if (handle instanceof LoggedSiteVisitorAware) { ((LoggedSiteVisitorAware) handle).setLoggedVisitor(loggedSiteVisitor); } return true; }
From source file:org.dataconservancy.dcs.lineage.http.support.RequestUtil.java
/** * Determine the host name that the client targeted with their {@code request}. If {@code considerHostHeader} is * {@code true}, and a HTTP {@code Host} header is present, the value of the header will be used as the host name. * If the header is not present, or if {@code considerHostHeader} is {@code false}, the host name will be determined * using {@link javax.servlet.http.HttpServletRequest#getRemoteHost()}. If {@code performLocalhostIpTranslation} * is {@code true}, and the host name is {@code LOCAL_HOST_IPV4} or {@code LOCAL_HOST_IPV6}, then the host name * will be set to {@code LOCAL_HOST_NAME}. * * @param request the request//from w w w .j a v a 2 s .com * @return the host name targeted by the {@code request} */ private String determineHostName(HttpServletRequest request) { String hostName = null; // If there is a 'Host' header with the request, and if // we are supposed to consider it when determining the host name, // then use it. // This is the best way to go, because the client is indicating // what host and port they targeted final String hostHeader = request.getHeader(HOST_HEADER); if (considerHostHeader && hostHeader != null && hostHeader.trim().length() != 0) { hostName = parseHostHeader(hostHeader)[0]; } // Either the 'Host' header wasn't considered, or parsing it failed for some reason. // So we fall back on request.getRemoteHost() if (hostName == null) { hostName = request.getRemoteHost(); } if (performLocalhostIpTranslation) { if (LOCAL_HOST_IPV4.equals(hostName) || LOCAL_HOST_IPV6.equals(hostName)) { hostName = LOCAL_HOST_NAME; } } return hostName; }
From source file:org.openiam.webadmin.grp.GroupDetailController.java
@Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { String userId = (String) request.getSession().getAttribute("userId"); String domainId = (String) request.getSession().getAttribute("domainId"); String login = (String) request.getSession().getAttribute("login"); GroupDetailCommand groupCommand = (GroupDetailCommand) command; Group group = groupCommand.getGroup(); prepareObject(group);/*from ww w . ja v a 2s. c o m*/ String btn = request.getParameter("btn"); if (btn != null && btn.equalsIgnoreCase("Delete")) { groupManager.removeGroup(group.getGrpId()); auditHelper.addLog("DELETE", domainId, login, "WEBCONSOLE", userId, "0", "GROUP", group.getGrpId(), null, "SUCCESS", null, null, null, null, null, group.getGrpName(), request.getRemoteHost()); ModelAndView mav = new ModelAndView("/deleteconfirm"); mav.addObject("msg", "Group has been successfully deleted."); return mav; } if (group.getGrpId() != null && group.getGrpId().length() > 0) { group.setLastUpdate(new Date(System.currentTimeMillis())); group.setLastUpdatedBy(userId); groupManager.updateGroup(group); auditHelper.addLog("UPDATE", domainId, login, "WEBCONSOLE", userId, "0", "GROUP", group.getGrpId(), null, "SUCCESS", null, null, null, null, null, group.getGrpName(), request.getRemoteHost()); } else { group.setGrpId(null); group.setCreatedBy(userId); group.setCreateDate(new Date(System.currentTimeMillis())); GroupResponse resp = groupManager.addGroup(group); String grpId = null; if (resp.getStatus() == ResponseStatus.SUCCESS) { grpId = resp.getGroup().getGrpId(); } auditHelper.addLog("CREATE", domainId, login, "WEBCONSOLE", userId, "0", "GROUP", grpId, null, "SUCCESS", null, null, null, null, null, group.getGrpName(), request.getRemoteHost()); } return new ModelAndView(new RedirectView(redirectView, true)); //ModelAndView mav = new ModelAndView(getSuccessView()); //return mav; }
From source file:unUtils.ActionError.java
@Override public Object doAction(WikittyPublicationContext context) { error.printStackTrace();//w ww. j a va 2s . c o m HttpServletRequest req = context.getRequest(); String result = "<html><body>Error: " + "<br>context: " + context + "<br>" + "<br>getContextPath: " + req.getContextPath() + "<br>getMethod: " + req.getMethod() + "<br>getPathInfo: " + req.getPathInfo() + "<br>getPathTranslated: " + req.getPathTranslated() + "<br>getQueryString: " + req.getQueryString() + "<br>getRemoteUser: " + req.getRemoteUser() + "<br>getRequestURI: " + req.getRequestURI() + "<br>getRequestURI: " + req.getRequestURI() + "<br>getRequestedSessionId: " + req.getRequestedSessionId() + "<br>getServletPath: " + req.getServletPath() + "<br>getCharacterEncoding: " + req.getCharacterEncoding() + "<br>getContentType: " + req.getContentType() + "<br>getLocalAddr: " + req.getLocalAddr() + "<br>getLocalName: " + req.getLocalName() + "<br>getProtocol: " + req.getProtocol() + "<br>getRemoteAddr: " + req.getRemoteAddr() + "<br>getRemoteHost: " + req.getRemoteHost() + "<br>getScheme: " + req.getScheme() + "<br>getServerName: " + req.getServerName() + "<br>" + "<br>error:<pre>" + StringEscapeUtils.escapeHtml(ExceptionUtil.stackTrace(error)) + "</pre>" + "</body></html>"; return result; }
From source file:org.apache.hadoop.hdfs.server.namenode.ImageServlet.java
private void validateRequest(ServletContext context, Configuration conf, HttpServletRequest request, HttpServletResponse response, FSImage nnImage, String theirStorageInfoString) throws IOException { if (UserGroupInformation.isSecurityEnabled() && !isValidRequestor(context, request.getUserPrincipal().getName(), conf)) { String errorMsg = "Only Namenode, Secondary Namenode, and administrators may access " + "this servlet"; response.sendError(HttpServletResponse.SC_FORBIDDEN, errorMsg); LOG.warn("Received non-NN/SNN/administrator request for image or edits from " + request.getUserPrincipal().getName() + " at " + request.getRemoteHost()); throw new IOException(errorMsg); }//from w w w. j ava2s . c o m String myStorageInfoString = nnImage.getStorage().toColonSeparatedString(); if (theirStorageInfoString != null && !myStorageInfoString.equals(theirStorageInfoString)) { String errorMsg = "This namenode has storage info " + myStorageInfoString + " but the secondary expected " + theirStorageInfoString; response.sendError(HttpServletResponse.SC_FORBIDDEN, errorMsg); LOG.warn("Received an invalid request file transfer request " + "from a secondary with storage info " + theirStorageInfoString); throw new IOException(errorMsg); } }
From source file:com.comcast.cmb.common.controller.EndpointServlet.java
private EndpointMessage parseMessage(HttpServletRequest request) throws IOException { EndpointMessage msg = new EndpointMessage(); String pathInfo = request.getPathInfo(); msg.id = pathInfo.substring(pathInfo.lastIndexOf("/") + 1); SimpleDateFormat fmt = new SimpleDateFormat("yy-MM-dd HH:mm:ss"); msg.host = request.getRemoteAddr() + "/" + request.getRemoteHost(); msg.recvOn = fmt.format(new Date()); msg.url = request.getRequestURL().toString(); msg.method = request.getMethod();//w w w. ja v a2 s . c o m msg.msg = ""; if (msg.method.equals("POST")) { BufferedReader reader = request.getReader(); String line; while ((line = reader.readLine()) != null) { msg.msg += line; } } return msg; }