<commit_before>package com.peterphi.std.guice.web;

import com.peterphi.std.types.SimpleId;

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

/**
 * Represents the current Http Call being processed by this Thread
 */
public class HttpCallContext
{
	private static ThreadLocal<HttpCallContext> contexts = new ThreadLocal<HttpCallContext>();

	/**
	 * Retrieve the HttpCallContext associated with this Thread
	 *
	 * @return
	 *
	 * @throws IllegalStateException
	 * 		if not inside an http call
	 */
	public static HttpCallContext get() throws IllegalStateException
	{
		final HttpCallContext ctx = peek();

		if (ctx != null)
			return ctx;
		else
			throw new IllegalStateException("Not in an HttpCallContext!");
	}

	/**
	 * Retrieve the HttpCallContext associated with this Thread (or null if none is associated)
	 *
	 * @return
	 *
	 * @throws IllegalStateException
	 * 		if not inside an http call
	 */
	public static HttpCallContext peek()
	{
		return contexts.get();
	}

	public static void clear()
	{
		contexts.remove();
	}

	/**
	 * Creates and associates an HttpCallContext with the current Thread
	 *
	 * @param request
	 * @param response
	 *
	 * @return
	 */
	public static HttpCallContext set(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
	{
		final HttpCallContext ctx = new HttpCallContext(request, response, servletContext);

		contexts.set(ctx);

		return ctx;
	}

	// Instance fields and methods
	/**
	 * The id associated with this HttpCallContext for the purposes of logging
	 */
	private final String logId;
	private final HttpServletRequest request;
	private final HttpServletResponse response;
	private final ServletContext servletContext;

	public HttpCallContext(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
	{
		this(generateLogId(), request, response, servletContext);
	}

	/**
	 * Generates an id for a call to be used when logging
	 *
	 * @return
	 */
	private static String generateLogId()
	{
		return SimpleId.alphanumeric(5);
	}

	public HttpCallContext(String logId, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
	{
		this.logId = logId;
		this.request = request;
		this.response = response;
		this.servletContext = servletContext;
	}

	public String getLogId()
	{
		return logId;
	}

	public HttpServletRequest getRequest()
	{
		return request;
	}

	public HttpServletResponse getResponse()
	{
		return response;
	}

	public ServletContext getServletContext()
	{
		return servletContext;
	}

	/**
	 * Returns a string representation of the request (e.g. "GET /webapp/rest/resource?a=b")
	 *
	 * @return
	 */
	public String getRequestInfo()
	{
		final String method = request.getMethod();
		final String uri = request.getRequestURI();
		final String qs = request.getQueryString();

		if (qs == null)
			return method + " " + uri;
		else
			return method + " " + uri + "?" + qs;
	}

}<commit_msg>Change == null to StringUtils.isEmpty<commit_after>package com.peterphi.std.guice.web;

import com.peterphi.std.types.SimpleId;
import org.apache.commons.lang.StringUtils;

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

/**
 * Represents the current Http Call being processed by this Thread
 */
public class HttpCallContext
{
	private static ThreadLocal<HttpCallContext> contexts = new ThreadLocal<HttpCallContext>();

	/**
	 * Retrieve the HttpCallContext associated with this Thread
	 *
	 * @return
	 *
	 * @throws IllegalStateException
	 * 		if not inside an http call
	 */
	public static HttpCallContext get() throws IllegalStateException
	{
		final HttpCallContext ctx = peek();

		if (ctx != null)
			return ctx;
		else
			throw new IllegalStateException("Not in an HttpCallContext!");
	}

	/**
	 * Retrieve the HttpCallContext associated with this Thread (or null if none is associated)
	 *
	 * @return
	 *
	 * @throws IllegalStateException
	 * 		if not inside an http call
	 */
	public static HttpCallContext peek()
	{
		return contexts.get();
	}

	public static void clear()
	{
		contexts.remove();
	}

	/**
	 * Creates and associates an HttpCallContext with the current Thread
	 *
	 * @param request
	 * @param response
	 *
	 * @return
	 */
	public static HttpCallContext set(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
	{
		final HttpCallContext ctx = new HttpCallContext(request, response, servletContext);

		contexts.set(ctx);

		return ctx;
	}

	// Instance fields and methods
	/**
	 * The id associated with this HttpCallContext for the purposes of logging
	 */
	private final String logId;
	private final HttpServletRequest request;
	private final HttpServletResponse response;
	private final ServletContext servletContext;

	public HttpCallContext(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
	{
		this(generateLogId(), request, response, servletContext);
	}

	/**
	 * Generates an id for a call to be used when logging
	 *
	 * @return
	 */
	private static String generateLogId()
	{
		return SimpleId.alphanumeric(5);
	}

	public HttpCallContext(String logId, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
	{
		this.logId = logId;
		this.request = request;
		this.response = response;
		this.servletContext = servletContext;
	}

	public String getLogId()
	{
		return logId;
	}

	public HttpServletRequest getRequest()
	{
		return request;
	}

	public HttpServletResponse getResponse()
	{
		return response;
	}

	public ServletContext getServletContext()
	{
		return servletContext;
	}

	/**
	 * Returns a string representation of the request (e.g. "GET /webapp/rest/resource?a=b")
	 *
	 * @return
	 */
	public String getRequestInfo()
	{
		final String method = request.getMethod();
		final String uri = request.getRequestURI();
		final String qs = request.getQueryString();

		if (StringUtils.isEmpty(qs))
			return method + " " + uri;
		else
			return method + " " + uri + "?" + qs;
	}

}
{'fraction_non_alphanumeric': 0.09034874290348743, 'fraction_numerical': 0.00032441200324412003, 'mean_word_length': 4.100082712985939, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '260801', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1748, 'n_words': 538}