SpanHttpDeriverUtil { public static List<HttpCode> getHttpStatusCodes(List<BinaryAnnotation> binaryAnnotations) { if (binaryAnnotations == null) { return Collections.emptyList(); } List<HttpCode> httpCodes = new ArrayList<>(); for (BinaryAnnotation binaryAnnotation: binaryAnnotations) { if (Constants.ZIPKIN_BIN_ANNOTATION_HTTP_STATUS_CODE.equals(binaryAnnotation.getKey()) && binaryAnnotation.getValue() != null) { String strHttpCode = binaryAnnotation.getValue(); Integer httpCode = toInt(strHttpCode.trim()); if (httpCode != null) { String description = EnglishReasonPhraseCatalog.INSTANCE.getReason(httpCode, Locale.ENGLISH); httpCodes.add(new HttpCode(httpCode, description)); } } } return httpCodes; } private  SpanHttpDeriverUtil(); static List<HttpCode> getHttpStatusCodes(List<BinaryAnnotation> binaryAnnotations); static List<HttpCode> getClientOrServerErrors(List<HttpCode> httpCodes); static String getHttpMethod(Span span); static boolean isHttp(Span span);  }
@Test public void testGetHttpStatusCodes() { BinaryAnnotation http200 = createHttpCodeBinaryAnnotation("200"); BinaryAnnotation http302 = createHttpCodeBinaryAnnotation("302"); BinaryAnnotation http400 = createHttpCodeBinaryAnnotation("400"); BinaryAnnotation http500 = createHttpCodeBinaryAnnotation("500"); BinaryAnnotation other = new BinaryAnnotation(); other.setKey("return code"); other.setValue("450"); List<BinaryAnnotation> binaryAnnotationList = Arrays.asList(http200, http302, http400, http500, other); Assert.assertEquals( Arrays.asList(new SpanHttpDeriverUtil.HttpCode(200, "ok"), new SpanHttpDeriverUtil.HttpCode(302, "302"), new SpanHttpDeriverUtil.HttpCode(400, "400"), new SpanHttpDeriverUtil.HttpCode(500, "500")), SpanHttpDeriverUtil.getHttpStatusCodes(binaryAnnotationList)); binaryAnnotationList = Arrays.asList(other, other); Assert.assertEquals(Collections.emptyList(), SpanHttpDeriverUtil.getHttpStatusCodes(binaryAnnotationList)); Assert.assertEquals("OK", SpanHttpDeriverUtil.getHttpStatusCodes( Arrays.asList(createHttpCodeBinaryAnnotation("200"))).get(0).getDescription()); }
@Test public void testGetHttpStatusCodesOfNullAndEmptyInput() { Assert.assertTrue(SpanHttpDeriverUtil.getHttpStatusCodes(null).isEmpty()); Assert.assertTrue(SpanHttpDeriverUtil.getHttpStatusCodes(Collections.emptyList()).isEmpty()); }