List of usage examples for javax.servlet.http HttpServletRequest getRemoteHost
public String getRemoteHost();
From source file:com.squid.kraken.v4.auth.RequestHelper.java
public static <T> T processRequest(Class<T> type, HttpServletRequest request, HttpRequestBase req) throws IOException, URISyntaxException, ServerUnavailableException, ServiceException, SSORedirectException {//from w ww. j a v a 2s . co m // set client information to the header String reqXFF = request.getHeader(STRING_XFF_HEADER); String postXFF; if (reqXFF != null) { // X-Forwarded-For header already exists in the request logger.info(STRING_XFF_HEADER + " : " + reqXFF); if (reqXFF.length() > 0) { // just add the remoteHost to it postXFF = reqXFF + ", " + request.getRemoteHost(); } else { postXFF = request.getRemoteHost(); } } else { postXFF = request.getRemoteHost(); } // add a new X-Forwarded-For header containing the remoteHost req.addHeader(STRING_XFF_HEADER, postXFF); // execute the login request HttpResponse executeCode; try { HttpClient client = HttpClientBuilder.create().build(); executeCode = client.execute(req); } catch (ConnectException e) { // Authentication server unavailable throw new ServerUnavailableException(e); } // process the result BufferedReader rd = new BufferedReader(new InputStreamReader(executeCode.getEntity().getContent())); StringBuffer resultBuffer = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { resultBuffer.append(line); } String result = resultBuffer.toString(); T fromJson; Gson gson = new Gson(); int statusCode = executeCode.getStatusLine().getStatusCode(); if (statusCode != 200) { if (executeCode.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) { String redirectURL = executeCode.getFirstHeader("Location").getValue(); throw new SSORedirectException("SSO Redirect Exception", redirectURL); } else { logger.info("Error : " + req.getURI() + " resulted in : " + result); WebServicesException exception; try { exception = gson.fromJson(result, WebServicesException.class); } catch (Exception e) { if ((statusCode >= 500) && (statusCode < 600)) { // Authentication server unavailable throw new ServerUnavailableException(); } else { throw new ServiceException(); } } throw new ServiceException(exception); } } else { // forward to input page displaying ok message try { fromJson = gson.fromJson(result, type); } catch (Exception e) { throw new ServiceException(e); } } return fromJson; }
From source file:oscar.util.Doc2PDF.java
public static String AddAbsoluteTag(HttpServletRequest request, String docText, String uri) { String absolutePath = ""; docText = docText.replaceAll("src='/", "src='"); docText = docText.replaceAll("src=\"/", "src=\""); docText = docText.replaceAll("src=/", "src="); if (request.getProtocol().toString().equals("HTTP/1.1")) { absolutePath = "http://"; } else {//from ww w .java 2 s.c o m absolutePath = "https://"; } absolutePath += request.getRemoteHost() + ":" + request.getServerPort() + "" + request.getContextPath() + "/"; docText = docText.replaceAll("src='", "src='" + absolutePath); docText = docText.replaceAll("src=\"", "src=\"" + absolutePath); return docText; }
From source file:fr.paris.lutece.util.http.SecurityUtil.java
/** * Write request variables into the dump stringbuffer * @param sb The dump stringbuffer/*from w ww . java2s .c o m*/ * @param request The HTTP request */ private static void dumpVariables(StringBuffer sb, HttpServletRequest request) { dumpVariable(sb, "AUTH_TYPE", request.getAuthType()); dumpVariable(sb, "REQUEST_METHOD", request.getMethod()); dumpVariable(sb, "PATH_INFO", request.getPathInfo()); dumpVariable(sb, "PATH_TRANSLATED", request.getPathTranslated()); dumpVariable(sb, "QUERY_STRING", request.getQueryString()); dumpVariable(sb, "REQUEST_URI", request.getRequestURI()); dumpVariable(sb, "SCRIPT_NAME", request.getServletPath()); dumpVariable(sb, "LOCAL_ADDR", request.getLocalAddr()); dumpVariable(sb, "SERVER_PROTOCOL", request.getProtocol()); dumpVariable(sb, "REMOTE_ADDR", request.getRemoteAddr()); dumpVariable(sb, "REMOTE_HOST", request.getRemoteHost()); dumpVariable(sb, "HTTPS", request.getScheme()); dumpVariable(sb, "SERVER_NAME", request.getServerName()); dumpVariable(sb, "SERVER_PORT", String.valueOf(request.getServerPort())); }
From source file:org.jahia.bin.errors.ErrorLoggingFilter.java
/** * Returns the request information for logging purposes. * * @param request the http request object * @return the request information for logging purposes *///w w w . j a v a 2 s. co m private static String getRequestInfo(HttpServletRequest request) { StringBuilder info = new StringBuilder(512); if (request != null) { String uri = (String) request.getAttribute("javax.servlet.error.request_uri"); String queryString = (String) request.getAttribute("javax.servlet.forward.query_string"); if (StringUtils.isNotEmpty(queryString)) { uri = uri + "?" + queryString; } info.append("Request information:").append("\nURL: ").append(uri).append("\nMethod: ") .append(request.getMethod()).append("\nProtocol: ").append(request.getProtocol()) .append("\nRemote host: ").append(request.getRemoteHost()).append("\nRemote address: ") .append(request.getRemoteAddr()).append("\nRemote port: ").append(request.getRemotePort()) .append("\nRemote user: ").append(request.getRemoteUser()).append("\nSession ID: ") .append(request.getRequestedSessionId()).append("\nSession user: ").append(getUserInfo(request)) .append("\nRequest headers: "); @SuppressWarnings("unchecked") Iterator<String> headerNames = new EnumerationIterator(request.getHeaderNames()); while (headerNames.hasNext()) { String headerName = headerNames.next(); String headerValue = request.getHeader(headerName); info.append("\n ").append(headerName).append(": ").append(headerValue); } } return info.toString(); }
From source file:com.flexive.faces.FxJsfUtils.java
/** * Get the server URL like "http://www.flexive.org" without the context path * * @return server URL/*from w w w.jav a 2 s . c o m*/ */ public static String getServerURL() { final FxRequest req = FxJsfUtils.getRequest(); try { return req.getRequestURL().substring(0, req.getRequestURL().indexOf(req.getContextPath())); } catch (Exception e) { final HttpServletRequest r = req.getRequest(); return r.getProtocol() + "://" + r.getRemoteHost() + (r.getProtocol().startsWith("http") ? "" : ":" + r.getRemotePort()); } }
From source file:de.is24.aws.instancemetadataserver.RemoteHostRoleNameProducer.java
@Override public Optional<String> getRoleName(HttpServletRequest request) { String hostName = request.getRemoteHost(); Optional<String> roleName = toRoleName(hostName); if (!roleName.isPresent()) { LOG.info("Unable to generate a role name for host {}.", hostName); }/*from w w w . j av a 2s . c om*/ return roleName; }
From source file:edu.harvard.iq.dvn.ingest.dsb.DSBWrapper.java
public static boolean isDSBRequest(HttpServletRequest req) { boolean dsbRequest = false; String dsbHost = System.getProperty("vdc.dsb.host"); if (dsbHost == null) { // vdc.dsb.host isn't set; // fall back to the old-style option: dsbHost = System.getProperty("vdc.dsb.url"); }//from ww w .j a v a2 s . c om if (dsbHost.equals(req.getRemoteHost())) { dsbRequest = true; } else { try { String dsbHostIPAddress = InetAddress.getByName(dsbHost).getHostAddress(); if (dsbHostIPAddress.equals(req.getRemoteHost())) { dsbRequest = true; } } catch (UnknownHostException ex) { // do nothing; // the "vdc.dsb.host" setting is clearly misconfigured, // so we just keep assuming this is NOT a DSB call } } return dsbRequest; }
From source file:cz.prochy.cellar.Cellar.java
@RequestMapping(value = "/error") public ResponseEntity<String> error(HttpServletRequest request) { logger.info("Returning error response to " + request.getRemoteHost()); return respond(); }
From source file:com.att.nsa.cambria.service.impl.EventsServiceImpl.java
private static LogDetails generateLogDetails(final String topicName, HttpServletRequest request, final String messageTimestamp, int messageSequence, Long batchId, final boolean transactionEnabled) { LogDetails logDetails = new LogDetails(); logDetails.setTopicId(topicName);/*www .jav a 2 s. c o m*/ logDetails.setMessageTimestamp(messageTimestamp); logDetails.setPublisherId(Utils.getUserApiKey(request)); logDetails.setPublisherIp(request.getRemoteHost()); logDetails.setMessageBatchId(batchId); logDetails.setMessageSequence(String.valueOf(messageSequence)); logDetails.setTransactionEnabled(transactionEnabled); logDetails.setTransactionIdTs(Utils.getFormattedDate(new Date())); logDetails.setServerIp(request.getLocalAddr()); return logDetails; }
From source file:se.kth.csc.controller.HomeController.java
/** * The welcome page of the web application *//*from ww w . j av a 2 s. c o m*/ @Order(Ordered.LOWEST_PRECEDENCE - 1000) @RequestMapping(value = { "/", "/about", "/help", "/queue/**", "/admin" }, method = RequestMethod.GET) public ModelAndView index(HttpServletRequest request) { String hostname; try { hostname = InetAddress.getByName(request.getRemoteHost()).getCanonicalHostName(); } catch (UnknownHostException e) { log.error("Hostname error", e); hostname = null; } return new ModelAndView("index", "hostname", hostname); }