List of usage examples for javax.servlet.http HttpServletRequest getLocalAddr
public String getLocalAddr();
From source file:net.fenyo.mail4hotspot.web.BrowserServlet.java
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException { // debug informations log.debug("doGet"); log.debug("context path: " + request.getContextPath()); log.debug("character encoding: " + request.getCharacterEncoding()); log.debug("content length: " + request.getContentLength()); log.debug("content type: " + request.getContentType()); log.debug("local addr: " + request.getLocalAddr()); log.debug("local name: " + request.getLocalName()); log.debug("local port: " + request.getLocalPort()); log.debug("method: " + request.getMethod()); log.debug("path info: " + request.getPathInfo()); log.debug("path translated: " + request.getPathTranslated()); log.debug("protocol: " + request.getProtocol()); log.debug("query string: " + request.getQueryString()); log.debug("requested session id: " + request.getRequestedSessionId()); log.debug("Host header: " + request.getServerName()); log.debug("servlet path: " + request.getServletPath()); log.debug("request URI: " + request.getRequestURI()); @SuppressWarnings("unchecked") final Enumeration<String> header_names = request.getHeaderNames(); while (header_names.hasMoreElements()) { final String header_name = header_names.nextElement(); log.debug("header name: " + header_name); @SuppressWarnings("unchecked") final Enumeration<String> header_values = request.getHeaders(header_name); while (header_values.hasMoreElements()) log.debug(" " + header_name + " => " + header_values.nextElement()); }//w w w.j a v a 2s . c o m if (request.getCookies() != null) for (Cookie cookie : request.getCookies()) { log.debug("cookie:"); log.debug("cookie comment: " + cookie.getComment()); log.debug("cookie domain: " + cookie.getDomain()); log.debug("cookie max age: " + cookie.getMaxAge()); log.debug("cookie name: " + cookie.getName()); log.debug("cookie path: " + cookie.getPath()); log.debug("cookie value: " + cookie.getValue()); log.debug("cookie version: " + cookie.getVersion()); log.debug("cookie secure: " + cookie.getSecure()); } @SuppressWarnings("unchecked") final Enumeration<String> parameter_names = request.getParameterNames(); while (parameter_names.hasMoreElements()) { final String parameter_name = parameter_names.nextElement(); log.debug("parameter name: " + parameter_name); final String[] parameter_values = request.getParameterValues(parameter_name); for (final String parameter_value : parameter_values) log.debug(" " + parameter_name + " => " + parameter_value); } // parse request String target_scheme = null; String target_host; int target_port; // request.getPathInfo() is url decoded final String[] path_info_parts = request.getPathInfo().split("/"); if (path_info_parts.length >= 2) target_scheme = path_info_parts[1]; if (path_info_parts.length >= 3) { target_host = path_info_parts[2]; try { if (path_info_parts.length >= 4) target_port = new Integer(path_info_parts[3]); else target_port = 80; } catch (final NumberFormatException ex) { log.warn(ex); target_port = 80; } } else { target_scheme = "http"; target_host = "www.google.com"; target_port = 80; } log.debug("remote URL: " + target_scheme + "://" + target_host + ":" + target_port); // create forwarding request final URL target_url = new URL(target_scheme + "://" + target_host + ":" + target_port); final HttpURLConnection target_connection = (HttpURLConnection) target_url.openConnection(); // be transparent for accept-language headers @SuppressWarnings("unchecked") final Enumeration<String> accepted_languages = request.getHeaders("accept-language"); while (accepted_languages.hasMoreElements()) target_connection.setRequestProperty("Accept-Language", accepted_languages.nextElement()); // be transparent for accepted headers @SuppressWarnings("unchecked") final Enumeration<String> accepted_content = request.getHeaders("accept"); while (accepted_content.hasMoreElements()) target_connection.setRequestProperty("Accept", accepted_content.nextElement()); }
From source file:siddur.solidtrust.image.ImageController.java
@RequestMapping(value = "/api/images1") public @ResponseBody Object findCarImages1(final @RequestParam("id") String id, HttpServletRequest request) { final int port = request.getLocalPort(); final String address = request.getLocalAddr(); String username = request.getAttribute(SolidtrustConstants.CLIENT_ID) + ""; AccessItem ai = new AccessItem(); ai.setIp(request.getRemoteHost());//w w w.j a v a2 s. c o m ai.setUsername(username); ai.setService(Product.IMAGES.getId()); ai.setRequest(id); ImageProduct ip = null; try { ip = findImagesByLicensePlate(id, false); ai.setResponse(ip.getImage1()); } catch (Exception e) { } if (ip == null) { ai.setStatus(-1); free.save(ai); return "no data"; } free.save(ai); String portStr = port == 80 ? "" : ":" + port; String prex = "http://" + address + portStr + "/solidtrust/images/"; ImageProduct resp = new ImageProduct(); resp.setArrangement(ip.getArrangement()); resp.setBrand(ip.getBrand()); resp.setType(ip.getType()); resp.setBuildYear(ip.getBuildYear()); if (ip.getImage1() != null) { resp.setImage1(prex + ip.getImage1()); } if (ip.getImage2() != null) { resp.setImage2(prex + ip.getImage2()); } if (ip.getImage3() != null) { resp.setImage3(prex + ip.getImage3()); } if (ip.getImage4() != null) { resp.setImage4(prex + ip.getImage4()); } return resp; }
From source file:nz.co.fortytwo.signalk.processor.LoggerProcessor.java
@Override public void process(Exchange exchange) throws Exception { logger.debug("LoggerProcessor starts"); HttpServletRequest request = exchange.getIn(HttpMessage.class).getRequest(); logger.debug("Session = " + request.getSession().getId()); HttpSession session = request.getSession(); if (logger.isDebugEnabled()) { logger.debug("Request = " + exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST).getClass()); logger.debug("Session = " + session.getId()); }/*from w w w .j ava 2 s. c o m*/ if (session.getId() != null) { String remoteAddress = request.getRemoteAddr(); String localAddress = request.getLocalAddr(); if (Util.sameNetwork(localAddress, remoteAddress)) { exchange.getIn().setHeader(SignalKConstants.MSG_TYPE, SignalKConstants.INTERNAL_IP); } else { exchange.getIn().setHeader(SignalKConstants.MSG_TYPE, SignalKConstants.EXTERNAL_IP); } if (exchange.getIn().getHeader(Exchange.HTTP_METHOD).equals("GET")) { processGet(exchange); } if (exchange.getIn().getHeader(Exchange.HTTP_METHOD).equals("POST")) { processPost(exchange); } } else { exchange.getIn().setHeader("Location", SignalKConstants.SIGNALK_AUTH); exchange.getIn().setBody("Authentication Required"); } }
From source file:com.icesoft.faces.webapp.http.servlet.ServletEnvironmentRequest.java
private void initializeServlet2point4Properties(HttpServletRequest servletRequest) { ServletContext context = servletRequest.getSession().getServletContext(); if (context.getMajorVersion() > 1 && context.getMinorVersion() > 3) { remotePort = servletRequest.getRemotePort(); localName = servletRequest.getLocalName(); localAddr = servletRequest.getLocalAddr(); localPort = servletRequest.getLocalPort(); }/*from w ww.j ava 2s. com*/ }
From source file:org.tolven.ajax.DocServlet.java
/** * Return XML content, optionally transformed. * @throws IOException /* w w w . j a va 2 s . c om*/ * @throws IOException * @throws ImageFormatException */ protected void returnXML(DocBase doc, HttpServletRequest req, HttpServletResponse res) throws IOException { AccountUser accountUser = TolvenRequest.getInstance().getAccountUser(); // res.setContentType("text/xml"); // res.setCharacterEncoding("UTF-8"); try { InputStream xsltStream = openXSLT(accountUser, doc, req.getLocalAddr(), req.getSession().getServletContext()); if (xsltStream == null) { returnText(doc, req, res); return; } Transformer transformer = new Transformer(xsltStream); String keyAlgorithm = propertyBean.getProperty(UserPrivateKey.USER_PRIVATE_KEY_ALGORITHM_PROP); TolvenSessionWrapper sessionWrapper = TolvenSessionWrapperFactory.getInstance(); Reader reader = new StringReader(docProtectionBean.getDecryptedContentString(doc, accountUser, sessionWrapper.getUserPrivateKey(keyAlgorithm))); transformer.transform(reader, res.getWriter()); } catch (Exception e) { throw new RuntimeException("Unable to render XML document " + doc.getId(), e); } }
From source file:rapture.server.web.servlet.BaseReflexScriptPageServlet.java
private Map<String, Object> getRequestVariables(HttpServletRequest req) { Map<String, Object> serverMap = new HashMap<String, Object>(); serverMap.put("ContentType", req.getContentType()); serverMap.put("ContextPath", req.getContextPath()); serverMap.put("Method", req.getMethod()); serverMap.put("PathInfo", req.getPathInfo()); serverMap.put("RemoteAddr", req.getRemoteAddr()); serverMap.put("", req.getLocalAddr()); serverMap.put("Headers", getHeaderVariables(req)); serverMap.put("Attributes", getHeaderAttributes(req)); return serverMap; }
From source file:net.shopxx.plugin.alipayLogin.AlipayLoginPlugin.java
@Override public Map<String, Object> getParameterMap(HttpServletRequest request) { PluginConfig pluginConfig = getPluginConfig(); Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("service", "alipay.auth.authorize"); parameterMap.put("partner", pluginConfig.getAttribute("partner")); parameterMap.put("_input_charset", "utf-8"); parameterMap.put("sign_type", "MD5"); parameterMap.put("return_url", getNotifyUrl()); parameterMap.put("target_service", "user.auth.quick.login"); parameterMap.put("exter_invoke_ip", request.getLocalAddr()); parameterMap.put("client_ip", request.getLocalAddr()); parameterMap.put("sign", generateSign(parameterMap)); return parameterMap; }
From source file:net.duckling.ddl.web.controller.AttachmentController.java
private void addPreviewLog(HttpServletRequest request) { try {//from w w w. jav a2s. c om DLogClient client = getDLogClient(); LogBean aLog = new LogBean(); aLog.setHost(request.getLocalAddr()); aLog.setMethod("preview"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = format.format(new Date()); aLog.setTime(time); Map<String, String> params = webLogResolver.buildFixedParameters(request); params.put("from", request.getParameter("from")); aLog.setOption(params); LinkedList<LogBean> ls = new LinkedList<LogBean>(); ls.add(aLog); client.sendLogData(client.prepareData(ls)); } catch (Exception e) { LOG.error("", e); } }
From source file:com.jd.survey.web.settings.SectorsController.java
@Secured({ "ROLE_ADMIN" }) @RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html") public String delete(@PathVariable("id") Long id, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("delete(): id=" + id); try {/*from www .ja v a2 s .co m*/ User user = userService.user_findByLogin(principal.getName()); if (!user.isAdmin()) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } surveySettingsService.sector_remove(id); return "redirect:/admin/sectors"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SectorsController.java
@Secured({ "ROLE_ADMIN" }) @RequestMapping(value = "/surveyTemplates/{id}", method = RequestMethod.DELETE, produces = "text/html") public String deletess(@PathVariable("id") Long id, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("delete(): id=" + id); try {/*from w ww .j av a 2 s. c om*/ User user = userService.user_findByLogin(principal.getName()); if (!user.isAdmin()) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } SurveyTemplate surveyTemplate = (SurveyTemplate) surveySettingsService.surveyTemplate_findById(id); surveySettingsService.surveyTemplate_remove(surveyTemplate); uiModel.asMap().clear(); return "redirect:/admin/sectors"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }