22
33import java .io .IOException ;
44
5- import com .amazonaws .services .kinesis .connectors .BasicJsonTransformer ;
65import com .amazonaws .services .kinesis .model .Record ;
76import com .amazonaws .util .json .JSONArray ;
87import com .amazonaws .util .json .JSONException ;
98import com .amazonaws .util .json .JSONObject ;
10- import com .sumologic .client .SimpleKinesisMessageModel ;
119import com .sumologic .client .implementations .SumologicTransformer ;
10+ import com .sumologic .client .model .CloudWatchLogsMessageModel ;
11+ import com .sumologic .client .model .LogEvent ;
1212
13- import org .apache .commons .logging .Log ;
14- import org .apache .commons .logging .LogFactory ;
13+ import org .apache .log4j .Logger ;
1514
16- import java .io .ByteArrayInputStream ;
17- import java .io .BufferedReader ;
18- import java .io .InputStreamReader ;
1915import java .nio .ByteBuffer ;
2016import java .nio .CharBuffer ;
2117import java .nio .charset .CharacterCodingException ;
2218import java .nio .charset .Charset ;
23- import java .nio .charset .CharsetDecoder ;
2419import java .nio .charset .CharsetEncoder ;
2520import java .util .List ;
26- import java .util .zip .GZIPInputStream ;
2721
28- import com .fasterxml .jackson .databind .JsonMappingException ;
2922import com .fasterxml .jackson .databind .ObjectMapper ;
30- import com .google .gson .Gson ;
3123
3224/**
3325 * A custom transfomer for {@link CloudWatchLogsMessageModel} records in JSON format. The output is in a format
3426 * usable for insertions to Sumologic.
3527 */
3628public class CloudWatchMessageModelSumologicTransformer
3729 implements SumologicTransformer <CloudWatchLogsMessageModel > {
38-
39- private static final Log LOG = LogFactory .getLog (CloudWatchMessageModelSumologicTransformer .class );
40-
30+ private static final Logger LOG = Logger .getLogger (CloudWatchMessageModelSumologicTransformer .class .getName ());
31+
4132 private static CharsetEncoder encoder = Charset .forName ("UTF-8" ).newEncoder ();
4233
4334 /**
@@ -84,7 +75,7 @@ public String fromClass(CloudWatchLogsMessageModel message) {
8475 @ Override
8576 public CloudWatchLogsMessageModel toClass (Record record ) {
8677 byte [] decodedRecord = record .getData ().array ();
87- String stringifiedRecord = decompressGzip (decodedRecord );
78+ String stringifiedRecord = SumologicKinesisUtils . decompressGzip (decodedRecord );
8879
8980 if (stringifiedRecord == null ) {
9081 LOG .error ("Unable to decompress the record: " +new String (record .getData ().array ())
@@ -109,48 +100,5 @@ public CloudWatchLogsMessageModel toClass(Record record) {
109100 +"\n error: " +e .getMessage ());
110101 }
111102 return null ;
112-
113103 }
114-
115- public static String decompressGzip (byte [] compressedData ) {
116- try {
117- GZIPInputStream gis = new GZIPInputStream (new ByteArrayInputStream (compressedData ));
118- BufferedReader bf = new BufferedReader (new InputStreamReader (gis , "UTF-8" ));
119-
120- String outStr = "" ;
121- String line ;
122- while ((line =bf .readLine ())!=null ) {
123- outStr += line ;
124- }
125- return outStr ;
126- } catch (IOException exc ) {
127- LOG .warn ("Exception during decompression of data: " + exc .getMessage ());
128- return null ;
129- }
130- }
131-
132- public static String byteBufferToString (ByteBuffer buffer ){
133- String data = "" ;
134- CharsetDecoder decoder = Charset .forName ("UTF-8" ).newDecoder ();
135- try {
136- int old_position = buffer .position ();
137- data = decoder .decode (buffer ).toString ();
138- buffer .position (old_position );
139- }catch (Exception e ){
140- e .printStackTrace ();
141- return "" ;
142- }
143- return data ;
144- }
145-
146- private static final Gson gson = new Gson ();
147- public static boolean verifyJSON (String json ) {
148- try {
149- gson .fromJson (json , Object .class );
150- return true ;
151- } catch (com .google .gson .JsonSyntaxException ex ) {
152- return false ;
153- }
154- }
155-
156104}
0 commit comments