List of usage examples for javax.servlet.http HttpServletRequest getRemoteHost
public String getRemoteHost();
From source file:siddur.solidtrust.site.APIController.java
@SuppressWarnings("deprecation") @RequestMapping(value = "/autoscout_price") public @ResponseBody Object autoscoutPrice(@RequestParam(value = "id", required = false) String key, @RequestParam(value = "brand", required = false) String brand, @RequestParam(value = "model", required = false) String model, @RequestParam(value = "build", required = false) String build, @RequestParam(value = "mileage", required = false) Integer mileage, HttpServletRequest request) throws Exception { AccessItem ai = new AccessItem(); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.AUTOSCOUT_PRICE.getId()); ai.setRequest(brand + " " + model + " " + mileage); Map<String, Object> map = new HashMap<String, Object>(); if (key != null) { AzureCar entity = azureService.findByLicensePlate(key); build = (entity.getDateOfBuild().getYear() + 1900) + ""; brand = entity.getBrand();// ww w. j a v a2s .co m model = entity.getType(); } List<AutoscoutNl> list = autoScountanalyzer.search(build, brand, model, mileage); if (!list.isEmpty()) { ClassicCarPrice price = autoScountanalyzer.calc(list); map.put("Average", price.getAveragePrice()); map.put("Highest", price.getHighestPrice()); map.put("Lowest", price.getLowestPrice()); map.put("count", list.size()); map.put("brand", brand); map.put("model", model); map.put("year", build); } Object result = null; if (map.isEmpty()) { result = "not data"; ai.setStatus(0); ai.setResponse(null); } else { result = map; ai.setResponse(map.get("Average") + ""); } free.save(ai); return result; }
From source file:siddur.solidtrust.site.APIController.java
@SuppressWarnings("deprecation") @RequestMapping(value = "/classic_price") public @ResponseBody Object classicPrice( @RequestParam(value = "type", required = false, defaultValue = "2") int searchType, @RequestParam("key") String key, @RequestParam(value = "enableBuild", required = false, defaultValue = "true") boolean enableBuild, HttpServletRequest request) throws Exception { AccessItem ai = new AccessItem(); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.CLASSIC_PRICE.getId()); ai.setRequest(key);//from ww w. jav a 2 s . co m Map<String, Object> map = new HashMap<String, Object>(); if (!StringUtils.isEmpty(key)) { key = key.trim(); if (key.length() > 4) { String brand, model; int year = 0; if (searchType == 2) { AzureCar entity = azureService.findByLicensePlate(key); year = (entity.getDateOfBuild().getYear() + 1900); brand = entity.getBrand(); model = entity.getType(); } else { try { year = Integer.parseInt(key.substring(0, 4)); } catch (Exception e) { e.printStackTrace(); } brand = model = key.substring(4); } List<ClassicCarItem> list = calculator.search(enableBuild ? year : 0, brand, model, false, true); if (searchType == 2 && list.size() < 5) { log4j.info("Found results are less than 5, enable to search with build year range"); list = calculator.search(enableBuild ? year : 0, brand, model, true, true); } if (!list.isEmpty()) { ClassicCarPrice price = calculator.calc(list); map.put("Average", price.getAveragePrice()); map.put("Highest", price.getHighestPrice()); map.put("Lowest", price.getLowestPrice()); map.put("count", list.size()); map.put("brand", brand); map.put("model", model); map.put("year", year); } } } Object result = null; if (map.isEmpty()) { result = "not data"; ai.setStatus(0); } else { result = map; } free.save(ai); return result; }
From source file:siddur.solidtrust.site.APIController.java
@RequestMapping("/logo") public @ResponseBody Object logo(String key, String type, HttpServletRequest request) throws Exception { AccessItem ai = new AccessItem(); ai.setRequest(request.getQueryString()); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.LOGO.getId()); String logo = logoService.find(key, "plate".equals(type)); ai.setResponse(logo);/*w w w.ja v a2s. c o m*/ free.save(ai); return logo; }
From source file:siddur.solidtrust.site.APIController.java
@RequestMapping(value = "/scout_de_price") public @ResponseBody Object autoscoutPrice2(@RequestParam(value = "brand") String brand, @RequestParam(value = "model") String model, @RequestParam(value = "build", required = false) String build, @RequestParam(value = "fuelType", required = false) String fuelType, @RequestParam(value = "mileage", required = false) Integer mileage, @RequestParam(value = "horsepower", required = false) Integer horsepower, @RequestParam(value = "engineSize", required = false) Integer engineSize, HttpServletRequest request) throws Exception { AccessItem ai = new AccessItem(); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.AUTOSCOUT_DE_PRICE.getId()); ai.setRequest(brand + " " + model + " " + mileage); Map<String, Object> map = new HashMap<String, Object>(); if (StringUtils.isNotBlank(fuelType)) { fuelType = fuelType.toLowerCase(); if ("petrol".equals(fuelType) || "gasoline".equals(fuelType) || "benzine".equals(fuelType)) { fuelType = "Benzin"; }/*from w ww.j ava 2 s.c o m*/ } List<AutoscoutDe> list = autoscoutDeAnalyzer.search(build, brand, model, engineSize, engineSize, fuelType, null, mileage, horsepower, null, null); if (list.isEmpty() && (horsepower != null || engineSize != null)) { list = autoscoutDeAnalyzer.search(build, brand, model, null, null, fuelType, null, mileage, null, null, null); } if (!list.isEmpty()) { ClassicCarPrice price = autoscoutDeAnalyzer.calc(list); map.put("Average", price.getAveragePrice()); map.put("Highest", price.getHighestPrice()); map.put("Lowest", price.getLowestPrice()); map.put("count", list.size()); map.put("brand", brand); map.put("model", model); } Object result = null; if (map.isEmpty()) { result = "not data"; ai.setStatus(0); ai.setResponse(null); } else { result = map; ai.setResponse(map.get("Average") + ""); } free.save(ai); return result; }
From source file:siddur.solidtrust.site.APIController.java
@RequestMapping("/cost") public @ResponseBody Object cost(String id, HttpServletRequest request) throws Exception { AccessItem ai = new AccessItem(); ai.setRequest(request.getQueryString()); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.CAR_COST.getId()); CarCost cc = carCostService.search(id); Object result = null;//www. j av a 2s .c om if (cc == null) { result = "no data"; ai.setResponse("no data"); } else { result = cc; ai.setResponse(cc.getBrand() + ", " + cc.getModel() + ", " + cc.getBuild()); } free.save(ai); return result; }
From source file:org.iwethey.forums.web.HeaderInterceptor.java
/** * Load the request attributes with the User object (if authenticated) * and start time for the page for audit purposes. * <p>/* www. j av a 2s . co m*/ * @param request The servlet request object. * @param response The servlet response object. * @param handler The request handler processing this request. */ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { Date now = new Date(); request.setAttribute("now", now); long start = now.getTime(); request.setAttribute("start", new Long(start)); Integer id = (Integer) WebUtils.getSessionAttribute(request, USER_ID_ATTRIBUTE); User user = null; if (id == null) { user = (User) WebUtils.getSessionAttribute(request, USER_ATTRIBUTE); if (user == null) { user = new User("Anonymous"); WebUtils.setSessionAttribute(request, USER_ATTRIBUTE, user); } } else { user = mUserManager.getUserById(id.intValue()); user.setLastPresent(new Date()); mUserManager.saveUserAttributes(user); } request.setAttribute("username", user.getNickname()); request.setAttribute(USER_ATTRIBUTE, user); System.out.println("Local Address = [" + request.getLocalAddr() + "]"); System.out.println("Local Name = [" + request.getLocalName() + "]"); System.out.println("Remote Address = [" + request.getRemoteAddr() + "]"); System.out.println("Remote Host = [" + request.getRemoteHost() + "]"); System.out.println("Remote Port = [" + request.getRemotePort() + "]"); System.out.println("Remote User = [" + request.getRemoteUser() + "]"); System.out.println("Context Path = [" + request.getContextPath() + "]"); System.out.println("===================="); Cookie[] cookies = request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; System.out.println("Cookie Domain = [" + cookie.getDomain() + "]"); System.out.println("Cookie Name = [" + cookie.getName() + "]"); System.out.println("Cookie Value = [" + cookie.getValue() + "]"); System.out.println("Cookie Expire = [" + cookie.getMaxAge() + "]"); System.out.println("===================="); if ("iwt_cookie".equals(cookie.getName())) { cookie.setMaxAge(1000 * 60 * 60 * 24 * 30 * 6); response.addCookie(cookie); } } } else { System.out.println("No cookies were found in the request"); } Cookie newCookie = new Cookie("iwt_cookie", "harrr2!"); newCookie.setPath(request.getContextPath()); newCookie.setDomain(request.getLocalName()); newCookie.setMaxAge(1000 * 60 * 60 * 24 * 30 * 6); response.addCookie(newCookie); request.setAttribute(HEADER_IMAGE_ATTRIBUTE, "/images/iwethey-lrpd-small.png"); return true; }
From source file:siddur.solidtrust.site.APIController.java
@RequestMapping(value = "/brand_mileage") public @ResponseBody Object brandMileage(@RequestParam("id") String id, HttpServletRequest request) throws Exception { AccessItem ai = new AccessItem(); ai.setRequest(id);/*ww w .j av a 2 s. c o m*/ ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.BRAND_MILEAPGE.getId()); AzureCar entity = null; Object result = null; Integer avg = null; if (!StringUtils.isEmpty(id)) { entity = azureService.findByLicensePlate(id.trim()); } if (entity != null) { String brand = entity.getBrand(); @SuppressWarnings("deprecation") int build = (entity.getDateOfBuild().getYear() + 1900); if (build >= Calendar.getInstance().get(Calendar.YEAR) - 16) { String fuelType = entity.getFuelType(); avg = topMileage.topMileage(brand, fuelType); } } if (avg == null) { String r = "Not found:" + id; ai.setResponse(r); result = r; ai.setStatus(0); } else { result = avg.intValue(); ai.setResponse(result + ""); } free.save(ai); return result; }
From source file:siddur.solidtrust.site.APIController.java
@RequestMapping("/trader") public @ResponseBody Object trader(@RequestParam(value = "brand", required = true) String brand, @RequestParam(value = "model", required = false) String model, HttpServletRequest request) throws Exception { AccessItem ai = new AccessItem(); ai.setRequest(request.getQueryString()); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.AUTOTRADER.getId()); List<Autotrader> result = traderService.searchByLucene(brand, model); if (result.isEmpty()) { ai.setStatus(0);/*from w w w. j av a 2s .com*/ } else { ai.setResponse(result.size() + ""); } free.save(ai); return result; }
From source file:siddur.solidtrust.site.APIController.java
@Transactional(readOnly = true) @RequestMapping(value = "/marktplaats_mileage") public @ResponseBody Object mileage(@RequestParam("id") String id, HttpServletRequest request) throws Exception { AccessItem ai = new AccessItem(); ai.setRequest(id);//from w w w.ja va 2 s. c o m ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.MARKTPLAATS_MILEAPGE.getId()); AzureCar entity = null; Object result = null; Integer avg = null; if (!StringUtils.isEmpty(id)) { entity = azureService.findByLicensePlate(id.trim()); } if (entity != null) { String brand = entity.getBrand(); String _model = entity.getType(); @SuppressWarnings("deprecation") String build = (entity.getDateOfBuild().getYear() + 1900) + ""; String fuelType = entity.getFuelType(); avg = mService.mileageByLuceneForAPI2(brand, _model, build, fuelType); } if (avg == null || avg == 0) { String r = "no data"; ai.setResponse(r); result = r; ai.setStatus(0); } else { result = avg; ai.setResponse(result + ""); } free.save(ai); return result; }
From source file:siddur.solidtrust.site.APIController.java
@RequestMapping("/anw") public @ResponseBody Object anw(@RequestParam(value = "brand", required = true) String brand, @RequestParam(value = "model", required = false) String model, @RequestParam(value = "build", required = false) String build, HttpServletRequest request) throws Exception { AccessItem ai = new AccessItem(); ai.setRequest(request.getQueryString()); ai.setIp(request.getRemoteHost()); ai.setUsername(request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""); ai.setService(Product.ANW.getId());//from w ww . ja va2 s . c o m List<ANWBautotests> result = anwService.searchByLucene(brand, model, build); if (result.isEmpty()) { ai.setStatus(0); } else { ai.setResponse(result.size() + ""); } free.save(ai); return result; }