Java Code Examples for javax.servlet.http.HttpServletRequest.getRemoteHost()

The following are Jave code examples for showing how to use getRemoteHost() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: apache-tomcat-7.0.73-with-comment   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testIncomingRequestIsSecuredButProtocolHeaderSaysItIsNotWithDefaultValues() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setSecure(true);
    request.setScheme("https");
    request.setHeader("x-forwarded-for", "140.211.11.130");
    request.setHeader("x-forwarded-proto", "http");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    boolean actualSecure = actualRequest.isSecure();
    assertFalse("request must be unsecured as header x-forwarded-proto said it is http", actualSecure);

    String actualScheme = actualRequest.getScheme();
    assertEquals("scheme must be http as header x-forwarded-proto said it is http", "http", actualScheme);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);

}
 
Example 2
Project: apache-tomcat-7.0.73-with-comment   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testIncomingRequestIsSecuredButProtocolHeaderSaysItIsNotWithCustomValues() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");
    filterDef.addInitParameter("remoteIpHeader", "x-my-forwarded-for");
    filterDef.addInitParameter("httpServerPort", "8080");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setSecure(true);
    request.setScheme("https");
    request.setHeader("x-my-forwarded-for", "140.211.11.130");
    request.setHeader("x-forwarded-proto", "http");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    boolean actualSecure = actualRequest.isSecure();
    assertFalse("request must be unsecured as header x-forwarded-proto said it is http", actualSecure);

    String actualScheme = actualRequest.getScheme();
    assertEquals("scheme must be http as header x-forwarded-proto said it is http", "http", actualScheme);

    int actualServerPort = actualRequest.getServerPort();
    assertEquals("wrong http server port", 8080, actualServerPort);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
 
Example 3
Project: apache-tomcat-7.0.73-with-comment   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testInvokeAllProxiesAreTrustedAndRemoteAddrMatchRegexp() throws Exception {

    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("internalProxies", "127\\.0\\.0\\.1|192\\.168\\..*|another-internal-proxy");
    filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
    filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
    filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setRemoteHost("remote-host-original-value");
    request.addHeader("x-forwarded-for", "140.211.11.130");
    request.addHeader("x-forwarded-for", "proxy1");
    request.addHeader("x-forwarded-for", "proxy2");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
    assertNull("all proxies are trusted, x-forwarded-for must be null", actualXForwardedFor);

    String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
    assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1, proxy2", actualXForwardedBy);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
 
Example 4
Project: apache-tomcat-7.0.73-with-comment   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testInvokeAllProxiesAreInternal() throws Exception {

    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
    filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
    filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
    filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setRemoteHost("remote-host-original-value");
    request.addHeader("x-forwarded-for", "140.211.11.130, 192.168.0.10, 192.168.0.11");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
    assertNull("all proxies are internal, x-forwarded-for must be null", actualXForwardedFor);

    String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
    assertNull("all proxies are internal, x-forwarded-by must be null", actualXForwardedBy);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
 
Example 5
Project: apache-tomcat-7.0.73-with-comment   File: RemoteIpFilter.java   View Source Code Vote up 5 votes
public XForwardedRequest(HttpServletRequest request) {
    super(request);
    this.localPort = request.getLocalPort();
    this.remoteAddr = request.getRemoteAddr();
    this.remoteHost = request.getRemoteHost();
    this.scheme = request.getScheme();
    this.secure = request.isSecure();
    this.serverPort = request.getServerPort();
    
    headers = new HashMap<String, List<String>>();
    for (Enumeration<String> headerNames = request.getHeaderNames(); headerNames.hasMoreElements();) {
        String header = headerNames.nextElement();
        headers.put(header, Collections.list(request.getHeaders(header)));
    }
}
 
Example 6
Project: tomcat7   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testIncomingRequestIsSecuredButProtocolHeaderSaysItIsNotWithDefaultValues() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setSecure(true);
    request.setScheme("https");
    request.setHeader("x-forwarded-for", "140.211.11.130");
    request.setHeader("x-forwarded-proto", "http");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    boolean actualSecure = actualRequest.isSecure();
    assertFalse("request must be unsecured as header x-forwarded-proto said it is http", actualSecure);

    String actualScheme = actualRequest.getScheme();
    assertEquals("scheme must be http as header x-forwarded-proto said it is http", "http", actualScheme);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);

}
 
Example 7
Project: tomcat7   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testInvokeAllowedRemoteAddrWithNullRemoteIpHeader() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
    filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
    filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
    filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setRemoteHost("remote-host-original-value");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    String actualXForwardedFor = request.getHeader("x-forwarded-for");
    assertNull("x-forwarded-for must be null", actualXForwardedFor);

    String actualXForwardedBy = request.getHeader("x-forwarded-by");
    assertNull("x-forwarded-by must be null", actualXForwardedBy);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "192.168.0.10", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "remote-host-original-value", actualRemoteHost);
}
 
Example 8
Project: tomcat7   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testInvokeAllProxiesAreInternal() throws Exception {

    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
    filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
    filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
    filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setRemoteHost("remote-host-original-value");
    request.addHeader("x-forwarded-for", "140.211.11.130, 192.168.0.10, 192.168.0.11");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
    assertNull("all proxies are internal, x-forwarded-for must be null", actualXForwardedFor);

    String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
    assertNull("all proxies are internal, x-forwarded-by must be null", actualXForwardedBy);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
 
Example 9
Project: apache-tomcat-7.0.73-with-comment   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testInvokeNotAllowedRemoteAddr() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
    filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
    filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
    filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");

    MockHttpServletRequest request = new MockHttpServletRequest();

    request.setRemoteAddr("not-allowed-internal-proxy");
    request.setRemoteHost("not-allowed-internal-proxy-host");
    request.setHeader("x-forwarded-for", "140.211.11.130, proxy1, proxy2");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
    assertEquals("x-forwarded-for must be unchanged", "140.211.11.130, proxy1, proxy2", actualXForwardedFor);

    String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
    assertNull("x-forwarded-by must be null", actualXForwardedBy);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "not-allowed-internal-proxy", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "not-allowed-internal-proxy-host", actualRemoteHost);
}
 
Example 10
Project: tomcat7   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testInvokeAllProxiesAreTrustedOrInternal() throws Exception {

    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
    filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
    filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
    filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");

    MockHttpServletRequest request = new MockHttpServletRequest();

    request.setRemoteAddr("192.168.0.10");
    request.setRemoteHost("remote-host-original-value");
    request.setHeader("x-forwarded-for", "140.211.11.130, proxy1, proxy2, 192.168.0.10, 192.168.0.11");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
    assertNull("all proxies are trusted, x-forwarded-for must be null", actualXForwardedFor);

    String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
    assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1, proxy2", actualXForwardedBy);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
 
Example 11
Project: tomcat7   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testInvokeNotAllowedRemoteAddr() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
    filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
    filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
    filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");

    MockHttpServletRequest request = new MockHttpServletRequest();

    request.setRemoteAddr("not-allowed-internal-proxy");
    request.setRemoteHost("not-allowed-internal-proxy-host");
    request.setHeader("x-forwarded-for", "140.211.11.130, proxy1, proxy2");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
    assertEquals("x-forwarded-for must be unchanged", "140.211.11.130, proxy1, proxy2", actualXForwardedFor);

    String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
    assertNull("x-forwarded-by must be null", actualXForwardedBy);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "not-allowed-internal-proxy", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "not-allowed-internal-proxy-host", actualRemoteHost);
}
 
Example 12
Project: oscm   File: ExampleServlet.java   View Source Code Vote up 5 votes
public static String getRealRootPath(HttpServletRequest request)
        throws IOException {
    String remoteHostName = request.getRemoteHost();
    if ("127.0.0.1".equals(remoteHostName)) {
        remoteHostName = "localhost";
    } else {
        remoteHostName = InetLookup.resolveHost(remoteHostName);
        int idx = remoteHostName.indexOf('.');
        if (idx > 0) {
            remoteHostName = remoteHostName.substring(0, idx);
        }
    }
    return new File(Constants.ROOT_PATH, remoteHostName).getCanonicalPath();
}
 
Example 13
Project: apache-tomcat-7.0.73-with-comment   File: TestRemoteIpFilter.java   View Source Code Vote up 5 votes
@Test
public void testInvokeAllProxiesAreTrusted() throws Exception {

    // PREPARE
    RemoteIpFilter remoteIpFilter = new RemoteIpFilter();
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
    filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
    filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
    filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");

    filterDef.setFilter(remoteIpFilter);
    MockHttpServletRequest request = new MockHttpServletRequest();

    request.setRemoteAddr("192.168.0.10");
    request.setRemoteHost("remote-host-original-value");
    request.setHeader("x-forwarded-for", "140.211.11.130, proxy1, proxy2");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
    assertNull("all proxies are trusted, x-forwarded-for must be null", actualXForwardedFor);

    String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
    assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1, proxy2", actualXForwardedBy);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
 
Example 14
Project: ctsms   File: WebUtil.java   View Source Code Vote up 4 votes
public static String getRemoteHost(HttpServletRequest request) {
	if (request != null) {
		return request.getRemoteHost();
	}
	return null;
}
 
Example 15
Project: csap-core   File: HostRequests.java   View Source Code Vote up 4 votes
@Deprecated
@RequestMapping ( value = UPDATE_PLATFORM , produces = MediaType.APPLICATION_JSON_VALUE )
public ObjectNode updatePlatformLocal (
										@RequestParam ( value = "extractDir" , required = true ) String extractToken,
										@RequestParam ( value = "chownUserid" , required = false ) String chownUserid,
										@RequestParam ( value = "timeoutSeconds" , required = false , defaultValue = "120" ) int timeoutSeconds,
										@RequestParam ( value = "deleteExisting" , required = false ) String deleteExisting,
										@RequestParam ( value = "auditUser" , required = false ) String auditUser,
										@RequestParam ( value = "distFile" , required = true ) MultipartFile multiPartFile,
										HttpServletRequest request ) {

	String extractDir = extractToken;
	if ( extractDir.startsWith( Application.FileToken.STAGING.value ) ) {
		// STAGING_TOKEN is used as csap install folder might be different;
		// full paths are not passed when syncing elements between hosts.
		extractDir = extractDir.replaceAll( Application.FileToken.STAGING.value, csapApp.stagingFolderAsString() );
	}

	String desc = multiPartFile.toString();
	if ( multiPartFile != null ) {
		desc = multiPartFile.getOriginalFilename() + " size: " + multiPartFile.getSize();
	}

	logger.info(
		"File System being updated using: {}\t extractToken: {}\t extractDir: {}\n\t chownUserid: {} \t timeoutSeconds: {}\t deleteExisting: {}",
		desc, extractToken, extractDir, chownUserid, timeoutSeconds, deleteExisting );

	ObjectNode jsonObjectResponse = jacksonMapper.createObjectNode();
	jsonObjectResponse.put( "host", Application.getHOST_NAME() );

	ArrayNode coreArray = jsonObjectResponse.putArray( "coreResults" );

	// MUST be the first line otherwise remote parsing will fail in
	// Transfermanager
	StringBuilder plainTextResponse = new StringBuilder( CSAP.AGENT_CONTEXT + "@"
			+ Application.getHOST_NAME() + ":" );

	String servletRemoteHost = request.getRemoteHost();

	if ( !csapApp.isHostAuthenticatedMember( servletRemoteHost ) ) {

		logger.error( "Security WARNING: bypass auth from {}", servletRemoteHost );
		plainTextResponse.append( "**" + CSAP.CONFIG_PARSE_ERROR + " Host "
				+ Application.getHOST_NAME()
				+ " received request from a host not in its cluster lifecycle: "
				+ servletRemoteHost );
		coreArray.add( "**" + CSAP.CONFIG_PARSE_ERROR + " Host "
				+ Application.getHOST_NAME()
				+ " received request from a host not in its cluster lifecycle: "
				+ servletRemoteHost );

		if ( !Application.isRunningOnDesktop() ) {
			return jsonObjectResponse;
		}
	} else {
		jsonObjectResponse = agentApi.platformUpdate( auditUser, "Dummy", extractToken, chownUserid, timeoutSeconds, deleteExisting,
			auditUser, multiPartFile, request );
	}

	return jsonObjectResponse;
}
 
Example 16
Project: atbash-octopus   File: ServletContainerSessionManager.java   View Source Code Vote up 4 votes
/**
 */
public Session createSession(SessionContext sessionContext) throws AuthorizationException {

    /*
    if (!WebUtils.isHttp(sessionContext)) {
        String msg = "SessionContext must be an HTTP compatible implementation.";
        throw new IllegalArgumentException(msg);
    }
    */

    HttpServletRequest request = sessionContext.getServletRequest();

    HttpSession httpSession = request.getSession();

    //SHIRO-240: DO NOT use the 'globalSessionTimeout' value here on the acquired session.
    //see: https://issues.apache.org/jira/browse/SHIRO-240

    String host = request.getRemoteHost();

    return createSession(httpSession, host);

}
 
Example 17
Project: mumu-core   File: WebUtil.java   View Source Code Vote up 4 votes
/**
 * @Title: getRemoteIP @Description: 获取到远程客户端的ip @param @param
 * request @param @return @return String 返回类型 @throws
 */
public static String getRemoteIP(HttpServletRequest request) {
	String ip = request.getRemoteHost();
	return ip;
}
 
Example 18
Project: careconnect-reference-implementation   File: GatewayCamelProcessor.java   View Source Code Vote up 4 votes
@Override
public void process(Exchange exchange) throws Exception {



    if (exchange.getIn().getBody() instanceof HttpServletRequest) {
        // This is a result of a passthrough operation in the resource provider.

        HttpServletRequest httpRequest = (HttpServletRequest) exchange.getIn().getBody();

        exchange.getIn().removeHeaders("*" );

        exchange.getIn().setBody(httpRequest.getInputStream());

        exchange.getIn().setHeader(Exchange.HTTP_METHOD, httpRequest.getMethod());

        if (httpRequest.getQueryString() != null) {

            //log.info("QueryString = "+httpRequest.getQueryString());
            List<NameValuePair> params = URLEncodedUtils.parse(new URI("http://dummy?" + httpRequest.getQueryString()), "UTF-8");

            ListIterator paramlist = params.listIterator();
            while (paramlist.hasNext()) {
                // Remove format. This causes errors in the server (internally we work in JSON only)
                // KGM 3/1/2018
                NameValuePair param = (NameValuePair) paramlist.next();
                // log.info("QS Name ="+param.getName()+" Value="+param.getValue());
                if (param.getName().equals("_format")) paramlist.remove();

            }
            String queryString = URLEncodedUtils.format(params, "UTF-8");
            //log.info("New QS="+queryString);

            exchange.getIn().setHeader(Exchange.HTTP_QUERY, queryString);
        } else {
            exchange.getIn().setHeader(Exchange.HTTP_QUERY, null);
        }


        exchange.getIn().setHeader(Exchange.HTTP_PATH, httpRequest.getPathInfo());

        if (httpRequest.getRemoteAddr() !=null && !httpRequest.getRemoteAddr().isEmpty()) {
            exchange.getIn().setHeader("X-Forwarded-For", httpRequest.getRemoteAddr());
        }
        if (httpRequest.getRemoteHost() !=null && !httpRequest.getRemoteHost().isEmpty()) {
            exchange.getIn().setHeader("X-Forwarded-Host", httpRequest.getRemoteHost());
        }
    }

    exchange.getIn().setHeader(Exchange.ACCEPT_CONTENT_TYPE, "application/json");

    if (exchange.getIn().getHeader("X-Request-ID") == null || exchange.getIn().getHeader("X-Request-ID").toString().isEmpty()) {
        exchange.getIn().setHeader("X-Request-ID",exchange.getExchangeId());
    }

}
 
Example 19
Project: dhus-core   File: ProxyWebAuthenticationDetails.java   View Source Code Vote up 4 votes
public static String getRemoteHost (HttpServletRequest request)
{
   String host = request.getHeader("X-Forwarded-Host");
   if (host == null) host=request.getRemoteHost();
   return host;
}
 
Example 20
Project: convertigo-engine   File: ServletRequester.java   View Source Code Vote up 4 votes
public void preGetDocument() throws EngineException {
	HttpServletRequest request = (HttpServletRequest) inputData;
	
	HttpUtils.checkCV(request);

	String remoteAddr = request.getRemoteAddr();
	Engine.logContext.info("Remote-Addr: \"" + remoteAddr + "\"");
	context.remoteAddr = remoteAddr;
	Log4jHelper.mdcPut(mdcKeys.ClientIP, remoteAddr);

	String remoteHost = "-";
	context.remoteHost = remoteHost;
	if (EnginePropertiesManager.getProperty(PropertyName.NET_REVERSE_DNS).equalsIgnoreCase("true")) {
		remoteHost = request.getRemoteHost();
		if (remoteHost != null) {
			context.remoteHost = remoteHost;
			Log4jHelper.mdcPut(mdcKeys.ClientHostName, context.remoteHost);
			Engine.logContext.info("Remote-Host: \"" + remoteHost + "\"");
		}
	}
	
	String contextID = context.contextID;
	Engine.logContext.debug("Context ID: " + contextID);

	String requestURI = request.getRequestURI();
	Engine.logContext.debug("Request URI: " + requestURI);

	String servletPath = request.getServletPath();
	Engine.logContext.debug("Servlet path: " + servletPath);
	context.servletPath = servletPath;

	String queryString = request.getQueryString();
	Engine.logContext.info("Query string: " + queryString);

	String userAgent = request.getHeader(HeaderName.UserAgent.value());
	Engine.logContext.info("User-Agent: \"" + userAgent + "\"");
	context.userAgent = userAgent;

	try {
		HttpSessionListener.checkSession(request);
	} catch (TASException e) {
		HttpUtils.terminateSession(request.getSession());
		throw new RuntimeException(e);
	}
}