|
25 | 25 | import java.io.StringWriter;
|
26 | 26 | import java.util.AbstractMap.SimpleEntry;
|
27 | 27 | import java.util.Map;
|
28 |
| -import java.util.Optional; |
29 | 28 | import java.util.function.BiConsumer;
|
30 | 29 | import java.util.stream.Collectors;
|
31 | 30 | import java.util.stream.Stream;
|
@@ -73,76 +72,61 @@ private Tags() {
|
73 | 72 | };
|
74 | 73 |
|
75 | 74 | public static final BiConsumer<Map<String, EventAttributeValue>, HttpRequest>
|
76 |
| - HTTP_REQUEST_EVENT = |
77 |
| - (map, req) -> { |
78 |
| - map.put(AttributeKey.HTTP_METHOD.getKey(), |
79 |
| - EventAttribute.setValue(req.getMethod().toString())); |
| 75 | + HTTP_REQUEST_EVENT = (map, req) -> { |
| 76 | + map.put(AttributeKey.HTTP_METHOD.getKey(), EventAttribute.setValue(req.getMethod().toString())); |
80 | 77 | map.put(AttributeKey.HTTP_TARGET.getKey(), EventAttribute.setValue(req.getUri()));
|
81 | 78 |
|
82 |
| - Optional<String> userAgent = Optional.ofNullable(req.getHeader(HttpHeaders.USER_AGENT)); |
83 |
| - if (userAgent.isPresent()) { |
84 |
| - map.put(AttributeKey.HTTP_USER_AGENT.getKey(), |
85 |
| - EventAttribute.setValue(userAgent.get())); |
| 79 | + String userAgent = req.getHeader(HttpHeaders.USER_AGENT); |
| 80 | + if (userAgent != null) { |
| 81 | + map.put(AttributeKey.HTTP_USER_AGENT.getKey(), EventAttribute.setValue(userAgent)); |
86 | 82 | }
|
87 | 83 |
|
88 |
| - Optional<String> host = Optional.ofNullable(req.getHeader(HttpHeaders.HOST)); |
89 |
| - if (host.isPresent()) { |
90 |
| - map.put(AttributeKey.HTTP_HOST.getKey(), |
91 |
| - EventAttribute.setValue(host.get())); |
| 84 | + String host = req.getHeader(HttpHeaders.HOST); |
| 85 | + if (host != null) { |
| 86 | + map.put(AttributeKey.HTTP_HOST.getKey(), EventAttribute.setValue(host)); |
92 | 87 | }
|
93 | 88 |
|
94 |
| - Optional<String> contentLength = |
95 |
| - Optional.ofNullable(req.getHeader(HttpHeaders.CONTENT_LENGTH)); |
96 |
| - if (contentLength.isPresent()) { |
| 89 | + String contentLength = req.getHeader(HttpHeaders.CONTENT_LENGTH); |
| 90 | + if (contentLength != null) { |
97 | 91 | map.put(AttributeKey.HTTP_REQUEST_CONTENT_LENGTH.getKey(),
|
98 |
| - EventAttribute.setValue(contentLength.get())); |
| 92 | + EventAttribute.setValue(contentLength)); |
99 | 93 | }
|
100 | 94 |
|
101 |
| - Optional<String> clientIpAddress = |
102 |
| - Optional.ofNullable(req.getHeader(HttpHeaders.X_FORWARDED_FOR)); |
103 |
| - if (clientIpAddress.isPresent()) { |
104 |
| - map.put(AttributeKey.HTTP_CLIENT_IP.getKey(), |
105 |
| - EventAttribute.setValue(clientIpAddress.get())); |
| 95 | + String clientIpAddress = req.getHeader(HttpHeaders.X_FORWARDED_FOR); |
| 96 | + if (clientIpAddress != null) { |
| 97 | + map.put(AttributeKey.HTTP_CLIENT_IP.getKey(), EventAttribute.setValue(clientIpAddress)); |
106 | 98 | }
|
107 | 99 |
|
108 |
| - Optional<String> httpScheme = |
109 |
| - Optional.ofNullable((String) req.getAttribute(AttributeKey.HTTP_SCHEME.getKey())); |
110 |
| - if (httpScheme.isPresent()) { |
111 |
| - map.put(AttributeKey.HTTP_SCHEME.getKey(), |
112 |
| - EventAttribute.setValue(httpScheme.get())); |
| 100 | + Object httpScheme = req.getAttribute(AttributeKey.HTTP_SCHEME.getKey()); |
| 101 | + if (httpScheme != null) { |
| 102 | + map.put(AttributeKey.HTTP_SCHEME.getKey(), EventAttribute.setValue((String) httpScheme)); |
113 | 103 | }
|
114 | 104 |
|
115 |
| - Optional<Integer> httpVersion = |
116 |
| - Optional.ofNullable((Integer) req.getAttribute(AttributeKey.HTTP_FLAVOR.getKey())); |
117 |
| - if (httpVersion.isPresent()) { |
118 |
| - map.put(AttributeKey.HTTP_FLAVOR.getKey(), |
119 |
| - EventAttribute.setValue(httpVersion.get())); |
| 105 | + Object httpVersion = req.getAttribute(AttributeKey.HTTP_FLAVOR.getKey()); |
| 106 | + if (httpVersion != null) { |
| 107 | + map.put(AttributeKey.HTTP_FLAVOR.getKey(), EventAttribute.setValue((Integer) httpVersion)); |
120 | 108 | }
|
121 |
| - |
122 | 109 | };
|
123 | 110 |
|
124 | 111 | public static final BiConsumer<Map<String, EventAttributeValue>, HttpResponse>
|
125 |
| - HTTP_RESPONSE_EVENT = |
126 |
| - (map, res) -> { |
127 |
| - int statusCode = res.getStatus(); |
128 |
| - if (res.getTargetHost() != null) { |
129 |
| - map.put(AttributeKey.HTTP_TARGET_HOST.getKey(), |
130 |
| - EventAttribute.setValue(res.getTargetHost())); |
131 |
| - } |
132 |
| - map.put(AttributeKey.HTTP_STATUS_CODE.getKey(), EventAttribute.setValue(statusCode)); |
133 |
| - }; |
| 112 | + HTTP_RESPONSE_EVENT = (map, res) -> { |
| 113 | + int statusCode = res.getStatus(); |
| 114 | + if (res.getTargetHost() != null) { |
| 115 | + map.put(AttributeKey.HTTP_TARGET_HOST.getKey(), |
| 116 | + EventAttribute.setValue(res.getTargetHost())); |
| 117 | + } |
| 118 | + map.put(AttributeKey.HTTP_STATUS_CODE.getKey(), EventAttribute.setValue(statusCode)); |
| 119 | + }; |
134 | 120 |
|
135 | 121 | public static final BiConsumer<Map<String, EventAttributeValue>, Throwable>
|
136 |
| - EXCEPTION = |
137 |
| - (map, t) -> { |
138 |
| - StringWriter sw = new StringWriter(); |
139 |
| - t.printStackTrace(new PrintWriter(sw)); |
| 122 | + EXCEPTION = (map, t) -> { |
| 123 | + StringWriter sw = new StringWriter(); |
| 124 | + t.printStackTrace(new PrintWriter(sw)); |
140 | 125 |
|
141 |
| - map.put(AttributeKey.EXCEPTION_TYPE.getKey(), |
142 |
| - EventAttribute.setValue(t.getClass().getName())); |
143 |
| - map.put(AttributeKey.EXCEPTION_STACKTRACE.getKey(), |
144 |
| - EventAttribute.setValue(sw.toString())); |
145 |
| - |
146 |
| - }; |
| 126 | + map.put(AttributeKey.EXCEPTION_TYPE.getKey(), |
| 127 | + EventAttribute.setValue(t.getClass().getName())); |
| 128 | + map.put(AttributeKey.EXCEPTION_STACKTRACE.getKey(), |
| 129 | + EventAttribute.setValue(sw.toString())); |
147 | 130 |
|
| 131 | + }; |
148 | 132 | }
|
0 commit comments