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

com.ajjpj.asysmon.measure.http.ASimpleHttpRequestAnalyzer Maven / Gradle / Ivy

There is a newer version: 1.0-pre28
Show newest version
package com.ajjpj.asysmon.measure.http;

import com.ajjpj.abase.collection.immutable.AOption;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;


/**
 * @author arno
 */
public class ASimpleHttpRequestAnalyzer implements AHttpRequestAnalyzer {
    public static final String PARAM_FULL_URL = "http-full-url";
    public static final String PARAM_REMOTE_ADDR = "http-remote-addr";
    public static final String PARAM_PREFIX_COOKIE = "http-cookie-";

    @Override public AHttpRequestDetails analyze(HttpServletRequest request) {
        final AOption identifier = extractIdentifier(request.getRequestURL().toString());
        final Map parameters = extractParameters(request);

        return new AHttpRequestDetails() {
            @Override public AOption getIdentifier() {
                return identifier;
            }
            @Override public Map getParameters() {
                return parameters;
            }
        };
    }

    protected Map extractParameters(HttpServletRequest request) {
        final Map result = new HashMap();

        result.put(PARAM_FULL_URL, request.getRequestURL().toString());
        result.put(PARAM_REMOTE_ADDR, request.getRemoteAddr());

        if(request.getCookies() != null) {
            for(Cookie cookie: request.getCookies()) {
                result.put(PARAM_PREFIX_COOKIE + cookie.getName(), cookie.getValue());
            }
        }

        return result;
    }

    protected AOption extractIdentifier(String url) {
        return AOption.some("");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy