|
1 | | -squash_java |
2 | | -=========== |
| 1 | +Squash Client Library: Java |
| 2 | +=========================== |
3 | 3 |
|
4 | | -Java client for Squash exception reporting format. The SquashEntry class is meant to be extended |
5 | | -and then serialized with gson for transmission to the Squash server. |
| 4 | +This client library reports exceptions to Squash, the Squarish exception |
| 5 | +reporting and management system. |
6 | 6 |
|
7 | | -For more information: https://git.squareup.com/square/squash |
| 7 | +Documentation |
| 8 | +------------- |
| 9 | + |
| 10 | +For an overview of the various components of Squash, see the website |
| 11 | +documentation at https://github.com/SquareSquash/web. |
| 12 | + |
| 13 | +Compatibility |
| 14 | +------------- |
| 15 | + |
| 16 | +This library is compatible with J2SE 1.6 or newer. All dependencies are handled |
| 17 | +by Maven. |
| 18 | + |
| 19 | +Usage |
| 20 | +----- |
| 21 | + |
| 22 | +The `SquashEntry` class is meant to be extended and then serialized with your |
| 23 | +choice of json library for transmission to your Squash server. We recommend |
| 24 | +using gson, but any auto-field-name-detecting library will do. |
| 25 | + |
| 26 | +First, extend `SquashEntry` and include any additional occurrence data you wish |
| 27 | +to send to Squash. See the `Occurrence` class documentation in the Squash web |
| 28 | +code for a list of known properties; you can also supply any arbitrary |
| 29 | +properties as well. |
| 30 | + |
| 31 | +```` java |
| 32 | +import com.squareup.squash.SquashEntry; |
| 33 | + |
| 34 | +public class AndroidSquashEntry extends SquashEntry implements LogEntry { |
| 35 | + // The API key used for all Android Squash entries. |
| 36 | + private static final String API_KEY = "YOUR_API_KEY"; |
| 37 | + private static final String CLIENT_ID = "android"; |
| 38 | + private static final String DEBUG = "Debug"; |
| 39 | + private static final String RELEASE = "Release"; |
| 40 | + // Transient so it doesn't try to serialize itself. |
| 41 | + private transient Gson gson; |
| 42 | + |
| 43 | + // Device stuff. |
| 44 | + private final String device_id; |
| 45 | + private final String device_type; |
| 46 | + private final String operating_system; |
| 47 | + private final boolean rooted; |
| 48 | + private final String network_operator; |
| 49 | + private final String network_type; |
| 50 | + private final String connectivity; |
| 51 | + private final String orientation; |
| 52 | + |
| 53 | + // Location stuff. |
| 54 | + private final String lat; |
| 55 | + private final String lon; |
| 56 | + private final String altitude; |
| 57 | + private final String location_precision; |
| 58 | + private final String heading; |
| 59 | + private final String speed; |
| 60 | + |
| 61 | + // Which app am I? |
| 62 | + private final String app_id; |
| 63 | +} |
| 64 | +```` |
| 65 | + |
| 66 | +Build a constructor or whatever you need to set all these parameters, and then |
| 67 | +add the ability for the class to transmit itself to Squash: |
| 68 | + |
| 69 | +```` java |
| 70 | +public class AndroidSquashEntry extends SquashEntry implements LogEntry { |
| 71 | + @Override public void writeTo(OutputStream output) throws IOException { |
| 72 | + final String json = gson.toJson(this); |
| 73 | + output.write(Strings.getBytes(json)); |
| 74 | + } |
| 75 | +} |
| 76 | +```` |
| 77 | + |
| 78 | +Add an exception handler that will generate these entry instances. (In the below |
| 79 | +example we're assuming that you've also built a factory that instantiates Squash |
| 80 | +entries, and a `transmit` method that transmits the JSON to Squash.) |
| 81 | + |
| 82 | +```` java |
| 83 | +public class SquashUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { |
| 84 | + @Inject AndroidSquashEntryFactory squashEntryFactory; |
| 85 | + |
| 86 | + @Override public void uncaughtException(Thread thread, Throwable ex) { |
| 87 | + try { |
| 88 | + transmit(squashEntryFactory.create(message, ex)); |
| 89 | + } catch (Throwable ignored) { |
| 90 | + // write your internal failsafe handler |
| 91 | + } |
| 92 | + } |
| 93 | +} |
| 94 | +```` |
| 95 | + |
| 96 | +... and install the exception handler. |
| 97 | + |
| 98 | +```` java |
| 99 | +final Thread.UncaughtExceptionHandler handler = |
| 100 | + Thread.getDefaultUncaughtExceptionHandler(); |
| 101 | +Thread.setDefaultUncaughtExceptionHandler( |
| 102 | + new SquashUncaughtExceptionHandler(this, handler)); |
| 103 | +```` |
| 104 | + |
| 105 | +De-Obfuscation and File Paths |
| 106 | +----------------------------- |
| 107 | + |
| 108 | +The [Squash Java Deobfuscator](https://github.com/SquareSquash/java_deobfuscator) |
| 109 | +Ruby gem can be included into your build-and-release process to upload yGuard |
| 110 | +or ProGuard obfuscation maps to Squash. |
| 111 | + |
| 112 | +Even if you are not using code obfuscation, you can still use this gem to map |
| 113 | +Java class names to their original file paths, as Java stack traces do not |
| 114 | +include the full path to source files, which Squash needs to perform its |
| 115 | +Git-blame magic. |
0 commit comments