@bugsee/react-native 0.0.0-stage → 7.0.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +552 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +944 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.bugsee.library.Bugsee;
|
|
7
|
+
import com.bugsee.library.contracts.common.Callback1;
|
|
8
|
+
import com.bugsee.library.contracts.exchange.EventFilter;
|
|
9
|
+
import com.bugsee.library.contracts.exchange.LogEvent;
|
|
10
|
+
|
|
11
|
+
import java.util.ArrayList;
|
|
12
|
+
import java.util.List;
|
|
13
|
+
import java.util.concurrent.ConcurrentHashMap;
|
|
14
|
+
import java.util.concurrent.ScheduledFuture;
|
|
15
|
+
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
16
|
+
import java.util.concurrent.TimeUnit;
|
|
17
|
+
import java.util.concurrent.atomic.AtomicBoolean;
|
|
18
|
+
import java.util.concurrent.atomic.AtomicLong;
|
|
19
|
+
import java.util.concurrent.atomic.AtomicReference;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The app's log filter, as a round trip into JS.
|
|
23
|
+
*
|
|
24
|
+
* <p>Registered with {@link Bugsee#setLogEventFilter}, the method both SDKs
|
|
25
|
+
* actually install a log filter with. Android's {@code setLogFilter} is a
|
|
26
|
+
* deprecated alias of that method; calling the alias would not be a second
|
|
27
|
+
* filter, but it is not the method the 7.x SDK documents.
|
|
28
|
+
*
|
|
29
|
+
* <p>The native filter stays installed even when the app has no log callback.
|
|
30
|
+
* It drops a classified console echo and returns every other line at once,
|
|
31
|
+
* with no JS round trip. {@link #setEnabled}{@code (false)} does not remove
|
|
32
|
+
* it. While a user callback is installed, a missing sink still drops: that
|
|
33
|
+
* is the redaction boundary. A missing sink with no user callback is the
|
|
34
|
+
* pass-through, and the line is kept.
|
|
35
|
+
*
|
|
36
|
+
* <p>{@link #filter} returns without waiting. The SDK drops a line whose
|
|
37
|
+
* callback is never run, and at 10 seconds recycles the pooled entry. This
|
|
38
|
+
* bridge forgets the pending request at {@link #BORROW_MS}, strictly earlier,
|
|
39
|
+
* without calling the callback. A recycled entry can carry the same text, so
|
|
40
|
+
* a reply that still sees the original message must not {@code setMessage}
|
|
41
|
+
* or {@code callback.run} once that deadline has passed. A missing sink
|
|
42
|
+
* while the user filter is installed, a failed emit, or a {@code null} reply
|
|
43
|
+
* while {@code getMessage()} is still the original line and the deadline has
|
|
44
|
+
* not fired pass {@code null} to the SDK, which discards the line. Once the
|
|
45
|
+
* message is no longer that line, the bridge does not call {@code setMessage}
|
|
46
|
+
* or {@code callback.run}.
|
|
47
|
+
*/
|
|
48
|
+
final class LogFilterBridge {
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* What the module implements to emit {@code onLogFilterRequest}.
|
|
52
|
+
*/
|
|
53
|
+
interface Sink {
|
|
54
|
+
void onLogFilterRequest(@NonNull String requestId, @NonNull String line);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Arms the moment a pending request is forgotten. Injectable so tests control time. */
|
|
58
|
+
interface Cancellable {
|
|
59
|
+
void cancel();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Arms a request's deadline. Injectable so tests control time. */
|
|
63
|
+
interface Scheduler {
|
|
64
|
+
@NonNull
|
|
65
|
+
Cancellable schedule(@NonNull Runnable task, long delayMs);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Installs the native filter. Tests install nothing. */
|
|
69
|
+
interface Installer {
|
|
70
|
+
void install(@NonNull EventFilter<LogEvent> filter);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Strictly under {@code BugseeCaptureDataProviderLog}'s 10_000 ms
|
|
75
|
+
* recycle. The SDK posts that timeout before it calls the filter, so an
|
|
76
|
+
* equal delay fires after the entry is back in the pool. A pooled entry
|
|
77
|
+
* reused for another line with the same text still looks borrowed.
|
|
78
|
+
* Forgetting the pending here discards JS's answer; it does not pass
|
|
79
|
+
* the line through.
|
|
80
|
+
*/
|
|
81
|
+
static final long BORROW_MS = 9_000L;
|
|
82
|
+
|
|
83
|
+
private static final class Pending {
|
|
84
|
+
@NonNull final String id;
|
|
85
|
+
@NonNull final LogEvent event;
|
|
86
|
+
/** The line the SDK handed us. A later {@code getMessage()} that differs means the entry was recycled. */
|
|
87
|
+
@NonNull final String original;
|
|
88
|
+
@NonNull final Callback1<LogEvent> callback;
|
|
89
|
+
@NonNull final Sink owner;
|
|
90
|
+
@Nullable Cancellable deadline;
|
|
91
|
+
|
|
92
|
+
Pending(
|
|
93
|
+
@NonNull final String id,
|
|
94
|
+
@NonNull final LogEvent event,
|
|
95
|
+
@NonNull final String original,
|
|
96
|
+
@NonNull final Callback1<LogEvent> callback,
|
|
97
|
+
@NonNull final Sink owner
|
|
98
|
+
) {
|
|
99
|
+
this.id = id;
|
|
100
|
+
this.event = event;
|
|
101
|
+
this.original = original;
|
|
102
|
+
this.callback = callback;
|
|
103
|
+
this.owner = owner;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private static final LogFilterBridge SHARED = new LogFilterBridge();
|
|
108
|
+
|
|
109
|
+
@NonNull
|
|
110
|
+
static LogFilterBridge shared() {
|
|
111
|
+
return SHARED;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private final Scheduler scheduler;
|
|
115
|
+
private final ConsoleEchoDedup echoes;
|
|
116
|
+
private final Installer installer;
|
|
117
|
+
private final AtomicReference<Sink> sink = new AtomicReference<>();
|
|
118
|
+
private final ConcurrentHashMap<String, Pending> pending = new ConcurrentHashMap<>();
|
|
119
|
+
private final AtomicLong ids = new AtomicLong();
|
|
120
|
+
/** True only while the app has a log callback. False is the native pass-through. */
|
|
121
|
+
private final AtomicBoolean userFilter = new AtomicBoolean();
|
|
122
|
+
|
|
123
|
+
/** Production: one daemon thread forgets pending requests at {@link #BORROW_MS}. */
|
|
124
|
+
private LogFilterBridge() {
|
|
125
|
+
this(new DaemonScheduler(), System::currentTimeMillis, Bugsee::setLogEventFilter);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Tests pass a scheduler they fire themselves. They do not touch {@link Bugsee}. */
|
|
129
|
+
LogFilterBridge(@NonNull final Scheduler scheduler) {
|
|
130
|
+
this(scheduler, System::currentTimeMillis, filter -> { });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Tests pass a clock so an echo claim can expire without waiting. */
|
|
134
|
+
LogFilterBridge(@NonNull final Scheduler scheduler, @NonNull final ConsoleEchoDedup.Clock clock) {
|
|
135
|
+
this(scheduler, clock, filter -> { });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private LogFilterBridge(
|
|
139
|
+
@NonNull final Scheduler scheduler,
|
|
140
|
+
@NonNull final ConsoleEchoDedup.Clock clock,
|
|
141
|
+
@NonNull final Installer installer
|
|
142
|
+
) {
|
|
143
|
+
this.scheduler = scheduler;
|
|
144
|
+
this.echoes = new ConsoleEchoDedup(clock);
|
|
145
|
+
this.installer = installer;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private final EventFilter<LogEvent> filter = new EventFilter<LogEvent>() {
|
|
149
|
+
@Override
|
|
150
|
+
public void filter(
|
|
151
|
+
@NonNull final LogEvent event,
|
|
152
|
+
@NonNull final Callback1<LogEvent> callback
|
|
153
|
+
) {
|
|
154
|
+
try {
|
|
155
|
+
route(event, callback);
|
|
156
|
+
} catch (final Throwable e) {
|
|
157
|
+
// The SDK rethrows a filter exception, which on the wrapper
|
|
158
|
+
// channel's thread is a crash. Drop the line instead.
|
|
159
|
+
drop(callback);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
void attach(@NonNull final Sink next) {
|
|
165
|
+
sink.set(next);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Drops every request this sink was asked. A reload can attach the new
|
|
170
|
+
* module first; the sink is cleared only when {@code current} is still
|
|
171
|
+
* it, but {@code current}'s pending entries are always removed. The
|
|
172
|
+
* callback is run with {@code null} only while the entry is still the
|
|
173
|
+
* SDK's live borrow. After the entry has been recycled, the pending is
|
|
174
|
+
* forgotten and the callback is not touched.
|
|
175
|
+
*/
|
|
176
|
+
void detach(@NonNull final Sink current) {
|
|
177
|
+
sink.compareAndSet(current, null);
|
|
178
|
+
final List<Pending> owned = new ArrayList<>();
|
|
179
|
+
for (final Pending item : pending.values()) {
|
|
180
|
+
if (item.owner == current && pending.remove(item.id, item)) {
|
|
181
|
+
owned.add(item);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
for (final Pending item : owned) {
|
|
185
|
+
cancel(item.deadline);
|
|
186
|
+
if (stillBorrowed(item)) {
|
|
187
|
+
drop(item.callback);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Turns the JS round trip on or off. The native filter stays installed
|
|
194
|
+
* either way: off is the pass-through, which drops an echo and returns
|
|
195
|
+
* every other line. It does not pass {@code null} to
|
|
196
|
+
* {@link Bugsee#setLogEventFilter}.
|
|
197
|
+
*/
|
|
198
|
+
void setEnabled(final boolean enabled) {
|
|
199
|
+
userFilter.set(enabled);
|
|
200
|
+
ensureInstalled();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Puts the native filter back if a launch replaced it. Does not change
|
|
205
|
+
* whether the user callback is asked.
|
|
206
|
+
*/
|
|
207
|
+
void ensureInstalled() {
|
|
208
|
+
installer.install(filter);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Applies JS's answer. {@code null} drops the line, while the entry is
|
|
213
|
+
* still the one the SDK lent us. A string is written onto that event and
|
|
214
|
+
* the same event is returned, so the level and the timestamp stay. If
|
|
215
|
+
* the event ignores {@code setMessage} (the interface default is a
|
|
216
|
+
* no-op), the line is dropped rather than kept unredacted.
|
|
217
|
+
*
|
|
218
|
+
* <p>If {@code getMessage()} is no longer the original line, the pooled
|
|
219
|
+
* entry has been recycled. This returns without {@code setMessage} and
|
|
220
|
+
* without {@code callback.run}: either would land on whatever line owns
|
|
221
|
+
* the entry now.
|
|
222
|
+
*/
|
|
223
|
+
void reply(@NonNull final String requestId, @Nullable final String line) {
|
|
224
|
+
final Pending item = pending.remove(requestId);
|
|
225
|
+
if (item == null) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
cancel(item.deadline);
|
|
229
|
+
if (!stillBorrowed(item)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (line == null) {
|
|
233
|
+
drop(item.callback);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
item.event.setMessage(line);
|
|
237
|
+
if (!line.equals(item.event.getMessage())) {
|
|
238
|
+
drop(item.callback);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
item.callback.run(item.event);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* The console patch calls this before the original hook writes logcat.
|
|
246
|
+
* A later {@code ReactNativeJS} line with this text is the echo and is
|
|
247
|
+
* dropped in {@link #route}. A {@code Bugsee.log} of the same text is
|
|
248
|
+
* {@code Custom} and does not arm another drop.
|
|
249
|
+
*
|
|
250
|
+
* <p>Only a credit noted before the write can drop the echo: the SDK's
|
|
251
|
+
* logcat reader filters on its own thread, and an un-noted
|
|
252
|
+
* {@code ReactNativeJS} line is kept. {@code BugseeModule.noteConsoleEcho}
|
|
253
|
+
* returns a value so codegen runs it on the JS thread, ahead of the write.
|
|
254
|
+
*/
|
|
255
|
+
void noteEcho(@Nullable final String message) {
|
|
256
|
+
echoes.note(message);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* One log event from the SDK. A logcat line tagged {@code ReactNativeJS}
|
|
261
|
+
* whose text was noted by {@link #noteEcho} is the console echo: it is
|
|
262
|
+
* dropped here, before JS is asked, so the user's filter runs once. The
|
|
263
|
+
* credit is consumed. With no user callback, every other line is returned
|
|
264
|
+
* immediately. With a user callback, those lines are asked. A missing
|
|
265
|
+
* sink on that path still drops.
|
|
266
|
+
*/
|
|
267
|
+
void route(
|
|
268
|
+
@NonNull final LogEvent event,
|
|
269
|
+
@NonNull final Callback1<LogEvent> callback
|
|
270
|
+
) {
|
|
271
|
+
if (echoes.dropEcho(event.getLogSource(), event.getTag(), event.getMessage())) {
|
|
272
|
+
drop(callback);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (!userFilter.get()) {
|
|
276
|
+
keep(callback, event);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
ask(event, callback);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
void ask(
|
|
283
|
+
@NonNull final LogEvent event,
|
|
284
|
+
@NonNull final Callback1<LogEvent> callback
|
|
285
|
+
) {
|
|
286
|
+
final String line = event.getMessage();
|
|
287
|
+
final Sink current = sink.get();
|
|
288
|
+
if (line == null || current == null) {
|
|
289
|
+
drop(callback);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
final String id = Long.toString(ids.incrementAndGet());
|
|
293
|
+
final Pending item = new Pending(id, event, line, callback, current);
|
|
294
|
+
pending.put(id, item);
|
|
295
|
+
try {
|
|
296
|
+
item.deadline = scheduler.schedule(() -> forget(id), BORROW_MS);
|
|
297
|
+
current.onLogFilterRequest(id, line);
|
|
298
|
+
} catch (final Throwable e) {
|
|
299
|
+
if (pending.remove(id, item)) {
|
|
300
|
+
cancel(item.deadline);
|
|
301
|
+
drop(callback);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* The SDK has recycled the entry, or is about to. Forget the request and
|
|
308
|
+
* do not call the callback: calling it would pass the original line
|
|
309
|
+
* through, or touch an entry that now belongs to another line.
|
|
310
|
+
*/
|
|
311
|
+
private void forget(@NonNull final String id) {
|
|
312
|
+
pending.remove(id);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** The entry is still the SDK's borrow of the line we were asked to filter. */
|
|
316
|
+
private static boolean stillBorrowed(@NonNull final Pending item) {
|
|
317
|
+
try {
|
|
318
|
+
return item.original.equals(item.event.getMessage());
|
|
319
|
+
} catch (final Throwable ignored) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
private static void cancel(@Nullable final Cancellable deadline) {
|
|
325
|
+
if (deadline == null) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
try {
|
|
329
|
+
deadline.cancel();
|
|
330
|
+
} catch (final Throwable ignored) {
|
|
331
|
+
// A timer that cannot be cancelled still only forgets the pending.
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
private static void drop(@NonNull final Callback1<LogEvent> callback) {
|
|
336
|
+
try {
|
|
337
|
+
callback.run(null);
|
|
338
|
+
} catch (final Throwable ignored) {
|
|
339
|
+
// The SDK already treats a throw from the callback as a drop.
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** The native pass-through. The line is kept. This is not a drop. */
|
|
344
|
+
private static void keep(
|
|
345
|
+
@NonNull final Callback1<LogEvent> callback,
|
|
346
|
+
@NonNull final LogEvent event
|
|
347
|
+
) {
|
|
348
|
+
try {
|
|
349
|
+
callback.run(event);
|
|
350
|
+
} catch (final Throwable ignored) {
|
|
351
|
+
// The SDK already has the line. A throw here must not replace it.
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** One daemon thread, started on first use, for every request's deadline. */
|
|
356
|
+
private static final class DaemonScheduler implements Scheduler {
|
|
357
|
+
private final ScheduledThreadPoolExecutor executor;
|
|
358
|
+
|
|
359
|
+
DaemonScheduler() {
|
|
360
|
+
executor = new ScheduledThreadPoolExecutor(1, runnable -> {
|
|
361
|
+
final Thread thread = new Thread(runnable, "BugseeRN-LogFilterDeadline");
|
|
362
|
+
thread.setDaemon(true);
|
|
363
|
+
return thread;
|
|
364
|
+
});
|
|
365
|
+
executor.setRemoveOnCancelPolicy(true);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
@Override
|
|
369
|
+
@NonNull
|
|
370
|
+
public Cancellable schedule(@NonNull final Runnable task, final long delayMs) {
|
|
371
|
+
final ScheduledFuture<?> future = executor.schedule(task, delayMs, TimeUnit.MILLISECONDS);
|
|
372
|
+
return () -> future.cancel(false);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
package com.bugsee.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.bugsee.library.contracts.exchange.NetworkEvent;
|
|
7
|
+
|
|
8
|
+
import org.json.JSONException;
|
|
9
|
+
import org.json.JSONObject;
|
|
10
|
+
|
|
11
|
+
import java.util.HashMap;
|
|
12
|
+
import java.util.Iterator;
|
|
13
|
+
import java.util.Map;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Builds a network event the app recorded itself and hands it to the SDK.
|
|
17
|
+
*
|
|
18
|
+
* <p>The timestamp is stamped here. The event comes from the exchange factory
|
|
19
|
+
* the caller supplies (production: {@code Bugsee.getExchangeFactory()}), then
|
|
20
|
+
* goes back with filtering required so an installed network filter still sees
|
|
21
|
+
* it. A missing factory or a null event is {@link Outcome#NO_EVENT}; the
|
|
22
|
+
* caller logs {@code addNetworkEvent dropped: the SDK made no event} and does
|
|
23
|
+
* not invent a timeout that would pass the event through.
|
|
24
|
+
*
|
|
25
|
+
* <p>This class does not call {@code Bugsee.getLaunchOptions()}, so a plain
|
|
26
|
+
* JVM test can drive it.
|
|
27
|
+
*/
|
|
28
|
+
final class NetworkEvents {
|
|
29
|
+
|
|
30
|
+
enum Outcome {
|
|
31
|
+
ADDED,
|
|
32
|
+
NO_EVENT,
|
|
33
|
+
REJECTED
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The SDK exchange factory's {@code createNetworkEvent}. */
|
|
37
|
+
interface Factory {
|
|
38
|
+
@Nullable
|
|
39
|
+
NetworkEvent create(
|
|
40
|
+
long timestamp,
|
|
41
|
+
@NonNull NetworkEvent.NetworkEventStage stage,
|
|
42
|
+
@Nullable String eventId,
|
|
43
|
+
@Nullable String mechanism,
|
|
44
|
+
@Nullable String method
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** {@code Bugsee.addNetworkEvent(event, requiresFiltering)}. */
|
|
49
|
+
interface Recorder {
|
|
50
|
+
void add(@NonNull NetworkEvent event, boolean requiresFiltering);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface Clock {
|
|
54
|
+
long now();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** What the bundle's network events say this wrapper recorded them as. */
|
|
58
|
+
static final String MECHANISM = "react-native";
|
|
59
|
+
|
|
60
|
+
private NetworkEvents() {
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@NonNull
|
|
64
|
+
static Outcome record(
|
|
65
|
+
@Nullable final String eventJson,
|
|
66
|
+
@Nullable final Factory factory,
|
|
67
|
+
@NonNull final Recorder recorder,
|
|
68
|
+
@NonNull final Clock clock
|
|
69
|
+
) {
|
|
70
|
+
final JSONObject object;
|
|
71
|
+
try {
|
|
72
|
+
object = new JSONObject(eventJson);
|
|
73
|
+
} catch (final JSONException e) {
|
|
74
|
+
return Outcome.REJECTED;
|
|
75
|
+
}
|
|
76
|
+
final String url = stringOrNull(object, "url");
|
|
77
|
+
final String method = stringOrNull(object, "method");
|
|
78
|
+
if (url == null || method == null) {
|
|
79
|
+
return Outcome.REJECTED;
|
|
80
|
+
}
|
|
81
|
+
final NetworkEvent.NetworkEventStage stage = stageOf(stringOrAbsent(object, "stage"));
|
|
82
|
+
if (stage == null) {
|
|
83
|
+
return Outcome.REJECTED;
|
|
84
|
+
}
|
|
85
|
+
if (!fieldsAreWritable(object)) {
|
|
86
|
+
return Outcome.REJECTED;
|
|
87
|
+
}
|
|
88
|
+
if (factory == null) {
|
|
89
|
+
return Outcome.NO_EVENT;
|
|
90
|
+
}
|
|
91
|
+
final NetworkEvent event;
|
|
92
|
+
try {
|
|
93
|
+
event = factory.create(clock.now(), stage, stringOrAbsent(object, "id"), MECHANISM, method);
|
|
94
|
+
} catch (final Throwable e) {
|
|
95
|
+
return Outcome.NO_EVENT;
|
|
96
|
+
}
|
|
97
|
+
if (event == null) {
|
|
98
|
+
return Outcome.NO_EVENT;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
apply(event, object, url);
|
|
102
|
+
} catch (final Throwable e) {
|
|
103
|
+
return Outcome.REJECTED;
|
|
104
|
+
}
|
|
105
|
+
// Filtering is required. An installed setNetworkFilter must see this
|
|
106
|
+
// event. Never pass false.
|
|
107
|
+
recorder.add(event, true);
|
|
108
|
+
return Outcome.ADDED;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* {@code completed} is the name JS and the device test use. The SDK's
|
|
113
|
+
* own {@code toString} for that stage is {@code complete}.
|
|
114
|
+
*/
|
|
115
|
+
@Nullable
|
|
116
|
+
static NetworkEvent.NetworkEventStage stageOf(@Nullable final String name) {
|
|
117
|
+
if (name == null || "completed".equals(name) || "complete".equals(name)) {
|
|
118
|
+
return NetworkEvent.NetworkEventStage.RequestCompleted;
|
|
119
|
+
}
|
|
120
|
+
final String wire;
|
|
121
|
+
if ("started".equals(name)) {
|
|
122
|
+
wire = "before";
|
|
123
|
+
} else if ("aborted".equals(name) || "cancel".equals(name)) {
|
|
124
|
+
wire = "abort";
|
|
125
|
+
} else if ("timings".equals(name)) {
|
|
126
|
+
wire = "timing";
|
|
127
|
+
} else {
|
|
128
|
+
wire = name;
|
|
129
|
+
}
|
|
130
|
+
return NetworkEvent.NetworkEventStage.fromString(wire, null);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private static boolean fieldsAreWritable(@NonNull final JSONObject object) {
|
|
134
|
+
if (object.has("body") && !isStringOrNull(object, "body")) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
if (object.has("statusText") && !isStringOrNull(object, "statusText")) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
if (object.has("errorDescription") && !isStringOrNull(object, "errorDescription")) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
if (object.has("errorShortMessage") && !isStringOrNull(object, "errorShortMessage")) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (object.has("id") && !isStringOrNull(object, "id")) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
if (object.has("responseCode") && !(object.opt("responseCode") instanceof Number)) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
if (!object.has("headers") || object.isNull("headers")) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
final Object headers = object.opt("headers");
|
|
156
|
+
if (!(headers instanceof JSONObject)) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
final JSONObject map = (JSONObject) headers;
|
|
160
|
+
final Iterator<String> keys = map.keys();
|
|
161
|
+
while (keys.hasNext()) {
|
|
162
|
+
final String key = keys.next();
|
|
163
|
+
if (!(map.opt(key) instanceof String)) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private static void apply(
|
|
171
|
+
@NonNull final NetworkEvent event,
|
|
172
|
+
@NonNull final JSONObject object,
|
|
173
|
+
@NonNull final String url
|
|
174
|
+
) throws JSONException {
|
|
175
|
+
event.setUrl(url);
|
|
176
|
+
if (object.has("body")) {
|
|
177
|
+
event.setBody(stringOrNull(object, "body"));
|
|
178
|
+
}
|
|
179
|
+
if (object.has("statusText")) {
|
|
180
|
+
event.setStatusText(stringOrNull(object, "statusText"));
|
|
181
|
+
}
|
|
182
|
+
if (object.has("errorDescription")) {
|
|
183
|
+
event.setErrorDescription(stringOrNull(object, "errorDescription"));
|
|
184
|
+
}
|
|
185
|
+
if (object.has("errorShortMessage")) {
|
|
186
|
+
event.setErrorShortMessage(stringOrNull(object, "errorShortMessage"));
|
|
187
|
+
}
|
|
188
|
+
if (object.has("responseCode")) {
|
|
189
|
+
event.setResponseCode(object.getInt("responseCode"));
|
|
190
|
+
}
|
|
191
|
+
if (object.has("headers") && !object.isNull("headers")) {
|
|
192
|
+
final JSONObject headers = object.getJSONObject("headers");
|
|
193
|
+
final Map<String, String> map = new HashMap<>();
|
|
194
|
+
final Iterator<String> keys = headers.keys();
|
|
195
|
+
while (keys.hasNext()) {
|
|
196
|
+
final String key = keys.next();
|
|
197
|
+
map.put(key, headers.getString(key));
|
|
198
|
+
}
|
|
199
|
+
event.setHeaders(map);
|
|
200
|
+
} else if (object.has("headers")) {
|
|
201
|
+
event.setHeaders(null);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private static boolean isStringOrNull(@NonNull final JSONObject object, @NonNull final String key) {
|
|
206
|
+
return object.isNull(key) || object.opt(key) instanceof String;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@Nullable
|
|
210
|
+
private static String stringOrNull(@NonNull final JSONObject object, @NonNull final String key) {
|
|
211
|
+
if (!object.has(key) || object.isNull(key)) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
final Object value = object.opt(key);
|
|
215
|
+
return value instanceof String ? (String) value : null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** A present string, or null when the key was left out. A JSON null is null. */
|
|
219
|
+
@Nullable
|
|
220
|
+
private static String stringOrAbsent(@NonNull final JSONObject object, @NonNull final String key) {
|
|
221
|
+
if (!object.has(key) || object.isNull(key)) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
final Object value = object.opt(key);
|
|
225
|
+
return value instanceof String ? (String) value : null;
|
|
226
|
+
}
|
|
227
|
+
}
|