<commit_before># honeybadger-java [![Build Status](https://travis-ci.org/honeybadger-io/honeybadger-java.svg)](https://travis-ci.org/honeybadger-io/honeybadger-java)

Java client to report exceptions to the :zap: [Honeybadger.io error notification
service](https://www.honeybadger.io/). Receive instant notification of
exceptions and errors in your Java applications.

## Description
This is a library for sending errors that implement ```java.lang.Throwable``` on the JVM to the online error reporting service <a href="https://www.honeybadger.io/">Honeybadger</a>.

## Download / Maven Repository
You can find the library on <a href="http://search.maven.org/#browse%7C-1627719036">Maven Central</a> or you can always clone this github repository.

## Implementation
If you want to send all unhandled errors to Honeybadger and have them logged to slf4j via 
the error log level, you will need to set some system properties and add a single line 
to the thread in which you want to register the error handler.

A typical stand-alone implementation may look like:

```java
import io.honeybadger.reporter.HoneybadgerUncaughtExceptionHandler;

public static void main(String argv[]) {
    HoneybadgerUncaughtExceptionHandler.registerAsUncaughtExceptionHandler();
    // The rest of the application goes here
}
```

A servlet based implemantion may look like:

In your web.xml file:
```xml
    <!-- Send all uncaught servlet exceptions and servlet request details to Honeybadger -->
    <filter>
        <filter-name>HoneybadgerFilter</filter-name>
        <filter-class>io.honeybadger.reporter.servlet.HoneybadgerFilter</filter-class>
        <init-param>
            <param-name>honeybadger.api_key</param-name>
            <param-value>API KEY GOES HERE</param-value>
        </init-param>
        <init-param>
            <param-name>honeybadger.excluded_sys_props</param-name>
            <param-value><PASSWORD>.password,<PASSWORD></param-value>
        </init-param>
        <init-param>
            <param-name>honeybadger.excluded_exception_classes</param-name>
            <param-value>org.apache.catalina.connector.ClientAbortException</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>HoneybadgerFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
```

If you want to send exceptions to HoneyBadger without having to register an uncaught 
exception handler, you can create an instance of ```HonebadgerReporter``` and call 
the ```reportError(Throwable error)``` method directly.

## Runtime Dependencies
All dependencies needed for running are included in the distributed JAR with one
exception - slf4j-api. We expect that you are using some logging library and that
you have imported the sl4j-api in order to provide a common interface for the 
logger to imported libraries. If you are using Maven, Gralde or Ivy, this should
happen automatically for you. If you are using Ant, you will need to import
the slf4j-api jar and an sl4j implementation.<commit_msg>Added documentation on Play framework usage.<commit_after># honeybadger-java [![Build Status](https://travis-ci.org/honeybadger-io/honeybadger-java.svg)](https://travis-ci.org/honeybadger-io/honeybadger-java)

Java client to report exceptions to the :zap: [Honeybadger.io error notification
service](https://www.honeybadger.io/). Receive instant notification of
exceptions and errors in your Java applications.

## Description
This is a library for sending errors that implement ```java.lang.Throwable``` on the JVM to the online error reporting service <a href="https://www.honeybadger.io/">Honeybadger</a>.

## Download / Maven Repository
You can find the library on <a href="http://search.maven.org/#browse%7C-1627719036">Maven Central</a> or you can always clone this github repository.

## Stand-alone Usage
If you want to send all unhandled errors to Honeybadger and have them logged to slf4j via 
the error log level, you will need to set some system properties and add a single line 
to the thread in which you want to register the error handler.

A typical stand-alone implementation may look like:

```java
import io.honeybadger.reporter.HoneybadgerUncaughtExceptionHandler;

public static void main(String argv[]) {
    HoneybadgerUncaughtExceptionHandler.registerAsUncaughtExceptionHandler();
    // The rest of the application goes here
}
```

## Servlet Usage
A servlet based implementation may look like:

In your web.xml file:
```xml
    <!-- Send all uncaught servlet exceptions and servlet request details to Honeybadger -->
    <filter>
        <filter-name>HoneybadgerFilter</filter-name>
        <filter-class>io.honeybadger.reporter.servlet.HoneybadgerFilter</filter-class>
        <init-param>
            <param-name>honeybadger.api_key</param-name>
            <param-value>API KEY GOES HERE</param-value>
        </init-param>
        <init-param>
            <param-name>honeybadger.excluded_sys_props</param-name>
            <param-value>bonecp.password,bonecp.username</param-value>
        </init-param>
        <init-param>
            <param-name>honeybadger.excluded_exception_classes</param-name>
            <param-value>org.apache.catalina.connector.ClientAbortException</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>HoneybadgerFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
```

## Play Framework Usage
This library has been tested against Play 2.4.2. You can add Honeybadger as an error
handler by adding the library to your SBT build file:
 
```
libraryDependencies += "io.honeybadger" % "honeybadger-java" % "<<VERSION NUMBER>>"
```
 
And then by adding the following line to your conf/application.conf file:

```
play.http.errorHandler=io.honeybadger.reporter.play.HoneybadgerErrorHandler
```

This will allow the library to wrap the default error handler implementation and
pass around Honeybadger error ids instead of the default Play error ids.

## API Only Usage
If you want to send exceptions to HoneyBadger without having to register an uncaught 
exception handler, you can create an instance of ```HonebadgerReporter``` and call 
the ```reportError(Throwable error)``` method directly.

## Runtime Dependencies
All dependencies needed for running are included in the distributed JAR with one
exception - slf4j-api. We expect that you are using some logging library and that
you have imported the sl4j-api in order to provide a common interface for the 
logger to imported libraries. If you are using Maven, Gralde or Ivy, this should
happen automatically for you. If you are using Ant, you will need to import
the slf4j-api jar and an sl4j implementation.
{'fraction_non_alphanumeric': 0.09312704552216602, 'fraction_numerical': 0.0052067836953287715, 'mean_word_length': 3.9433823529411764, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1905110', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1892, 'n_words': 664}