All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bitsensor.plugins.java.http.filter.handler.RequestIpHandler Maven / Gradle / Ivy

The newest version!
package io.bitsensor.plugins.java.http.filter.handler;

import io.bitsensor.lib.entity.proto.Datapoint;
import io.bitsensor.plugins.java.core.BitSensor;
import io.bitsensor.plugins.shaded.org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Collects the IP address.
 */
@Component
public class RequestIpHandler implements RequestHandler {

    /**
     * Adds the IP address of the HTTP request to the {@link Datapoint}. For documentation on configurations behind
     * loadbalancers, check See Also for your server.
     *
     * @param request  The current HTTP request.
     * @param response The current HTTP response.
     * @see Tomcat
     * @see Spring
     * Boot
     */
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response) {
        if (request.getRemoteAddr() != null) {
            BitSensor.addContext("ip", request.getRemoteAddr());
        }
    }

    /**
     * @return {@link ExecutionMoment#PRE_HANDLE}
     */
    @Override
    public ExecutionMoment getExecutionMoment() {
        return ExecutionMoment.PRE_HANDLE;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy