<commit_before>/**
 * Copyright (c) 2011-2012, ReXSL.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met: 1) Redistributions of source code must retain the above
 * copyright notice, this list of conditions and the following
 * disclaimer. 2) Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution. 3) Neither the name of the ReXSL.com nor
 * the names of its contributors may be used to endorse or promote
 * products derived from this software without specific prior written
 * permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.rexsl.trap;

import com.jcabi.log.Logger;
import java.io.IOException;
import java.net.URI;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.CharEncoding;

/**
 * All uncaught exceptions will be catched here.
 *
 * <p>Configure it in your {@code WEB-INF/web.xml} like this:
 *
 * <pre>
 * &lt;servlet>
 *  &lt;servlet-name&gt;ExceptionTrap&lt;/servlet-name&gt;
 *  &lt;servlet-class&gt;com.rexsl.trap.ExceptionTrap&lt;/servlet-class&gt;
 *  &lt;init-param&gt;
 *   &lt;param-name&gt;com.rexsl.trap.Template&lt;/param-name&gt;
 *   &lt;param-value&gt;
 *    com.rexsl.trap.StaticTemplate?uri=com/example/Trap-Template.html
 *   &lt;/param-value&gt;
 *  &lt;/init-param&gt;
 *  &lt;init-param&gt;
 *   &lt;param-name&gt;com.rexsl.trap.Notifier&lt;/param-name&gt;
 *   &lt;param-value&gt;
 *    com.rexsl.trap.SmtpNotifier?to=me&#64;example.com&amp;...
 *   &lt;/param-value&gt;
 *  &lt;/init-param&gt;
 * &lt;/servlet&gt;
 * &lt;servlet-mapping&gt;
 *  &lt;servlet-name&gt;ExceptionTrap&lt;/servlet-name&gt;
 *  &lt;url-pattern&gt;/trap&lt;/url-pattern&gt;
 * &lt;/servlet-mapping&gt;
 * &lt;error-page&gt;
 *  &lt;exception-type&gt;java.lang.Throwable&lt;/exception-type&gt;
 *  &lt;location&gt;/trap&lt;/location&gt;
 * &lt;/error-page&gt;
 * </pre>
 *
 * <p>Configuration of the trap behavior is done through {@code init-params},
 * which are named as interfaces with values as URIs. Every URI has a name
 * of implementation class and a list of query params, which will be send to
 * the class in {@link Properties}. See {@link SmtpNotifier} and
 * {@link SmtpBulkNotifier} for better examples.
 *
 * <p>Spaces and all control chars (new lines, tabs, etc) are automatically
 * removed from param values.
 *
 * <p>Multiple values can be separated by commas. If you want to use comma
 * inside an URI replace it with {@code %2C}.
 *
 * @author <NAME> (<EMAIL>)
 * @version $Id$
 * @since 0.3.6
 */
public final class ExceptionTrap extends HttpServlet {

    /**
     * Serialization marker.
     */
    private static final long serialVersionUID = 0x75298A7876D21470L;
<commit_msg>refs #480 - fixed the defect reported in #262<commit_after>/**
 * Copyright (c) 2011-2012, ReXSL.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met: 1) Redistributions of source code must retain the above
 * copyright notice, this list of conditions and the following
 * disclaimer. 2) Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution. 3) Neither the name of the ReXSL.com nor
 * the names of its contributors may be used to endorse or promote
 * products derived from this software without specific prior written
 * permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.rexsl.trap;

import com.jcabi.log.Logger;
import java.io.IOException;
import java.net.URI;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.CharEncoding;

/**
 * All uncaught exceptions will be catched here.
 *
 * <p>Configure it in your {@code WEB-INF/web.xml} like this:
 *
 * <pre>
 * &lt;servlet>
 *  &lt;servlet-name&gt;ExceptionTrap&lt;/servlet-name&gt;
 *  &lt;servlet-class&gt;com.rexsl.trap.ExceptionTrap&lt;/servlet-class&gt;
 *  &lt;init-param&gt;
 *   &lt;param-name&gt;com.rexsl.trap.Template&lt;/param-name&gt;
 *   &lt;param-value&gt;
 *    com.rexsl.trap.StaticTemplate?uri=com/example/Trap-Template.html
 *   &lt;/param-value&gt;
 *  &lt;/init-param&gt;
 *  &lt;init-param&gt;
 *   &lt;param-name&gt;com.rexsl.trap.Notifier&lt;/param-name&gt;
 *   &lt;param-value&gt;
 *    com.rexsl.trap.SmtpNotifier?to=me&#64;example.com&amp;...
 *   &lt;/param-value&gt;
 *  &lt;/init-param&gt;
 * &lt;/servlet&gt;
 * &lt;servlet-mapping&gt;
 *  &lt;servlet-name&gt;ExceptionTrap&lt;/servlet-name&gt;
 *  &lt;url-pattern&gt;/trap&lt;/url-pattern&gt;
 * &lt;/servlet-mapping&gt;
 * &lt;error-page&gt;
 *  &lt;exception-type&gt;java.lang.Throwable&lt;/exception-type&gt;
 *  &lt;location&gt;/trap&lt;/location&gt;
 * &lt;/error-page&gt;
 * </pre>
 *
 * <p>Configuration of the trap behavior is done through {@code init-params},
 * which are named as interfaces with values as URIs. Every URI has a name
 * of implementation class and a list of query params, which will be send to
 * the class in {@link Properties}. See {@link SmtpNotifier} and
 * {@link SmtpBulkNotifier} for better examples.
 *
 * <p>Spaces and all control chars (new lines, tabs, etc) are automatically
 * removed from param values.
 *
 * <p>Multiple values can be separated by commas. If you want to use comma
 * inside an URI replace it with {@code %2C}.
 *
 * @author <NAME> (<EMAIL>)
 * @version $Id$
 * @since 0.3.6
 * @todo #262 This class should be serializable, but it's not. It doesn't
 *  restore its state after deserialization. We should create a test for it
 *  and then fix the defect.
 */
public final class ExceptionTrap extends HttpServlet {

    /**
     * Serialization marker.
     */
    private static final long serialVersionUID = 0x75298A7876D21470L;

{'fraction_non_alphanumeric': 0.11192506304791641, 'fraction_numerical': 0.008766662663624355, 'mean_word_length': 4.352185089974293, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7487129', 'n_tokens_mistral': 2695, 'n_tokens_neox': 2523, 'n_words': 850}