13
13
*/
14
14
package zipkin .server ;
15
15
16
+ import java .io .ByteArrayInputStream ;
16
17
import java .io .ByteArrayOutputStream ;
17
18
import java .io .IOException ;
18
- import java .util .zip .DataFormatException ;
19
- import java .util .zip .Inflater ;
19
+ import java .util .zip .GZIPInputStream ;
20
20
import org .springframework .beans .factory .annotation .Autowired ;
21
21
import org .springframework .http .HttpStatus ;
22
22
import org .springframework .http .ResponseEntity ;
@@ -47,8 +47,8 @@ public class ZipkinHttpCollector {
47
47
final CollectorMetrics metrics ;
48
48
final Collector collector ;
49
49
50
- @ Autowired
51
- ZipkinHttpCollector ( StorageComponent storage , CollectorSampler sampler , CollectorMetrics metrics ) {
50
+ @ Autowired ZipkinHttpCollector ( StorageComponent storage , CollectorSampler sampler ,
51
+ CollectorMetrics metrics ) {
52
52
this .metrics = metrics .forTransport ("http" );
53
53
this .collector = Collector .builder (getClass ())
54
54
.storage (storage ).sampler (sampler ).metrics (this .metrics ).build ();
@@ -81,7 +81,8 @@ DeferredResult<ResponseEntity<?>> validateAndStoreSpans(String encoding, Codec c
81
81
body = gunzip (body );
82
82
} catch (IOException e ) {
83
83
metrics .incrementMessagesDropped ();
84
- result .setResult (ResponseEntity .badRequest ().body ("Cannot gunzip spans\n " ));
84
+ result .setResult (
85
+ ResponseEntity .badRequest ().body ("Cannot gunzip spans: " + e .getMessage () + "\n " ));
85
86
return result ;
86
87
}
87
88
}
@@ -107,16 +108,14 @@ DeferredResult<ResponseEntity<?>> validateAndStoreSpans(String encoding, Codec c
107
108
};
108
109
109
110
static byte [] gunzip (byte [] input ) throws IOException {
110
- Inflater inflater = new Inflater ();
111
- inflater .setInput (input );
111
+ GZIPInputStream in = new GZIPInputStream (new ByteArrayInputStream (input ));
112
112
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream (input .length )) {
113
- while (!inflater .finished ()) {
114
- int count = inflater .inflate (GZIP_BUFFER .get ());
115
- outputStream .write (GZIP_BUFFER .get (), 0 , count );
113
+ byte [] buf = GZIP_BUFFER .get ();
114
+ int len ;
115
+ while ((len = in .read (buf )) > 0 ) {
116
+ outputStream .write (buf , 0 , len );
116
117
}
117
118
return outputStream .toByteArray ();
118
- } catch (DataFormatException e ) {
119
- throw new IOException (e .getMessage (), e );
120
119
}
121
120
}
122
121
}
0 commit comments