├── .github └── workflows │ └── build.yml ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build.gradle ├── build.xml ├── docs ├── building.md ├── concepts.md ├── example.md ├── installing.md ├── internals.md ├── licenses │ └── HEADER.txt ├── pics │ ├── OpenKit - State diagram.xml │ ├── OpenKit-BeaconCache.svg │ ├── OpenKit-BeaconCache.xml │ └── OpenKit-state_diagram.svg ├── supported_versions.md └── upgrade_guide.md ├── generate_javadoc.bat ├── gradle ├── coverage.gradle ├── license.gradle ├── publish.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── samples └── SimpleSample.java ├── settings.gradle ├── src ├── main │ └── java │ │ └── com │ │ └── dynatrace │ │ └── openkit │ │ ├── CrashReportingLevel.java │ │ ├── DataCollectionLevel.java │ │ ├── DynatraceOpenKitBuilder.java │ │ ├── api │ │ ├── Action.java │ │ ├── ConnectionType.java │ │ ├── LogLevel.java │ │ ├── Logger.java │ │ ├── OpenKit.java │ │ ├── OpenKitConstants.java │ │ ├── RootAction.java │ │ ├── SSLTrustManager.java │ │ ├── Session.java │ │ ├── WebRequestTracer.java │ │ └── http │ │ │ ├── HttpRequest.java │ │ │ ├── HttpRequestInterceptor.java │ │ │ ├── HttpResponse.java │ │ │ └── HttpResponseInterceptor.java │ │ ├── core │ │ ├── BeaconSender.java │ │ ├── SessionWatchdog.java │ │ ├── SessionWatchdogContext.java │ │ ├── caching │ │ │ ├── BeaconCache.java │ │ │ ├── BeaconCacheEntry.java │ │ │ ├── BeaconCacheEvictionStrategy.java │ │ │ ├── BeaconCacheEvictor.java │ │ │ ├── BeaconCacheImpl.java │ │ │ ├── BeaconCacheRecord.java │ │ │ ├── BeaconKey.java │ │ │ ├── SpaceEvictionStrategy.java │ │ │ └── TimeEvictionStrategy.java │ │ ├── communication │ │ │ ├── AbstractBeaconSendingState.java │ │ │ ├── BeaconSendingCaptureOffState.java │ │ │ ├── BeaconSendingCaptureOnState.java │ │ │ ├── BeaconSendingContext.java │ │ │ ├── BeaconSendingFlushSessionsState.java │ │ │ ├── BeaconSendingInitState.java │ │ │ ├── BeaconSendingRequestUtil.java │ │ │ ├── BeaconSendingResponseUtil.java │ │ │ └── BeaconSendingTerminalState.java │ │ ├── configuration │ │ │ ├── BeaconCacheConfiguration.java │ │ │ ├── BeaconConfiguration.java │ │ │ ├── ConfigurationDefaults.java │ │ │ ├── HTTPClientConfiguration.java │ │ │ ├── OpenKitConfiguration.java │ │ │ ├── PrivacyConfiguration.java │ │ │ ├── ServerConfiguration.java │ │ │ └── ServerConfigurationUpdateCallback.java │ │ ├── objects │ │ │ ├── BaseActionImpl.java │ │ │ ├── CancelableOpenKitObject.java │ │ │ ├── EventPayloadAttributes.java │ │ │ ├── EventPayloadBuilder.java │ │ │ ├── LeafActionImpl.java │ │ │ ├── NullAction.java │ │ │ ├── NullRootAction.java │ │ │ ├── NullSession.java │ │ │ ├── NullWebRequestTracer.java │ │ │ ├── OpenKitComposite.java │ │ │ ├── OpenKitImpl.java │ │ │ ├── OpenKitInitializer.java │ │ │ ├── OpenKitInitializerImpl.java │ │ │ ├── OpenKitObject.java │ │ │ ├── RootActionImpl.java │ │ │ ├── SessionCreator.java │ │ │ ├── SessionCreatorImpl.java │ │ │ ├── SessionCreatorInput.java │ │ │ ├── SessionImpl.java │ │ │ ├── SessionProxyImpl.java │ │ │ ├── SessionState.java │ │ │ ├── SupplementaryBasicData.java │ │ │ ├── SupplementaryBasicDataImpl.java │ │ │ ├── WebRequestTracerBaseImpl.java │ │ │ ├── WebRequestTracerStringURL.java │ │ │ └── WebRequestTracerURLConnection.java │ │ └── util │ │ │ ├── CrashFormatter.java │ │ │ ├── DefaultLogger.java │ │ │ ├── EventPayloadBuilderUtil.java │ │ │ ├── InetAddressValidator.java │ │ │ ├── PercentEncoder.java │ │ │ └── StringUtil.java │ │ ├── protocol │ │ ├── AdditionalQueryParameters.java │ │ ├── Beacon.java │ │ ├── BeaconInitializer.java │ │ ├── EventType.java │ │ ├── HTTPClient.java │ │ ├── JsonResponseParser.java │ │ ├── KeyValueResponseParser.java │ │ ├── ProtocolConstants.java │ │ ├── ResponseAttribute.java │ │ ├── ResponseAttributes.java │ │ ├── ResponseAttributesDefaults.java │ │ ├── ResponseAttributesImpl.java │ │ ├── ResponseParser.java │ │ ├── SerializableBeaconValue.java │ │ ├── StatusResponse.java │ │ ├── http │ │ │ ├── HttpRequestHttpURLConnectionAdapter.java │ │ │ ├── HttpResponseHttpURLConnectionAdapter.java │ │ │ ├── NullHttpRequestInterceptor.java │ │ │ └── NullHttpResponseInterceptor.java │ │ └── ssl │ │ │ ├── SSLBlindTrustManager.java │ │ │ └── SSLStrictTrustManager.java │ │ ├── providers │ │ ├── DefaultHTTPClientProvider.java │ │ ├── DefaultRandomNumberGenerator.java │ │ ├── DefaultSessionIDProvider.java │ │ ├── DefaultThreadIDProvider.java │ │ ├── DefaultTimingProvider.java │ │ ├── FixedRandomNumberGenerator.java │ │ ├── FixedSessionIdProvider.java │ │ ├── HTTPClientProvider.java │ │ ├── HttpURLConnectionWrapper.java │ │ ├── RandomNumberGenerator.java │ │ ├── SessionIDProvider.java │ │ ├── ThreadIDProvider.java │ │ └── TimingProvider.java │ │ └── util │ │ └── json │ │ ├── JSONParser.java │ │ ├── constants │ │ └── JSONLiterals.java │ │ ├── lexer │ │ ├── JSONLexer.java │ │ ├── JSONToken.java │ │ └── LexerException.java │ │ ├── objects │ │ ├── JSONArrayValue.java │ │ ├── JSONBooleanValue.java │ │ ├── JSONNullValue.java │ │ ├── JSONNumberValue.java │ │ ├── JSONObjectValue.java │ │ ├── JSONOutputConfig.java │ │ ├── JSONStringValue.java │ │ ├── JSONValue.java │ │ └── JSONValueWriter.java │ │ └── parser │ │ ├── JSONParserState.java │ │ └── ParserException.java ├── test │ └── java │ │ └── com │ │ └── dynatrace │ │ └── openkit │ │ ├── CrashReportingLevelTest.java │ │ ├── DataCollectionLevelTest.java │ │ ├── DynatraceOpenKitBuilderTest.java │ │ ├── core │ │ ├── SessionWatchdogContextTest.java │ │ ├── SessionWatchdogTest.java │ │ ├── caching │ │ │ ├── BeaconCacheEntryTest.java │ │ │ ├── BeaconCacheEvictorTest.java │ │ │ ├── BeaconCacheImplTest.java │ │ │ ├── BeaconCacheRecordTest.java │ │ │ ├── BeaconKeyTest.java │ │ │ ├── SpaceEvictionStrategyTest.java │ │ │ └── TimeEvictionStrategyTest.java │ │ ├── communication │ │ │ ├── AbstractBeaconSendingStateTest.java │ │ │ ├── BeaconSendingCaptureOffStateTest.java │ │ │ ├── BeaconSendingCaptureOnStateTest.java │ │ │ ├── BeaconSendingContextTest.java │ │ │ ├── BeaconSendingFlushSessionsStateTest.java │ │ │ ├── BeaconSendingInitStateTest.java │ │ │ ├── BeaconSendingRequestUtilTest.java │ │ │ ├── BeaconSendingResponseUtilTest.java │ │ │ └── BeaconSendingTerminalStateTest.java │ │ ├── configuration │ │ │ ├── BeaconCacheConfigurationTest.java │ │ │ ├── BeaconConfigurationTest.java │ │ │ ├── HttpClientConfigurationTest.java │ │ │ ├── OpenKitConfigurationTest.java │ │ │ ├── PrivacyConfigurationTest.java │ │ │ └── ServerConfigurationTest.java │ │ ├── objects │ │ │ ├── BaseActionImplTest.java │ │ │ ├── EventPayloadBuilderTest.java │ │ │ ├── LeafActionImplTest.java │ │ │ ├── NullActionTest.java │ │ │ ├── NullRootActionTest.java │ │ │ ├── NullSessionTest.java │ │ │ ├── NullWebRequestTracerTest.java │ │ │ ├── OpenKitImplTest.java │ │ │ ├── OpenKitInitializerImplTest.java │ │ │ ├── RootActionImplTest.java │ │ │ ├── SessionCreatorImplTest.java │ │ │ ├── SessionImplTest.java │ │ │ ├── SessionProxyImplTest.java │ │ │ ├── WebRequestTracerBaseImplTest.java │ │ │ ├── WebRequestTracerStringURLTest.java │ │ │ └── WebRequestTracerURLConnectionTest.java │ │ └── util │ │ │ ├── CrashFormatterTest.java │ │ │ ├── DefaultLoggerTest.java │ │ │ ├── InetAddressValidatorTest.java │ │ │ ├── PercentEncoderTest.java │ │ │ └── StringUtilTest.java │ │ ├── protocol │ │ ├── BeaconTest.java │ │ ├── EventPayloadMatcher.java │ │ ├── EventTypeTest.java │ │ ├── HTTPClientTest.java │ │ ├── JsonResponseParserTest.java │ │ ├── KeyValueResponseParserTest.java │ │ ├── ResponseAttributesDefaultsTest.java │ │ ├── ResponseAttributesImplTest.java │ │ ├── ResponseParserTest.java │ │ ├── StatusResponseTest.java │ │ └── http │ │ │ ├── HttpRequestHttpURLConnectionAdapterTest.java │ │ │ ├── HttpResponseHttpURLConnectionAdapterTest.java │ │ │ ├── NullHttpRequestInterceptorTest.java │ │ │ └── NullHttpResponseInterceptorTest.java │ │ ├── providers │ │ ├── DefaultHttpClientProviderTest.java │ │ ├── DefaultRandomNumberGeneratorTest.java │ │ ├── DefaultSessionIDProviderTest.java │ │ ├── DefaultThreadIDProviderTest.java │ │ ├── DefaultTimingProviderTest.java │ │ ├── FixedRandomNumberGeneratorTest.java │ │ └── FixedSessionIdProviderTest.java │ │ └── util │ │ └── json │ │ ├── JSONParserTest.java │ │ ├── lexer │ │ ├── JSONLexerTest.java │ │ └── JSONTokenTest.java │ │ └── objects │ │ ├── JSONArrayValueTest.java │ │ ├── JSONBooleanValueTest.java │ │ ├── JSONNullValueTest.java │ │ ├── JSONNumberValueTest.java │ │ ├── JSONObjectValueTest.java │ │ ├── JSONStringValueTest.java │ │ ├── JSONValueTest.java │ │ └── JSONValueWriterTest.java └── test7 │ └── java │ └── com │ └── dynatrace │ └── openkit │ ├── core │ ├── SessionWatchdogContextTest.java │ ├── SessionWatchdogTest.java │ ├── caching │ │ ├── BeaconCacheEvictorTest.java │ │ ├── BeaconCacheImplTest.java │ │ ├── SpaceEvictionStrategyTest.java │ │ └── TimeEvictionStrategyTest.java │ ├── communication │ │ ├── AbstractBeaconSendingStateTest.java │ │ ├── BeaconSendingCaptureOffStateTest.java │ │ ├── BeaconSendingCaptureOnStateTest.java │ │ ├── BeaconSendingContextTest.java │ │ ├── BeaconSendingFlushSessionsStateTest.java │ │ ├── BeaconSendingInitStateTest.java │ │ └── BeaconSendingRequestUtilTest.java │ ├── configuration │ │ └── BeaconConfigurationTest.java │ └── objects │ │ ├── BaseActionImplTest.java │ │ ├── NullActionTest.java │ │ ├── OpenKitImplTest.java │ │ ├── RootActionImplTest.java │ │ ├── SessionCreatorImplTest.java │ │ ├── SessionImplTest.java │ │ ├── SessionProxyImplTest.java │ │ ├── WebRequestTracerBaseImplTest.java │ │ └── WebRequestTracerURLConnectionTest.java │ ├── protocol │ ├── BeaconTest.java │ ├── EventPayloadMatcher.java │ ├── HTTPClientTest.java │ ├── ResponseAttributesImplTest.java │ └── http │ │ ├── HttpRequestHttpURLConnectionAdapterTest.java │ │ ├── NullHttpRequestInterceptorTest.java │ │ └── NullHttpResponseInterceptorTest.java │ └── util │ └── json │ ├── lexer │ └── JSONLexerTest.java │ └── objects │ ├── JSONArrayValueTest.java │ └── JSONObjectValueTest.java └── version.properties /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build & Test 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | build: 12 | 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | java: [ '8', '11', '17' ] 17 | name: Java ${{ matrix.Java }} Build 18 | 19 | steps: 20 | - uses: actions/checkout@v3 21 | - name: Setup Java 22 | uses: actions/setup-java@v3 23 | with: 24 | java-version: ${{ matrix.java }} 25 | distribution: 'temurin' 26 | - name: Build with Gradle 27 | uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 28 | with: 29 | arguments: build 30 | 31 | coverage: 32 | needs: build 33 | runs-on: ubuntu-latest 34 | 35 | steps: 36 | - uses: actions/checkout@v3 37 | - name: Setup Java 38 | uses: actions/setup-java@v3 39 | with: 40 | java-version: 8 41 | distribution: 'temurin' 42 | - name: Code Coverage 43 | env: 44 | COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} 45 | run: ./gradlew test jacocoTestReport coverallsJacoco -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # folders 2 | .gradle/ 3 | .idea/ 4 | .metadata/ 5 | .settings/ 6 | .qbcache/ 7 | .recommenders/ 8 | .shelf/ 9 | bin/ 10 | build/ 11 | javadoc/ 12 | out/ 13 | .vs/ 14 | 15 | # files 16 | .classpath 17 | .project 18 | *.iml 19 | *.ipr 20 | *.iws 21 | *.orig 22 | *.launch 23 | *.log 24 | *-ide-plugin.xml 25 | .DS_Store 26 | **/.DS_Store 27 | 28 | #excludes 29 | !**/src/*/resources/** 30 | !**/src/*/java/** 31 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Dynatrace OpenKit 2 | Welcome, and thank you for your interest in contributing to Dynatrace OpenKit! 3 | 4 | There are many ways in which you can contribute, beyond writing code. In this document you will find a high level 5 | overview how you can contribute. 6 | 7 | Before making your first contribution, please read our [Code of Conduct][code_of_conduct]. 8 | 9 | ## Having questions? 10 | Your comments, feedback and questions are welcome, and we, the development team, provide answers on multiple channels. 11 | 12 | If you do not have access to Dynatrace internal Slack, search for tickets on [GitHub issues][gh-issues] or report new ones. 13 | If you do have access to Dynatrace internal Slack, you can use the public channel `#team-openkit` for questions. 14 | 15 | ## Reporting Issues 16 | ### Security issues 17 | In case you found a security issue, please do not file a public ticket, but rather contact us directly 18 | via [openkit@dynatrace.com][mail] and send us your findings. 19 | 20 | ### Bugs 21 | If you have found an issue with OpenKit, which is not security related, you can send us a bug report 22 | either via [GitHub issues][gh-issues] or via the [Dynatrace support portal][dt-support]. 23 | 24 | ## Contributing code 25 | ### GitHub Flow 26 | Pull requests are the best way to propose changes to the codebase (we use [Github Flow][gh-flow]). We actively welcome your pull requests: 27 | 28 | 1. Fork the repo and create your branch. 29 | 2. If you've added code that should be tested, add tests. 30 | 3. If you've changed APIs, update the documentation. 31 | 4. Ensure the changes build and tests are passing. 32 | See [Building OpenKit Java][building] for detailed instructions. 33 | 5. Issue that pull request! 34 | 35 | ### License of pull requests 36 | 37 | Any contributions you make will be under the [Apache 2.0 license][license] that covers the project. 38 | 39 | [mail]: mailto:openkit@dynatrace.com 40 | [gh-issues]: https://github.com/Dynatrace/openkit-java/issues 41 | [gh-flow]: https://guides.github.com/introduction/flow/index.html 42 | [dt-support]: https://www.dynatrace.com/services-support/#get-support 43 | [code_of_conduct]: ./CODE_OF_CONDUCT.md 44 | [license]: ./LICENSE 45 | [building]: ./docs/building.md -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /docs/building.md: -------------------------------------------------------------------------------- 1 | # Building OpenKit Java 2 | ## Prerequisites for building 3 | ### Building the Source/Generating the JavaDoc 4 | * Java Development Kit (JDK) 6, 7, 8 or 11 5 | * Environment Variable JAVA_HOME set to JDK install directory 6 | 7 | ### (Unit-)Testing the OpenKit 8 | * Java Runtime Environment (JRE) 6, 7, 8 or 11 9 | Dependencies for testing (JUnit, Hamcrest, Mockito) are managed by Gradle. 10 | 11 | ## Building the Source 12 | Navigate to OpenKit's top level directory and run the following command in your shell. 13 | 14 | * Windows command prompt 15 | ```shell 16 | gradlew jar 17 | ``` 18 | * Linux/UNIX shell 19 | ```shell 20 | ./gradlew jar 21 | ``` 22 | 23 | The built jar file(s) `openkit-.jar` will be located in the `build/libs` directory. 24 | 25 | ## Running all checks 26 | Navigate to OpenKit's top level directory and run the following command in your shell. 27 | 28 | * Windows command prompt 29 | ```shell 30 | gradlew test 31 | ``` 32 | * Linux/UNIX shell 33 | ```shell 34 | ./gradlew test 35 | ``` 36 | 37 | ## Generating the JavaDoc 38 | Navigate to OpenKit's top level directory and run the following command in your shell. 39 | 40 | * Windows command prompt 41 | ```shell 42 | gradlew javadoc 43 | ``` 44 | * Linux/UNIX shell 45 | ```shell 46 | ./gradlew javadoc 47 | ``` 48 | 49 | The generated javadoc will be located in the `build/docs/javadoc` directory. 50 | -------------------------------------------------------------------------------- /docs/installing.md: -------------------------------------------------------------------------------- 1 | # Installing and updating OpenKit Java 2 | 3 | ## Prerequisites 4 | OpenKit Java requires a Java Runtime Environment (JRE) 6, 7, 8 or 11. 5 | 6 | ## Obtaining OpenKit Java 7 | OpenKit is available as Maven package on [Mavencentral][mvncentral] and should be used via Maven, Gradle or Ivy. 8 | 9 | An alternative way, if automatic dependency management is not possible, is to obtain the jar file 10 | from [GitHub Releases][gh-releases]. 11 | 12 | ## Updating OpenKit Java 13 | The recommended approach to update OpenKit is via Maven, Gradle or Ivy from [Mavencentral][mvncentral]. 14 | 15 | An alternative way, if automatic dependency management is not possible, is manually updating 16 | the jar file from [GitHub Releases][gh-releases]. 17 | 18 | ## Release notifications 19 | GitHub offers the possibility to receive notifications for new releases. Detailed instructions are available 20 | on the [Watching and unwatching releases for a repository][gh-release-notification] page. 21 | 22 | [mvncentral]: https://search.maven.org/artifact/com.dynatrace.openkit/openkit-java 23 | [gh-releases]: https://github.com/Dynatrace/openkit-java/releases 24 | [gh-release-notification]: https://help.github.com/en/github/receiving-notifications-about-activity-on-github/watching-and-unwatching-releases-for-a-repository -------------------------------------------------------------------------------- /docs/licenses/HEADER.txt: -------------------------------------------------------------------------------- 1 | Copyright ${year} ${name} 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /docs/pics/OpenKit - State diagram.xml: -------------------------------------------------------------------------------- 1 | 3Vpbc5s4FP41fkwHEPjy2DhJd2d2Z3fGnWn7KIMMagF5hBzb/fWVQAKEwKHE4KR5CToc3b7znYuEZ2CdnD5RuI/+JQGKZ44VnGbgYeY4trVy+D8hOReS5WpeCEKKA6lUCTb4J1I9pfSAA5RpioyQmOG9LvRJmiKfaTJIKTnqajsS67PuYYgMwcaHsSn9ggMWyV14ViX/C+EwUjPblnyzhf6PkJJDKuebOWCX/xWvE6jGkvpZBANyrInA4wysKSGseEpOaxQLbBVsRb+njrfluilKWa8Oah3srPaOAg6FbBLKIhKSFMaPlfQ+3x8SI1i8FbEk5o82f0QnzL7Wnr8JlQ+eaKWMnr/qzW9ygO+IsbPkADwwwkXVvP8QslcjpsFHYVve9GOYZdgvhE84Lhcgxn04yYGL1lm2TGgkWhk5UF9uXvKWQRoipeUWMoFLrZ/E8xMiCeLTcAWKYsjws04hKJkYlnpl1/8J5itxLOk1ruLQWc1r6UMUi5K9Kpvyh9oyKlFu6Xaru94YVpemlXa3NatrNs/1+lo9Y5T8QGsSE5qvFFj5Xz8+DLW5a49ic75ceK4p7IUts25KOE1KzBve/IK+Z1sNphQrGMobidQzjA9yx3+nmBlcqpgibHCMMEObPczhPvJ8obMHUl+ywBVG3XHj1YwtQqdvtdFgt5M06LTxM6IMnS6a76TjWuKswvOxCv6lLKoF/qaL1i2u+ecFUJcGqKZzxjHPfEgHjqeOvXifceKyDYMMmfCVvjIqfKCJnmegB1rAA1cAb9UDvBcjWw1UsWnM64CPMQ5TLtsSxkjSFWwuxqbfDUPLadKMwfWeaeZ3Y1fXPFeLRfYAS7+cwy5VLovBpcv4SUxVKfUspiLW9SjV1y1bMkVKDHvx8MJ0M1CU4Z9wmysIdCTJuLZ3P/MeRLqQjulzMBBt8dgEB0Fu6xhuUXxf1uONpMIr8jZkO4NfedaQq5vV6/W2oHjH+eJoHiBbQ/1XjnKnxlFdyG6XoddWhM7kFeHwc8CNnAnczJnmhjOdUfYuvMm7ojc5y6XmTnev9CdVM+tOerccwbsUn+qFcyZAgHt2oDgNBa9SgUVgmJVGJNkespcL6ZtUzq7TyPILs3JejlQ4O4sxYpZ+d7HQSwD9GLt4Y+dYa4qoNagYBJ5OE2BfPsg270LAlQ+y4I+4ABnMCnD1643ePmsZkXCdB0H0n7ojfc8XCc2jsDOf8CLBBROT2r4dqcGbIjXoJHX6/jndjMWTctoxK6cBJB/lgqfbCdovExzPcLchSb6F+dc/53dk5caVDpiPc3XUxbiuaqFZXTT0X10tuO7U1cIYh+Ne9FJBdNyPIX29X62m5v1P8SGLNoj7J0nNM/C7C66gcX4CqwmDK1j0CK6XPj3w+HXbDw9zT0PPW5rojfXlwTW5+RnRBHN3/PNo6U5JS9d56zm/JT4PSOVuS6xVLjl2KgdL3cDe6rWpvP/1GG9WP3Ap1KtfEYHHXw== -------------------------------------------------------------------------------- /docs/pics/OpenKit-BeaconCache.xml: -------------------------------------------------------------------------------- 1 | 3ZpNj9owEIZ/Ddcq9iTAHgvLtoeuVJVDzybxkqghRo756q+vQxySYDBsRW13ueCMnQ8/nozfGWUA09X+Cyfr9JUlNB/gINkP4HmAMYqiUP5VlkNtGY9xbVjyLFGDWsM8+02VMVDWTZbQsjdQMJaLbN03xqwoaCx6NsI52/WHvbG8f9c1WVLNMI9Jrlt/ZolI1SyioLV/pdkybe6MAtWzIPGvJWebQt1vgOHt+Ku7V6S5lhpfpiRhu44JZgOYcsZE3VrtpzSv2DbY6vNervSenpvTQtxzglqWLck3aupzWpYZK6RRXuxlQkncHAxzecnJgsvWsmqpGYhDQ63cZaucFPJokopVLo1INuM0y5Nv5MA21ROVQhJqjiaclnLtvzePi85Mr6TyqEBa5WlcKD/BwenmW8oF3V+dOzoRlZ5K2YoKfpBD1AnNaiofRc2a7NoVx6GypZ3VDsfKSJSXLU+XbknLhoJ9GTxo4Gfb6rlx8EwEuRPt31HBl6koDBconMj0KAwfQOFJo/CDxownlcN9QjqFlKyrJt1XzpOwzeLYc3Sb6p2jiXKXXZoJOl+TuOreyRjV53YXJngMpgdQQvpb2sEU+owJhTY5hSZO0T0RzCNyY5vk9HDUITf0mZPVN1F3sM+xqHdLV2F7fzZlF2EcRSb3Gbl1n9CfOB6YMGG3mN6llXBgExsyYYP/CZvV3XBowjb2GRsauXS3kcatzYlwNyfCHy8ngrNtxG5ShMYaemtZUb3sfqRFyJAXYdd5Ub1IXmyo2LChYteJ0Q1OVjOjC+UGe8L12pvlg3K9oOg7HhS59SCPShDYoPCx39L1fEuzKiawQYRhv7Wrxs1qwNJFWIeb44KEmVsYuvQ3XUG14hW64hU+nniNnlyK1wvFbHsl/QdpskdsqWAQZeBavNaL5MWWCoayBrgWrzc4WRWvgE2gvCvr30Jns64PTgvWV4KSD7ofDHoWXOsL8KdkDQb9Cn7r/nM1YFWHgUG/gt+6X+P2D2O9PGy/dTn2dT4ogtkf -------------------------------------------------------------------------------- /docs/supported_versions.md: -------------------------------------------------------------------------------- 1 | # Supported OpenKit Java versions 2 | 3 | The following table gives an overview of supported OpenKit Java versions. 4 | 5 | As OpenKit applies the principles of [semantic versioning][semver] only the latest bugfix 6 | releases are actively maintained for a major-minor version pair. 7 | Example: Version `1.4.3` supersedes `1.4.2` and therefore only `1.4.3` will be maintained. 8 | 9 | ## Active maintenance 10 | | Version | Bug fixes | Security fixes | Remarks | 11 | |---------|:------------------:|:------------------:|------------------| 12 | | 3.3.X | :heavy_check_mark: | :heavy_check_mark: | | 13 | | 3.2.X | :x: | :heavy_check_mark: | | 14 | | 3.1.X | :x: | :heavy_check_mark: | | 15 | | 3.0.X | :x: | :heavy_check_mark: | | 16 | | 2.2.X | :x: | :x: | Upgrade to 3.3.X | 17 | | 2.1.X | :x: | :x: | Upgrade to 3.3.X | 18 | | 2.0.X | :x: | :x: | Upgrade to 3.3.X | 19 | | 1.4.X | :x: | :x: | Upgrade to 3.3.X | 20 | | 1.3.X | :x: | :x: | Upgrade to 3.3.X | 21 | | 1.2.X | :x: | :x: | Upgrade to 3.3.X | 22 | | 1.1.X | :x: | :x: | Upgrade to 3.3.X | 23 | | 1.0.X | :x: | :x: | Upgrade to 3.3.X | 24 | 25 | 26 | [semver]: https://semver.org/ -------------------------------------------------------------------------------- /generate_javadoc.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | ECHO Cleaning up old javadoc 4 | rmdir /s /q javadoc 5 | 6 | ECHO Generating new javadoc ... 7 | ECHO. 8 | %JAVA_HOME%\bin\javadoc -public -sourcepath src/main/java -d javadoc com.dynatrace.openkit.api com.dynatrace.openkit 9 | 10 | ECHO. 11 | ECHO DONE! -------------------------------------------------------------------------------- /gradle/coverage.gradle: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2023 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | def coverageReportDir = file("$buildDir/reports/coverage/jacoco") 18 | 19 | jacoco { 20 | toolVersion = "0.8.8" 21 | reportsDir = coverageReportDir 22 | } 23 | 24 | def coverageXmlReportFile = file("${coverageReportDir}/jacocoReport.xml") 25 | 26 | jacocoTestReport { 27 | reports { 28 | xml.enabled = true 29 | xml.destination = coverageXmlReportFile 30 | html.enabled = true 31 | html.destination = file("${coverageReportDir}/html") 32 | } 33 | } 34 | 35 | coverallsJacoco { 36 | reportPath = coverageXmlReportFile.toString() 37 | } 38 | 39 | tasks.coverallsJacoco { 40 | dependsOn 'check' 41 | onlyIf { System.env.'CI' } 42 | } -------------------------------------------------------------------------------- /gradle/license.gradle: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.github.hierynomus.license' 18 | 19 | license { 20 | header = rootProject.file('docs/licenses/HEADER.txt') 21 | strictCheck = true 22 | ignoreFailures = true // enable if this should break the build 23 | ext.year = Calendar.getInstance().get(Calendar.YEAR) 24 | ext.name = 'Dynatrace LLC' 25 | } 26 | -------------------------------------------------------------------------------- /gradle/publish.gradle: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | publishing { 17 | publications { 18 | mavenJava(MavenPublication) { 19 | artifactId project.name 20 | 21 | from components.java 22 | 23 | artifact sourceJar { 24 | classifier "sources" 25 | } 26 | artifact javadocJar { 27 | classifier "javadoc" 28 | } 29 | pom { 30 | name = "${project.group}:${project.name}" 31 | packaging = 'jar' 32 | description = 'Dynatrace OpenKit - Java Reference Implementation' 33 | url = 'https://github.com/Dynatrace/openkit-java' 34 | 35 | scm { 36 | url = 'https://github.com/Dynatrace/openkit-java.git' 37 | } 38 | 39 | licenses { 40 | license { 41 | name = 'Apache License, Version 2.0' 42 | url = 'http://www.apache.org/licenses/LICENSE-2.0' 43 | } 44 | } 45 | developers { 46 | developer { 47 | id = 'Dynatrace' 48 | name = 'Dynatrace LLC' 49 | email = 'openkit@dynatrace.com' 50 | } 51 | } 52 | } 53 | } 54 | } 55 | } 56 | 57 | artifacts { 58 | archives sourceJar, javadocZip, javadocJar 59 | } 60 | 61 | if (project.hasProperty("ossrhUsername") && project.ossrhUsername && project.hasProperty("ossrhPassword") && project.ossrhPassword) { 62 | signing { 63 | sign publishing.publications.mavenJava 64 | } 65 | nexusPublishing { 66 | packageGroup = "com.dynatrace" 67 | useStaging = true 68 | repositories { 69 | sonatype { 70 | nexusUrl = uri("https://oss.sonatype.org/service/local/") 71 | snapshotRepositoryUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/") 72 | username = ossrhUsername 73 | password = ossrhPassword 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dynatrace/openkit-java/59b3afcebaa7cbfbaf7e47cf70336d6e6865d8d2/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "openkit-java" -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/CrashReportingLevel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit; 18 | 19 | import com.dynatrace.openkit.protocol.SerializableBeaconValue; 20 | 21 | /** 22 | * Specifies the level at which crashes are reported to the server. 23 | */ 24 | public enum CrashReportingLevel implements SerializableBeaconValue { 25 | /** 26 | * Crashes are not sent to the server 27 | */ 28 | OFF(0), 29 | /** 30 | * Crashes are not sent to the server 31 | */ 32 | OPT_OUT_CRASHES(1), 33 | /** 34 | * Crashes are sent to the server 35 | */ 36 | OPT_IN_CRASHES(2); 37 | 38 | private final int intValue; 39 | 40 | CrashReportingLevel(int intValue) { 41 | this.intValue = intValue; 42 | } 43 | 44 | public int getIntValue() { 45 | return intValue; 46 | } 47 | 48 | @Override 49 | public String asBeaconValue() { 50 | return String.valueOf(intValue); 51 | } 52 | 53 | public static CrashReportingLevel defaultValue() { 54 | return OPT_IN_CRASHES; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/DataCollectionLevel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit; 18 | 19 | import com.dynatrace.openkit.protocol.SerializableBeaconValue; 20 | 21 | /** 22 | * Specifies the granularity of which/how much data is collected/sent. 23 | */ 24 | public enum DataCollectionLevel implements SerializableBeaconValue { 25 | /** 26 | * No data will be collected at all 27 | */ 28 | OFF(0), 29 | /** 30 | * Only performance related data will be collected 31 | */ 32 | PERFORMANCE(1), 33 | /** 34 | * All available RUM (real user monitoring) data, including performance related data, is collected. 35 | */ 36 | USER_BEHAVIOR(2); 37 | 38 | private final int intValue; 39 | 40 | DataCollectionLevel(int intValue){ 41 | this.intValue = intValue; 42 | } 43 | 44 | public int getIntValue() { 45 | return intValue; 46 | } 47 | 48 | @Override 49 | public String asBeaconValue() { 50 | return String.valueOf(intValue); 51 | } 52 | 53 | public static DataCollectionLevel defaultValue() { 54 | return USER_BEHAVIOR; 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/api/ConnectionType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2022 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.api; 18 | 19 | /** 20 | * Specifies the type of a network connection. 21 | */ 22 | public enum ConnectionType { 23 | /** 24 | * Mobile connection type 25 | */ 26 | Mobile("m"), 27 | 28 | /** 29 | * Wireless connection type 30 | */ 31 | Wifi("w"), 32 | 33 | /** 34 | * Offline 35 | */ 36 | Offline("o"), 37 | 38 | /** 39 | * Connection via local area network 40 | */ 41 | Lan("l"); 42 | 43 | private final String value; 44 | 45 | ConnectionType(String value){ 46 | this.value = value; 47 | } 48 | 49 | public String getValue() { 50 | return value; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/api/LogLevel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.api; 18 | 19 | public enum LogLevel { 20 | DEBUG(0), 21 | INFO(10), 22 | WARN(20), 23 | ERROR(30); 24 | 25 | private final int priority; 26 | 27 | LogLevel(int priority) { 28 | this.priority = priority; 29 | } 30 | 31 | public int getPriority() { 32 | return priority; 33 | } 34 | 35 | public boolean hasSameOrGreaterPriorityThan(LogLevel other) { 36 | return getPriority() >= other.getPriority(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/api/OpenKitConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.api; 18 | 19 | import java.net.URL; 20 | import java.util.jar.Attributes; 21 | import java.util.jar.Manifest; 22 | 23 | /** 24 | * Defines constant values used in OpenKit 25 | */ 26 | public class OpenKitConstants { 27 | 28 | 29 | /** 30 | * Explicit default constructor to hide implicit public one. 31 | */ 32 | private OpenKitConstants() { 33 | throw new IllegalStateException("constants class"); 34 | } 35 | 36 | /** 37 | * Name of Dynatrace HTTP header which is used for tracing web requests. 38 | */ 39 | public static final String WEBREQUEST_TAG_HEADER = "X-dynaTrace"; 40 | 41 | // default values used in configuration 42 | public static final String DEFAULT_APPLICATION_VERSION; 43 | public static final String DEFAULT_OPERATING_SYSTEM; 44 | public static final String DEFAULT_MANUFACTURER; 45 | public static final String DEFAULT_MODEL_ID = "OpenKitDevice"; 46 | 47 | // load default version and vendor information from MANIFEST.MF 48 | static { 49 | 50 | String specificationVersion = ""; 51 | String implementationVersion = ""; 52 | String implementationVendor = "Dynatrace"; 53 | 54 | try { 55 | Class clazz = OpenKitConstants.class; 56 | String className = clazz.getSimpleName() + ".class"; 57 | String classPath = clazz.getResource(className).toString(); 58 | if (classPath.startsWith("jar")) { 59 | String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; 60 | Manifest manifest = new Manifest(new URL(manifestPath).openStream()); 61 | Attributes attr = manifest.getMainAttributes(); 62 | 63 | specificationVersion = attr.getValue("Specification-Version"); 64 | implementationVersion = attr.getValue("Implementation-Version"); 65 | implementationVendor = attr.getValue("Implementation-Vendor"); 66 | } 67 | } catch (Exception e) { 68 | // intentionally left empty 69 | } 70 | 71 | if (implementationVersion != null && !implementationVersion.trim().isEmpty()) { 72 | DEFAULT_APPLICATION_VERSION = specificationVersion + "-" + implementationVersion; 73 | } else { 74 | DEFAULT_APPLICATION_VERSION = specificationVersion; 75 | } 76 | DEFAULT_OPERATING_SYSTEM = "OpenKit " + DEFAULT_APPLICATION_VERSION; 77 | DEFAULT_MANUFACTURER = implementationVendor; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/api/RootAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.api; 18 | 19 | /** 20 | * This interface provides the same functionality as Action, additionally it allows to create child Actions 21 | */ 22 | public interface RootAction extends Action { 23 | 24 | /** 25 | * Enters a (child) Action with a specified name on this Action. 26 | * 27 | *

28 | * If the given {@code actionName} is {@code null} or an empty string, 29 | * no reporting will happen on that {@link RootAction}. 30 | *

31 | * 32 | * @param actionName name of the Action 33 | * @return Action instance to work with 34 | */ 35 | Action enterAction(String actionName); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/api/SSLTrustManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.api; 18 | 19 | import javax.net.ssl.HostnameVerifier; 20 | import javax.net.ssl.X509TrustManager; 21 | 22 | /** 23 | * Interface to provide a user-defined trust manager to the configuration. 24 | *

25 | *

26 | * When OpenKit connects to a server with self-signed SSL/TLS certificates then 27 | * an implementation of this interface is required to verify the certificate. 28 | *

29 | */ 30 | public interface SSLTrustManager { 31 | 32 | /** 33 | * Get the X509TrustManager for SSL/TLS certificate authentication. 34 | */ 35 | X509TrustManager getX509TrustManager(); 36 | 37 | /** 38 | * Get the HostnameVerifier which checks if a hostname is allowed. 39 | */ 40 | HostnameVerifier getHostnameVerifier(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/api/WebRequestTracer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.api; 18 | 19 | import java.io.Closeable; 20 | 21 | /** 22 | * This interface allows tracing and timing of a web request. 23 | */ 24 | public interface WebRequestTracer extends Closeable { 25 | 26 | /** 27 | * Returns the Dynatrace tag which has to be set manually as Dynatrace HTTP header 28 | * ({@link OpenKitConstants#WEBREQUEST_TAG_HEADER}).
29 | * This is only necessary for tracing web requests via 3rd party HTTP clients. 30 | * 31 | * @return the Dynatrace tag to be set as HTTP header value or an empty String if capture is off 32 | */ 33 | String getTag(); 34 | 35 | /** 36 | * Sets the amount of sent data of this web request. Has to be called before {@link WebRequestTracer#stop(int)}. 37 | * 38 | * @deprecated 39 | * This method should no longer be used due its datatype limitation. Use {@link WebRequestTracer#setBytesSent(long)} instead. 40 | * 41 | * @param bytesSent number of bytes 42 | */ 43 | @Deprecated 44 | WebRequestTracer setBytesSent(int bytesSent); 45 | 46 | /** 47 | * Sets the amount of sent data of this web request. Has to be called before {@link WebRequestTracer#stop(int)}. 48 | * 49 | * @param bytesSent number of bytes 50 | */ 51 | WebRequestTracer setBytesSent(long bytesSent); 52 | 53 | /** 54 | * Sets the amount of received data of this web request. Has to be called before {@link WebRequestTracer#stop(int)}. 55 | * 56 | * @deprecated 57 | * This method should no longer be used due its datatype limitation. Use {@link WebRequestTracer#setBytesReceived(long)} instead. 58 | * 59 | * @param bytesReceived number of bytes 60 | */ 61 | @Deprecated 62 | WebRequestTracer setBytesReceived(int bytesReceived); 63 | 64 | /** 65 | * Sets the amount of received data of this web request. Has to be called before {@link WebRequestTracer#stop(int)}. 66 | * 67 | * @param bytesReceived number of bytes 68 | */ 69 | WebRequestTracer setBytesReceived(long bytesReceived); 70 | 71 | /** 72 | * Starts the web request timing. Should be called when the web request is initiated. 73 | */ 74 | WebRequestTracer start(); 75 | 76 | /** 77 | * Stops the web request timing with the given response code. Should be called when the web request is finished. 78 | * 79 | * @param responseCode response code of this web request 80 | */ 81 | void stop(int responseCode); 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/api/http/HttpRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.api.http; 18 | 19 | import java.net.URL; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | /** 24 | * Interface representing an HTTP request. 25 | */ 26 | public interface HttpRequest { 27 | 28 | /** 29 | * Gets the HTTP request {@link URL}. 30 | */ 31 | URL getUrl(); 32 | 33 | /** 34 | * Gets the HTTP request method. 35 | */ 36 | String getMethod(); 37 | 38 | /** 39 | * Gets an immutable map containing the request headers and their values. 40 | */ 41 | Map> getHeaders(); 42 | 43 | /** 44 | * Gets the header's value. 45 | * 46 | * @param name Header name for which to retrieve the value. 47 | * 48 | * @return The header's value, which might also be {@code null} if not set. 49 | */ 50 | String getHeader(String name); 51 | 52 | /** 53 | * Sets an HTTP header or overwrites an existing HTTP header with new value. 54 | *

55 | * Trying to set an HTTP header with null name will return immediately. 56 | * Trying to set one of the following restricted headers will also return immediately. 57 | *

58 | *
    59 | *
  • {@code Access-Control-Request-Headers}
  • 60 | *
  • {@code Access-Control-Request-Method}
  • 61 | *
  • {@code Connection}
  • 62 | *
  • {@code Content-Length}
  • 63 | *
  • {@code Content-Transfer-Encoding}
  • 64 | *
  • {@code Host}
  • 65 | *
  • {@code Keep-Alive}
  • 66 | *
  • {@code Origin}
  • 67 | *
  • {@code Trailer}
  • 68 | *
  • {@code Transfer-Encoding}
  • 69 | *
  • {@code Upgrade}
  • 70 | *
  • {@code Via}
  • 71 | *
72 | * 73 | * @param name The header's name, which must not be {@code null} or any of the restricted headers. 74 | * @param value The header's value 75 | */ 76 | void setHeader(String name, String value); 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/api/http/HttpRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.api.http; 18 | 19 | /** 20 | * An interface allowing to intercept an HTTP request, before it is sent to the backend system. 21 | * 22 | *

23 | * This interceptor is only applied to HTTP requests which are sent to Dynatrace backends. 24 | *

25 | */ 26 | public interface HttpRequestInterceptor { 27 | 28 | /** 29 | * Intercept the HTTP request and manipulate it. 30 | * 31 | *

32 | * Currently it's only possible to set custom HTTP headers. 33 | *

34 | * 35 | * @param httpRequest The HTTP request to Dynatrace backend. 36 | */ 37 | void intercept(HttpRequest httpRequest); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/api/http/HttpResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.api.http; 18 | 19 | import java.net.URL; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | /** 24 | * Interface representing an HTTP response. 25 | */ 26 | public interface HttpResponse { 27 | 28 | /** 29 | * Gets the request {@link URL} associated with this response. 30 | */ 31 | URL getRequestUrl(); 32 | 33 | /** 34 | * Gets the request method associated with this response. 35 | */ 36 | String getRequestMethod(); 37 | 38 | /** 39 | * Gets the HTTP response code. 40 | * 41 | *

42 | * If reading the HTTP status line fails, {@link Integer#MIN_VALUE} is returned. 43 | *

44 | * 45 | * @return HTTP response code returned by server, or a negative value in case of an error. 46 | */ 47 | int getResponseCode(); 48 | 49 | /** 50 | * Gets the HTTP response message. 51 | * 52 | *

53 | * If reading the HTTP status line fails, {@code null} is returned. 54 | *

55 | * 56 | * @return HTTP response message returned by server or {@code null}. 57 | */ 58 | String getResponseMessage(); 59 | 60 | /** 61 | * Gets the HTTP response headers and their values. 62 | * 63 | * @return An immutable map of HTTP response headers mapping to their values. 64 | */ 65 | Map> getHeaders(); 66 | 67 | /** 68 | * Gets the value of an HTTP response header. 69 | * 70 | *

71 | * If the header occurs multiple times, it depends on the underlying implementation 72 | * which value is returned. 73 | * 74 | * In this case prefer {@link #getHeaders()} instead. 75 | *

76 | * 77 | * @return Value associated with HTTP response header {@code name} or {@code null}. 78 | */ 79 | String getHeader(String name); 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/api/http/HttpResponseInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.api.http; 18 | 19 | /** 20 | * An interface allowing to intercept an HTTP response from Dynatrace backends. 21 | * 22 | *

23 | * This interceptor is only applied to HTTP responses coming from Dynatrace backend requests. 24 | *

25 | */ 26 | public interface HttpResponseInterceptor { 27 | 28 | /** 29 | * Intercept the HTTP response from Dynatrace backend. 30 | * 31 | *

32 | * This method allows the implementor to read custom HTTP response headers. 33 | *

34 | * 35 | * @param httpResponse The HTTP response from Dynatrace backend. 36 | */ 37 | void intercept(HttpResponse httpResponse); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/caching/BeaconCacheEvictionStrategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.caching; 18 | 19 | /** 20 | * An implementor of this interface shall evict {@link BeaconCacheEntry} based 21 | * on strategy's rules. 22 | */ 23 | public interface BeaconCacheEvictionStrategy { 24 | 25 | /** 26 | * Called when this strategy is executed. 27 | */ 28 | void execute(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/caching/BeaconKey.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.core.caching; 18 | 19 | public class BeaconKey { 20 | 21 | public final int beaconId; 22 | public final int beaconSeqNo; 23 | 24 | public BeaconKey(int beaconId, int beaconSeqNo) { 25 | this.beaconId = beaconId; 26 | this.beaconSeqNo = beaconSeqNo; 27 | } 28 | 29 | @Override 30 | public boolean equals(Object o) { 31 | if (this == o) { 32 | return true; 33 | } 34 | if (o == null || getClass() != o.getClass()) { 35 | return false; 36 | } 37 | 38 | BeaconKey beaconKey = (BeaconKey) o; 39 | 40 | if (beaconId != beaconKey.beaconId) { 41 | return false; 42 | } 43 | return beaconSeqNo == beaconKey.beaconSeqNo; 44 | } 45 | 46 | @Override 47 | public int hashCode() { 48 | int result = beaconId; 49 | result = 31 * result + beaconSeqNo; 50 | return result; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "[sn=" + beaconId + ", seq=" + beaconSeqNo + "]"; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/communication/AbstractBeaconSendingState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.communication; 18 | 19 | /** 20 | * Base class for all beacon sending states. 21 | * 22 | *

23 | * Transition to: 24 | *

    25 | *
  • {@link AbstractBeaconSendingState#getShutdownState()}
  • 26 | *
27 | *

28 | */ 29 | abstract class AbstractBeaconSendingState { 30 | 31 | /** 32 | * Boolean variable indicating whether this state is a terminal state or not. 33 | */ 34 | private final boolean isTerminalState; 35 | 36 | AbstractBeaconSendingState(boolean isTerminalState) { 37 | this.isTerminalState = isTerminalState; 38 | } 39 | 40 | /** 41 | * Execute the current state. 42 | * 43 | *

44 | * In case shutdown was requested, a state transition is performed by this method to the {@link AbstractBeaconSendingState} 45 | * returned by {@link AbstractBeaconSendingState#getShutdownState()}. 46 | *

47 | */ 48 | void execute(BeaconSendingContext context) { 49 | 50 | try { 51 | doExecute(context); 52 | } catch (InterruptedException e) { 53 | onInterrupted(context); 54 | context.requestShutdown(); 55 | Thread.currentThread().interrupt(); 56 | } 57 | 58 | if (context.isShutdownRequested()) { 59 | context.setNextState(getShutdownState()); 60 | } 61 | } 62 | 63 | /** 64 | * Perform cleanup on interrupt. 65 | * 66 | * @param context State's context. 67 | */ 68 | void onInterrupted(BeaconSendingContext context) { 69 | // default -> do nothing 70 | } 71 | 72 | /** 73 | * Real state execution. 74 | * 75 | * @param context State's context. 76 | */ 77 | abstract void doExecute(BeaconSendingContext context) throws InterruptedException; 78 | 79 | /** 80 | * Get an instance of the {@link AbstractBeaconSendingState} to which a transition is made upon shutdown request. 81 | */ 82 | abstract AbstractBeaconSendingState getShutdownState(); 83 | 84 | /** 85 | * Get {@code true} if this state is a terminal state, {@code false} otherwise. 86 | */ 87 | boolean isTerminalState() { 88 | return isTerminalState; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/communication/BeaconSendingRequestUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.communication; 18 | 19 | import com.dynatrace.openkit.protocol.StatusResponse; 20 | 21 | /** 22 | * Utility class for sending requests to the server and retry several times 23 | */ 24 | class BeaconSendingRequestUtil { 25 | 26 | private BeaconSendingRequestUtil() { 27 | } 28 | 29 | /** 30 | * Send a status request to the server and try to get the status response. 31 | * 32 | * @param context Used to retrieve the {@link com.dynatrace.openkit.protocol.HTTPClient} and for delaying methods. 33 | * @param numRetries The number of retries (total number of tries = numRetries + 1) 34 | * @param initialRetryDelayInMillis The initial delay which is doubled between one unsuccessful attempt and the next retry. 35 | * @return A status response or {@code null} if shutdown was requested or number of retries was reached. 36 | */ 37 | static StatusResponse sendStatusRequest(BeaconSendingContext context, int numRetries, long initialRetryDelayInMillis) throws InterruptedException { 38 | 39 | StatusResponse statusResponse; 40 | long sleepTimeInMillis = initialRetryDelayInMillis; 41 | int retry = 0; 42 | 43 | while (true) { 44 | statusResponse = context.getHTTPClient().sendStatusRequest(context); 45 | if (BeaconSendingResponseUtil.isSuccessfulResponse(statusResponse) 46 | || BeaconSendingResponseUtil.isTooManyRequestsResponse(statusResponse) // is handled by the states 47 | || retry >= numRetries 48 | || context.isShutdownRequested()) { 49 | break; 50 | } 51 | 52 | // if no (valid) status response was received -> sleep and double the delay for each retry 53 | context.sleep(sleepTimeInMillis); 54 | sleepTimeInMillis *= 2; 55 | retry++; 56 | } 57 | 58 | return statusResponse; 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/communication/BeaconSendingResponseUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.communication; 18 | 19 | import com.dynatrace.openkit.protocol.StatusResponse; 20 | 21 | /** 22 | * Utility class for responses. 23 | */ 24 | class BeaconSendingResponseUtil { 25 | 26 | /** 27 | * Default constructor. 28 | * 29 | *

30 | * This constructor is private since the class is handled as static class. 31 | *

32 | */ 33 | private BeaconSendingResponseUtil() { 34 | } 35 | 36 | /** 37 | * Test if the given {@link StatusResponse} is a successful response. 38 | * 39 | * @param response The given response to check whether it is successful or not. 40 | * @return {@code true} if response is successful, {@code false} otherwise. 41 | */ 42 | static boolean isSuccessfulResponse(StatusResponse response) { 43 | 44 | return response != null && !response.isErroneousResponse(); 45 | } 46 | 47 | /** 48 | * Test if the given {@link StatusResponse} is a "too many requests" response. 49 | * 50 | *

51 | * A "too many requests" response is an HTTP response with response code 429. 52 | *

53 | * 54 | * @param response The given response to check whether it is a "too many requests" response or not. 55 | * @return {@code true} if response indicates too many requests, {@code false} otherwise. 56 | */ 57 | static boolean isTooManyRequestsResponse(StatusResponse response) { 58 | 59 | return response != null && response.getResponseCode() == StatusResponse.HTTP_TOO_MANY_REQUESTS; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/communication/BeaconSendingTerminalState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.communication; 18 | 19 | /** 20 | * Terminal state for beacon sending. 21 | */ 22 | class BeaconSendingTerminalState extends AbstractBeaconSendingState { 23 | 24 | BeaconSendingTerminalState() { 25 | super(true); 26 | } 27 | 28 | @Override 29 | void doExecute(BeaconSendingContext context) { 30 | 31 | // set the shutdown request - just to ensure it's set 32 | context.requestShutdown(); 33 | } 34 | 35 | @Override 36 | AbstractBeaconSendingState getShutdownState() { 37 | return this; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "Terminal"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/configuration/BeaconCacheConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.configuration; 18 | 19 | import com.dynatrace.openkit.DynatraceOpenKitBuilder; 20 | 21 | /** 22 | * Configuration for beacon cache. 23 | */ 24 | public class BeaconCacheConfiguration { 25 | 26 | private final long maxRecordAge; 27 | private final long cacheSizeLowerBound; 28 | private final long cacheSizeUpperBound; 29 | 30 | /** 31 | * Constructor 32 | * 33 | * @param builder OpenKit builder storing all necessary configuration information. 34 | */ 35 | private BeaconCacheConfiguration(DynatraceOpenKitBuilder builder) { 36 | this.maxRecordAge = builder.getBeaconCacheMaxRecordAge(); 37 | this.cacheSizeLowerBound = builder.getBeaconCacheLowerMemoryBoundary(); 38 | this.cacheSizeUpperBound = builder.getBeaconCacheUpperMemoryBoundary(); 39 | } 40 | 41 | /** 42 | * Create a {@link BeaconCacheConfiguration} from given {@link DynatraceOpenKitBuilder}. 43 | * 44 | * @param builder The OpenKit builder for which to create a {@link BeaconCacheConfiguration}. 45 | * @return Newly created {@link BeaconCacheConfiguration} or {@code null} if given argument is {@code null} 46 | */ 47 | public static BeaconCacheConfiguration from(DynatraceOpenKitBuilder builder) { 48 | if (builder == null) { 49 | return null; 50 | } 51 | return new BeaconCacheConfiguration(builder); 52 | } 53 | 54 | /** 55 | * Get maximum record age. 56 | */ 57 | public long getMaxRecordAge() { 58 | return maxRecordAge; 59 | } 60 | 61 | /** 62 | * Get lower memory limit for cache. 63 | */ 64 | public long getCacheSizeLowerBound() { 65 | return cacheSizeLowerBound; 66 | } 67 | 68 | /** 69 | * Get upper memory limit for cache. 70 | */ 71 | public long getCacheSizeUpperBound() { 72 | return cacheSizeUpperBound; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/configuration/ConfigurationDefaults.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.configuration; 18 | 19 | import com.dynatrace.openkit.CrashReportingLevel; 20 | import com.dynatrace.openkit.DataCollectionLevel; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | 24 | /** 25 | * Class containing all default values for all configurations. 26 | */ 27 | public class ConfigurationDefaults { 28 | 29 | /** 30 | * The default {@link BeaconCacheConfiguration} when user does not override it. 31 | * 32 | * Default settings allow beacons which are max 2 hours old and unbounded memory limits. 33 | */ 34 | public static final long DEFAULT_MAX_RECORD_AGE_IN_MILLIS = TimeUnit.MINUTES.toMillis(45); // 1hour and 45 minutes 35 | /** 36 | * Defines the default upper memory boundary of the {@link com.dynatrace.openkit.core.caching.BeaconCache}. 37 | * 38 | *

39 | * The upper boundary is the size limit at which the {@link com.dynatrace.openkit.core.caching.BeaconCache} 40 | * will start evicting records. The default uppper boundary is 100 MB 41 | *

42 | */ 43 | public static final long DEFAULT_UPPER_MEMORY_BOUNDARY_IN_BYTES = 100L * 1024L * 1024L; // 100 MiB 44 | /** 45 | * Defines the lower memory boundary of the {@link com.dynatrace.openkit.core.caching.BeaconCache} 46 | * 47 | *

48 | * The lower boundary is the size until which the {@link com.dynatrace.openkit.core.caching.BeaconCache} will 49 | * evict records once the upper boundary was exceeded. The default lower boundary is 80 MB 50 | *

51 | */ 52 | public static final long DEFAULT_LOWER_MEMORY_BOUNDARY_IN_BYTES = 80L * 1024L * 1024L; // 80 MiB 53 | 54 | /** Default data collection level used, if no other value was specified */ 55 | public static final DataCollectionLevel DEFAULT_DATA_COLLECTION_LEVEL = DataCollectionLevel.defaultValue(); 56 | /** Default crash reporting level used, if no other value was specified */ 57 | public static final CrashReportingLevel DEFAULT_CRASH_REPORTING_LEVEL = CrashReportingLevel.defaultValue(); 58 | 59 | private ConfigurationDefaults() { 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/configuration/ServerConfigurationUpdateCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.core.configuration; 18 | 19 | /** 20 | * Defines a callback to be notified when a {@link ServerConfiguration} is updated. 21 | */ 22 | public interface ServerConfigurationUpdateCallback { 23 | 24 | /** 25 | * Called when a server configuration is updated. 26 | * @param serverConfiguration the updated server configuration. 27 | */ 28 | void onServerConfigurationUpdate(ServerConfiguration serverConfiguration); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/CancelableOpenKitObject.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | public interface CancelableOpenKitObject extends OpenKitObject { 20 | 21 | /** 22 | * Cancel the {@link OpenKitObject}. 23 | * 24 | *

25 | * Canceling is similar to closing, except that data that is not 26 | * reported yet, will not be reported at all. 27 | *

28 | */ 29 | void cancel(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/EventPayloadAttributes.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | public class EventPayloadAttributes { 20 | public static final String TIMESTAMP = "timestamp"; 21 | public static final String EVENT_KIND = "event.kind"; 22 | public static final String EVENT_PROVIDER = "event.provider"; 23 | public static final String APP_VERSION = "app.version"; 24 | public static final String OS_NAME = "os.name"; 25 | public static final String DEVICE_MANUFACTURER = "device.manufacturer"; 26 | public static final String DEVICE_MODEL_IDENTIFIER = "device.model.identifier"; 27 | 28 | public static final String EVENT_KIND_RUM = "RUM_EVENT"; 29 | public static final String EVENT_KIND_BIZ = "BIZ_EVENT"; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/LeafActionImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.Action; 20 | import com.dynatrace.openkit.api.Logger; 21 | import com.dynatrace.openkit.protocol.Beacon; 22 | 23 | /** 24 | * Implementation of a leaf action. 25 | * 26 | *

27 | * A leaf action is an {@link Action} which cannot have further 28 | * sub actions. 29 | * Further sub objects may still be attached to this {@link Action}. 30 | *

31 | */ 32 | public class LeafActionImpl extends BaseActionImpl { 33 | 34 | /** The parent action */ 35 | private final Action parentAction; 36 | 37 | /** 38 | * Constructor for constructing the leaf action class. 39 | * 40 | * @param logger The logger used to log information 41 | * @param parentAction The root action, to which this leaf action belongs to 42 | * @param name The action's name 43 | * @param beacon The beacon for retrieving certain data and sending data 44 | */ 45 | LeafActionImpl(Logger logger, RootActionImpl parentAction, String name, Beacon beacon) { 46 | super(logger, parentAction, name, beacon); 47 | this.parentAction = parentAction; 48 | } 49 | 50 | @Override 51 | protected Action getParentAction() { 52 | return parentAction; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return getClass().getSimpleName() + " [sn=" + beacon.getSessionNumber() + ", id=" + id + ", name=" + name 58 | + ", pa=" + parentActionID + "] "; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/NullAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.Action; 20 | import com.dynatrace.openkit.api.RootAction; 21 | import com.dynatrace.openkit.api.WebRequestTracer; 22 | 23 | import java.net.URLConnection; 24 | 25 | /** 26 | * This class is returned as Action by {@link RootAction#enterAction(String)} when the {@link RootAction#leaveAction()} 27 | * has been called before. 28 | */ 29 | class NullAction implements Action { 30 | 31 | private final Action parentAction; 32 | 33 | /** 34 | * Construct null action with parent action. 35 | * @param parentAction The parent action, which might be {@code null}. 36 | */ 37 | NullAction(Action parentAction) { 38 | this.parentAction = parentAction; 39 | } 40 | 41 | @Override 42 | public Action reportEvent(String eventName) { 43 | return this; 44 | } 45 | 46 | @Override 47 | public Action reportValue(String valueName, int value) { 48 | return this; 49 | } 50 | 51 | @Override 52 | public Action reportValue(String valueName, long value) { 53 | return this; 54 | } 55 | 56 | @Override 57 | public Action reportValue(String valueName, double value) { 58 | return this; 59 | } 60 | 61 | @Override 62 | public Action reportValue(String valueName, String value) { 63 | return this; 64 | } 65 | 66 | @Override 67 | public Action reportError(String errorName, int errorCode) { 68 | return this; 69 | } 70 | 71 | @Override 72 | public Action reportError(String errorName, String causeName, String causeDescription, String causeStackTrace) { 73 | return this; 74 | } 75 | 76 | @Override 77 | public Action reportError(String errorName, Throwable throwable) { 78 | return this; 79 | } 80 | 81 | @Override 82 | public WebRequestTracer traceWebRequest(URLConnection connection) { 83 | return NullWebRequestTracer.INSTANCE; 84 | } 85 | 86 | @Override 87 | public WebRequestTracer traceWebRequest(String url) { 88 | return NullWebRequestTracer.INSTANCE; 89 | } 90 | 91 | @Override 92 | public Action leaveAction() { 93 | return parentAction; 94 | } 95 | 96 | @Override 97 | public Action cancelAction() { 98 | return parentAction; 99 | } 100 | 101 | @Override 102 | public long getDurationInMilliseconds() { 103 | return 0; 104 | } 105 | 106 | @Override 107 | public void close() { 108 | // nothing 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/NullRootAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.Action; 20 | import com.dynatrace.openkit.api.RootAction; 21 | import com.dynatrace.openkit.api.Session; 22 | import com.dynatrace.openkit.api.WebRequestTracer; 23 | 24 | import java.net.URLConnection; 25 | 26 | /** 27 | * This implementation of {@link RootAction} is returned by {@link Session#enterAction(String)} when the 28 | * {@link Session#end()}has been called before. 29 | */ 30 | public enum NullRootAction implements RootAction { 31 | 32 | /** 33 | * The sole {@link NullRootAction} instance 34 | */ 35 | INSTANCE; 36 | 37 | @Override 38 | public Action enterAction(String actionName) { 39 | return new NullAction(this); 40 | } 41 | 42 | @Override 43 | public Action reportEvent(String eventName) { 44 | return this; 45 | } 46 | 47 | @Override 48 | public Action reportValue(String valueName, int value) { 49 | return this; 50 | } 51 | 52 | @Override 53 | public Action reportValue(String valueName, long value) { 54 | return this; 55 | } 56 | 57 | @Override 58 | public Action reportValue(String valueName, double value) { 59 | return this; 60 | } 61 | 62 | @Override 63 | public Action reportValue(String valueName, String value) { 64 | return this; 65 | } 66 | 67 | @Override 68 | public Action reportError(String errorName, int errorCode) { 69 | return this; 70 | } 71 | 72 | @Override 73 | public Action reportError(String errorName, String causeName, String causeDescription, String causeStackTrace) { 74 | return this; 75 | } 76 | 77 | @Override 78 | public Action reportError(String errorName, Throwable throwable) { 79 | return this; 80 | } 81 | 82 | @Override 83 | public WebRequestTracer traceWebRequest(URLConnection connection) { 84 | return NullWebRequestTracer.INSTANCE; 85 | } 86 | 87 | @Override 88 | public WebRequestTracer traceWebRequest(String url) { 89 | return NullWebRequestTracer.INSTANCE; 90 | } 91 | 92 | @Override 93 | public Action leaveAction() { 94 | return null; // no parent action 95 | } 96 | 97 | @Override 98 | public Action cancelAction() { 99 | return null; 100 | } 101 | 102 | @Override 103 | public long getDurationInMilliseconds() { 104 | return 0; 105 | } 106 | 107 | @Override 108 | public void close() { 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/NullWebRequestTracer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.Action; 20 | import com.dynatrace.openkit.api.WebRequestTracer; 21 | 22 | /** 23 | * This implementation of {@link WebRequestTracer} is returned by {@link Action#traceWebRequest(String)} or 24 | * {@link Action#traceWebRequest(java.net.URLConnection)} when the {@link Action#leaveAction()} ()} 25 | * has been called before. 26 | */ 27 | public enum NullWebRequestTracer implements WebRequestTracer { 28 | 29 | /** 30 | * The sole {@link NullWebRequestTracer} instance 31 | */ 32 | INSTANCE; 33 | 34 | @Override 35 | public String getTag() { 36 | return ""; 37 | } 38 | 39 | @Override 40 | public WebRequestTracer setBytesSent(int bytesSent) { 41 | return this; 42 | } 43 | 44 | @Override 45 | public WebRequestTracer setBytesSent(long bytesSent) { 46 | return this; 47 | } 48 | 49 | @Override 50 | public WebRequestTracer setBytesReceived(int bytesReceived) { 51 | return this; 52 | } 53 | 54 | @Override 55 | public WebRequestTracer setBytesReceived(long bytesReceived) { 56 | return this; 57 | } 58 | 59 | @Override 60 | public WebRequestTracer start() { 61 | return this; 62 | } 63 | 64 | @Override 65 | public void stop(int respondeCode) { 66 | // nothing, NullObject pattern 67 | } 68 | 69 | @Override 70 | public void close() { 71 | // nothing, NullObject pattern 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/OpenKitInitializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.Logger; 20 | import com.dynatrace.openkit.core.BeaconSender; 21 | import com.dynatrace.openkit.core.SessionWatchdog; 22 | import com.dynatrace.openkit.core.caching.BeaconCache; 23 | import com.dynatrace.openkit.core.caching.BeaconCacheEvictor; 24 | import com.dynatrace.openkit.core.configuration.OpenKitConfiguration; 25 | import com.dynatrace.openkit.core.configuration.PrivacyConfiguration; 26 | import com.dynatrace.openkit.providers.SessionIDProvider; 27 | import com.dynatrace.openkit.providers.ThreadIDProvider; 28 | import com.dynatrace.openkit.providers.TimingProvider; 29 | 30 | /** 31 | * Provides relevant data for initializing / creating an OpenKit instance. 32 | */ 33 | public interface OpenKitInitializer { 34 | 35 | /** 36 | * Logger for reporting messages 37 | */ 38 | Logger getLogger(); 39 | 40 | /** 41 | * Privacy settings of which data is collected 42 | */ 43 | PrivacyConfiguration getPrivacyConfiguration(); 44 | 45 | /** 46 | * OpenKit / application related configuration. 47 | */ 48 | OpenKitConfiguration getOpenKitConfiguration(); 49 | 50 | /** 51 | * Provider to obtain the current timestamp. 52 | */ 53 | TimingProvider getTimingProvider(); 54 | 55 | /** 56 | * Provider for the identifier of the current thread. 57 | */ 58 | ThreadIDProvider getThreadIdProvider(); 59 | 60 | /** 61 | * Provider to obtain the identifier for the next session. 62 | */ 63 | SessionIDProvider getSessionIdProvider(); 64 | 65 | /** 66 | * Cache where beacon data is stored until it is sent. 67 | */ 68 | BeaconCache getBeaconCache(); 69 | 70 | /** 71 | * Eviction thread to avoid the beacon cache from overflowing. 72 | */ 73 | BeaconCacheEvictor getBeaconCacheEvictor(); 74 | 75 | /** 76 | * Sender thread for sending beacons to the server. 77 | */ 78 | BeaconSender getBeaconSender(); 79 | 80 | /** 81 | * Watchdog thread to perform certain actions for sessions at/after a specific time. 82 | */ 83 | SessionWatchdog getSessionWatchdog(); 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/OpenKitObject.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import java.io.Closeable; 20 | 21 | /** 22 | * Basic interface for every OpenKit related object. 23 | */ 24 | public interface OpenKitObject extends Closeable { 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/RootActionImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.Action; 20 | import com.dynatrace.openkit.api.Logger; 21 | import com.dynatrace.openkit.api.RootAction; 22 | import com.dynatrace.openkit.protocol.Beacon; 23 | 24 | /** 25 | * Actual implementation of the {@link RootAction} interface. 26 | */ 27 | public class RootActionImpl extends BaseActionImpl implements RootAction { 28 | 29 | /** 30 | * Constructor for constructing the root action class. 31 | * 32 | * @param logger The logger used to log information 33 | * @param parentSession The session, to which this root action belongs to 34 | * @param name The action's name 35 | * @param beacon The beacon for retrieving certain data and sending data 36 | */ 37 | RootActionImpl(Logger logger, SessionImpl parentSession, String name, Beacon beacon) { 38 | super(logger, parentSession, name, beacon); 39 | } 40 | 41 | @Override 42 | public Action enterAction(String actionName) { 43 | if (actionName == null || actionName.isEmpty()) { 44 | logger.warning(this + "enterAction: actionName must not be null or empty"); 45 | return new NullAction(this); 46 | } 47 | if (logger.isDebugEnabled()) { 48 | logger.debug(this + "enterAction(" + actionName + ")"); 49 | } 50 | synchronized (lockObject) { 51 | if (!isActionLeft()) { 52 | LeafActionImpl childAction = new LeafActionImpl(logger, this, actionName, beacon); 53 | storeChildInList(childAction); 54 | return childAction; 55 | } 56 | } 57 | 58 | return new NullAction(this); 59 | } 60 | 61 | @Override 62 | protected Action getParentAction() { 63 | // NOTE: root actions do not have a parent action 64 | return null; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return getClass().getSimpleName() + " [sn=" + beacon.getSessionNumber() + ", id=" + id + ", name=" + name + "] "; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/SessionCreator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | /** 20 | * Defines a creator for new sessions. 21 | */ 22 | public interface SessionCreator { 23 | 24 | /** 25 | * Returns a newly created {@link SessionImpl}. 26 | * 27 | * @param parent the parent composite of the session to create. 28 | */ 29 | SessionImpl createSession(OpenKitComposite parent); 30 | 31 | /** 32 | * Resets the internal state of this session creator. A reset includes the following: 33 | *
    34 | *
  • resetting the consecutive sequence session number which is increased every time a session is created.
  • 35 | *
  • use a new session ID (which will stay the same for all newly created sessions)
  • 36 | *
  • use a new randomized number (which will stay the same for all newly created sessions)
  • 37 | *
38 | */ 39 | void reset(); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/SessionCreatorInput.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.Logger; 20 | import com.dynatrace.openkit.core.caching.BeaconCache; 21 | import com.dynatrace.openkit.core.configuration.OpenKitConfiguration; 22 | import com.dynatrace.openkit.core.configuration.PrivacyConfiguration; 23 | import com.dynatrace.openkit.providers.SessionIDProvider; 24 | import com.dynatrace.openkit.providers.ThreadIDProvider; 25 | import com.dynatrace.openkit.providers.TimingProvider; 26 | 27 | /** 28 | * Provider of the input parameters for the {@link SessionCreator} 29 | */ 30 | public interface SessionCreatorInput { 31 | 32 | /** 33 | * Returns the logger to report/trace messages. 34 | */ 35 | Logger getLogger(); 36 | 37 | /** 38 | * Returns the application / device related configuration 39 | */ 40 | OpenKitConfiguration getOpenKitConfiguration(); 41 | 42 | /** 43 | * Returns the privacy related configuration 44 | */ 45 | PrivacyConfiguration getPrivacyConfiguration(); 46 | 47 | /** 48 | * Returns the beacon cache in which new sessions/beacons will be stored until they are sent. 49 | */ 50 | BeaconCache getBeaconCache(); 51 | 52 | /** 53 | * Returns the provider to obtain the next session ID 54 | */ 55 | SessionIDProvider getSessionIdProvider(); 56 | 57 | /** 58 | * Returns the provider to obtain the ID of the current thread. 59 | */ 60 | ThreadIDProvider getThreadIdProvider(); 61 | 62 | /** 63 | * Returns the provider to obtain the current timestamp. 64 | */ 65 | TimingProvider getTimingProvider(); 66 | 67 | /** 68 | * Returns the current server ID. 69 | */ 70 | int getCurrentServerId(); 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/SessionState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.Session; 20 | 21 | /** 22 | * Holds information about the current state of a session 23 | */ 24 | public interface SessionState { 25 | 26 | /** 27 | * Indicates whether the {@link com.dynatrace.openkit.api.Session} is configured or not. 28 | * 29 | *

30 | * A {@link com.dynatrace.openkit.api.Session} is considered as configured if it received configuration updates 31 | * from the server. 32 | *

33 | */ 34 | boolean isConfigured(); 35 | 36 | /** 37 | * Indicates if the {@link com.dynatrace.openkit.api.Session} is finished and was configured. 38 | */ 39 | boolean isConfiguredAndFinished(); 40 | 41 | /** 42 | * Indicates if the {@link com.dynatrace.openkit.api.Session} is configured and not yet finished. 43 | */ 44 | boolean isConfiguredAndOpen(); 45 | 46 | /** 47 | * Indicates if the {@link com.dynatrace.openkit.api.Session} is finished. 48 | * 49 | *

50 | * A session is considered as finished, after the {@link Session#end()} method was called. 51 | *

52 | */ 53 | boolean isFinished(); 54 | 55 | /** 56 | * Indicates that the session was tried for ending/closing but could not be closed due to still open Actions, Web 57 | * Requests. 58 | */ 59 | boolean wasTriedForEnding(); 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/SupplementaryBasicData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2022 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.ConnectionType; 20 | 21 | /** 22 | * Specifies supplementary basic data which will be written to the {@link com.dynatrace.openkit.protocol.Beacon} 23 | */ 24 | public interface SupplementaryBasicData { 25 | /** 26 | * Sets the network technology used by the device 27 | */ 28 | void setNetworkTechnology(String technology); 29 | 30 | /** 31 | * Returns the network technology used by the device 32 | * @return network technology 33 | */ 34 | String getNetworkTechnology(); 35 | 36 | /** 37 | * Sets the connection type used by the device 38 | */ 39 | void setConnectionType(ConnectionType connectionType); 40 | 41 | /** 42 | * Returns the connection type used by the device 43 | * @return connection type 44 | */ 45 | ConnectionType getConnectionType(); 46 | 47 | /** 48 | * Sets the carrier used by the device 49 | */ 50 | void setCarrier(String carrier); 51 | 52 | /** 53 | * Returns the carrier used by the device 54 | * @return carrier 55 | */ 56 | String getCarrier(); 57 | } -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/SupplementaryBasicDataImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2022 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.ConnectionType; 20 | 21 | public class SupplementaryBasicDataImpl implements SupplementaryBasicData { 22 | private String networkTechnology; 23 | private ConnectionType connectionType; 24 | private String carrier; 25 | 26 | @Override 27 | public synchronized void setNetworkTechnology(String technology) { 28 | this.networkTechnology = technology; 29 | } 30 | 31 | public synchronized String getNetworkTechnology() { 32 | return networkTechnology; 33 | } 34 | 35 | @Override 36 | public synchronized void setConnectionType(ConnectionType connectionType) { 37 | this.connectionType = connectionType; 38 | } 39 | 40 | public synchronized ConnectionType getConnectionType() { 41 | return connectionType; 42 | } 43 | 44 | @Override 45 | public synchronized void setCarrier(String carrier) { 46 | this.carrier = carrier; 47 | } 48 | 49 | public synchronized String getCarrier() { 50 | return carrier; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/objects/WebRequestTracerStringURL.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.Logger; 20 | import com.dynatrace.openkit.api.OpenKitConstants; 21 | import com.dynatrace.openkit.protocol.Beacon; 22 | 23 | import java.util.regex.Pattern; 24 | 25 | /** 26 | * Inherited class of {@link WebRequestTracerBaseImpl} which can be used for tracing and timing of a web request handled by any 3rd party HTTP Client. 27 | * 28 | *

29 | * Setting the Dynatrace tag to the {@link OpenKitConstants#WEBREQUEST_TAG_HEADER} HTTP header has to be done manually by the user. 30 | *

31 | */ 32 | public class WebRequestTracerStringURL extends WebRequestTracerBaseImpl { 33 | 34 | private static final Pattern SCHEMA_VALIDATION_PATTERN = Pattern.compile("^[a-z][a-z0-9+\\-.]*://.+", Pattern.CASE_INSENSITIVE); 35 | 36 | /** 37 | * Creates web request tracer with a simple string URL 38 | * 39 | * @param logger The logger used to log information 40 | * @param parent The parent object, to which this web request tracer belongs to 41 | * @param beacon {@link Beacon} for data sending and tag creation 42 | * @param url The URL to trace 43 | */ 44 | public WebRequestTracerStringURL(Logger logger, 45 | OpenKitComposite parent, 46 | Beacon beacon, 47 | String url) { 48 | super(logger, parent, extractURLParts(url), beacon); 49 | } 50 | 51 | /** 52 | * Extract URL parts of interest from given url. 53 | * 54 | *

55 | * The URL parts of interest are 56 | *

    57 | *
  • scheme
  • 58 | *
  • host
  • 59 | *
  • port
  • 60 | *
  • path
  • 61 | *
62 | *

63 | * 64 | * @param url The URL to trace, including all possible components 65 | * @return The {@code url} substring containing scheme, host, port, path 66 | */ 67 | private static String extractURLParts(String url) { 68 | // separate query string from URL 69 | if (isValidURLScheme(url)) { 70 | return url.split("\\?", 2)[0]; 71 | } 72 | 73 | return WebRequestTracerBaseImpl.UNKNOWN_URL; 74 | } 75 | 76 | /** 77 | * Tests if given {@code url} has a valid URL scheme. 78 | * 79 | * @param url The URL to test 80 | * @return {@code true} if the URL scheme is valid, {@code false} otherwise. 81 | */ 82 | static boolean isValidURLScheme(String url) { 83 | return url != null && SCHEMA_VALIDATION_PATTERN.matcher(url).matches(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/util/CrashFormatter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.util; 18 | 19 | import java.io.PrintWriter; 20 | import java.io.StringWriter; 21 | import java.io.Writer; 22 | 23 | /** 24 | * Utility class used to format a given {@link Throwable} into a format usable for OpenKit. 25 | */ 26 | public class CrashFormatter { 27 | 28 | private final Throwable throwable; 29 | 30 | public CrashFormatter(Throwable throwable) { 31 | this.throwable = throwable; 32 | } 33 | 34 | public String getName() { 35 | return throwable.getClass().getName(); 36 | } 37 | 38 | public String getReason() { 39 | // note: throwable.toString() will also use getLocalizedMessage() 40 | return throwable.getLocalizedMessage(); 41 | } 42 | 43 | public String getStackTrace() { 44 | StringWriter sw = new StringWriter(); 45 | PrintWriter pw = new StackTracePrintWriter(sw); 46 | throwable.printStackTrace(pw); 47 | return sw.getBuffer().toString(); 48 | } 49 | 50 | private static final class StackTracePrintWriter extends PrintWriter { 51 | 52 | private static final char NEWLINE = '\n'; 53 | 54 | private StackTracePrintWriter(Writer out) { 55 | super(out, true); 56 | } 57 | 58 | @Override 59 | public void println() { 60 | write(NEWLINE); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/util/EventPayloadBuilderUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.util; 18 | 19 | import com.dynatrace.openkit.core.objects.EventPayloadBuilder; 20 | import com.dynatrace.openkit.util.json.objects.JSONArrayValue; 21 | import com.dynatrace.openkit.util.json.objects.JSONNumberValue; 22 | import com.dynatrace.openkit.util.json.objects.JSONObjectValue; 23 | import com.dynatrace.openkit.util.json.objects.JSONValue; 24 | 25 | import java.util.Iterator; 26 | 27 | public class EventPayloadBuilderUtil { 28 | 29 | private EventPayloadBuilderUtil() { 30 | } 31 | 32 | private static boolean isObjectContainingNonFiniteNumericValues(JSONObjectValue jsonObject) { 33 | for(String key: jsonObject.keySet()) { 34 | if(isItemContainingNonFiniteNumericValues(jsonObject.get(key))) { 35 | return true; 36 | } 37 | } 38 | 39 | return false; 40 | } 41 | 42 | private static boolean isArrayContainingNonFiniteNumericValues(JSONArrayValue jsonArrayValue) { 43 | Iterator it = jsonArrayValue.iterator(); 44 | 45 | while(it.hasNext()) { 46 | if(isItemContainingNonFiniteNumericValues(it.next())) { 47 | return true; 48 | } 49 | } 50 | 51 | return false; 52 | } 53 | 54 | public static boolean isItemContainingNonFiniteNumericValues(JSONValue jsonValue) { 55 | return (jsonValue.isObject() && isObjectContainingNonFiniteNumericValues((JSONObjectValue) jsonValue)) 56 | || (jsonValue.isArray() && isArrayContainingNonFiniteNumericValues((JSONArrayValue) jsonValue)) 57 | || (jsonValue.isNumber() && !((JSONNumberValue) jsonValue).isFinite()); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/core/util/StringUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.dynatrace.openkit.core.util; 19 | 20 | public class StringUtil { 21 | 22 | private StringUtil() { 23 | } 24 | 25 | /** 26 | * Generates a 64 bit hash from the given string. 27 | * 28 | * @param stringValue the value to be hashed 29 | * @return the 64 bit hash of the given string ({@code 0} in case the given string is {@code null}) or empty. 30 | */ 31 | public static long to64BitHash(String stringValue) { 32 | if(stringValue == null) { 33 | return 0; 34 | } 35 | 36 | long hash = 0; 37 | 38 | for (int i = 0; i < stringValue.length(); i++) { 39 | hash = 31 * hash + stringValue.charAt(i); 40 | } 41 | return hash; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/protocol/AdditionalQueryParameters.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.protocol; 18 | 19 | /** 20 | * Provides additional parameters that will be appended when a server request is sent. 21 | */ 22 | public interface AdditionalQueryParameters { 23 | 24 | /** 25 | * Returns the current timestamp of the configuration received by the server 26 | */ 27 | long getConfigurationTimestamp(); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/protocol/BeaconInitializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.protocol; 18 | 19 | import com.dynatrace.openkit.api.Logger; 20 | import com.dynatrace.openkit.core.caching.BeaconCache; 21 | import com.dynatrace.openkit.core.objects.SupplementaryBasicData; 22 | import com.dynatrace.openkit.providers.RandomNumberGenerator; 23 | import com.dynatrace.openkit.providers.SessionIDProvider; 24 | import com.dynatrace.openkit.providers.ThreadIDProvider; 25 | import com.dynatrace.openkit.providers.TimingProvider; 26 | 27 | /** 28 | * Provides relevant data for initializing/creating a {@link Beacon} 29 | */ 30 | public interface BeaconInitializer { 31 | 32 | /** 33 | * Returns the logger for reporting messages. 34 | */ 35 | Logger getLogger(); 36 | 37 | /** 38 | * Returns the cache where the data of the beacon is stored until it gets sent. 39 | */ 40 | BeaconCache getBeaconCache(); 41 | 42 | /** 43 | * Returns the client IP address of the session / beacon. 44 | */ 45 | String getClientIpAddress(); 46 | 47 | /** 48 | * Returns the {@link SessionIDProvider} to obtain the identifier of the session / beacon 49 | */ 50 | SessionIDProvider getSessionIdProvider(); 51 | 52 | /** 53 | * Returns the sequence number for the beacon/session for identification in case of session split by events. The 54 | * session sequence number complements the session ID. 55 | */ 56 | int getSessionSequenceNumber(); 57 | 58 | /** 59 | * Returns the {@link ThreadIDProvider} to obtain the identifier of the current thread. 60 | */ 61 | ThreadIDProvider getThreadIdProvider(); 62 | 63 | /** 64 | * Returns the {@link TimingProvider} to obtain the current timestamp. 65 | */ 66 | TimingProvider getTimingProvider(); 67 | 68 | /** 69 | * Returns the {@link RandomNumberGenerator} to obtain random numbers (e.g. for randomizing device IDs) 70 | */ 71 | RandomNumberGenerator getRandomNumberGenerator(); 72 | 73 | /** 74 | * Returns the {@link SupplementaryBasicData} to obtain additional mutable basic data 75 | */ 76 | SupplementaryBasicData getSupplementaryBasicData(); 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/protocol/EventType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.protocol; 18 | 19 | /** 20 | * Event types used in the beacon protocol. 21 | */ 22 | public enum EventType implements SerializableBeaconValue { 23 | /** 24 | * Action event 25 | */ 26 | ACTION(1), 27 | /** 28 | * Report string value event 29 | */ 30 | VALUE_STRING(11), 31 | /** 32 | * Report integer value event 33 | */ 34 | VALUE_INT(12), 35 | /** 36 | * Report double value event 37 | */ 38 | VALUE_DOUBLE(13), 39 | /** 40 | * Named event 41 | */ 42 | NAMED_EVENT(10), 43 | /** 44 | * Session start event 45 | */ 46 | SESSION_START(18), 47 | /** 48 | * Session end event 49 | */ 50 | SESSION_END(19), 51 | /** 52 | * Tagged web request event 53 | */ 54 | WEB_REQUEST(30), 55 | /** 56 | * Report error code event 57 | */ 58 | ERROR(40), 59 | /** 60 | * Report exception event 61 | */ 62 | EXCEPTION(42), 63 | /** 64 | * Report crash event 65 | */ 66 | CRASH(50), 67 | /** 68 | * Identify user event 69 | */ 70 | IDENTIFY_USER(60), 71 | /** 72 | * Event API 73 | */ 74 | EVENT(98); 75 | 76 | private final int value; 77 | 78 | EventType(int value) { 79 | this.value = value; 80 | } 81 | 82 | public int protocolValue() { 83 | return value; 84 | } 85 | 86 | @Override 87 | public String asBeaconValue() { 88 | return String.valueOf(value); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/protocol/ProtocolConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.protocol; 18 | 19 | public class ProtocolConstants { 20 | 21 | // version constants 22 | public static final String OPENKIT_VERSION = "8.297.30400"; 23 | public static final int PROTOCOL_VERSION = 3; 24 | public static final int PLATFORM_TYPE_OPENKIT = 1; 25 | public static final String AGENT_TECHNOLOGY_TYPE = "okjava"; 26 | public static final String ERROR_TECHNOLOGY_TYPE = "c"; 27 | public static final String RESPONSE_TYPE = "json"; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/protocol/ResponseAttribute.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.dynatrace.openkit.protocol; 17 | 18 | /** 19 | * Specifies an attribute in the {@link ResponseAttributes} sent by the server. 20 | */ 21 | public enum ResponseAttribute { 22 | 23 | /** 24 | * Maximum POST body size when sending beacon data. 25 | */ 26 | MAX_BEACON_SIZE, 27 | 28 | /** 29 | * Maximum duration after which a session is split. 30 | */ 31 | MAX_SESSION_DURATION, 32 | 33 | /** 34 | * Maximum number of top level actions after which a session is split. 35 | */ 36 | MAX_EVENTS_PER_SESSION, 37 | 38 | /** 39 | * Idle timeout after which a session is split. 40 | */ 41 | SESSION_TIMEOUT, 42 | 43 | /** 44 | * Send interval 45 | */ 46 | SEND_INTERVAL, 47 | 48 | /** 49 | * Version of the visit store to be used. 50 | */ 51 | VISIT_STORE_VERSION, 52 | 53 | /** 54 | * Indicator whether capturing data is allowed or not. 55 | */ 56 | IS_CAPTURE, 57 | 58 | /** 59 | * Indicator whether crashes should be captured or not. 60 | */ 61 | IS_CAPTURE_CRASHES, 62 | 63 | /** 64 | * Indicator whether errors should be captured or not. 65 | */ 66 | IS_CAPTURE_ERRORS, 67 | 68 | /** 69 | * Sampling percentage for sessions. 70 | */ 71 | TRAFFIC_CONTROL_PERCENTAGE, 72 | 73 | /** 74 | * The ID of the application to which a configuration applies. 75 | */ 76 | APPLICATION_ID, 77 | 78 | /** 79 | * Multiplicity 80 | */ 81 | MULTIPLICITY, 82 | 83 | /** 84 | * The ID of the server to which data should be sent to. 85 | */ 86 | SERVER_ID, 87 | 88 | /** 89 | * Status of the new session configuration request. 90 | */ 91 | STATUS, 92 | 93 | /** 94 | * Timestamp of the configuration sent by the server. 95 | */ 96 | TIMESTAMP 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/protocol/ResponseParser.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.dynatrace.openkit.protocol; 17 | 18 | import com.dynatrace.openkit.util.json.parser.ParserException; 19 | 20 | /** 21 | * Evaluates a response string and transforms it into corresponding {@link ResponseAttributes} 22 | */ 23 | public class ResponseParser { 24 | 25 | private static final String KEY_VALUE_RESPONSE_TYPE_MOBILE = "type=m"; 26 | private static final String KEY_VALUE_RESPONSE_TYPE_MOBILE_WITH_SEPARATOR = "type=m&"; 27 | 28 | private ResponseParser() { 29 | } 30 | 31 | public static ResponseAttributes parseResponse(String responseString) throws ParserException { 32 | if (isKeyValuePairResponse(responseString)) { 33 | return KeyValueResponseParser.parse(responseString); 34 | } 35 | 36 | return JsonResponseParser.parse(responseString); 37 | } 38 | 39 | private static boolean isKeyValuePairResponse(String responseString) { 40 | return responseString.equals(KEY_VALUE_RESPONSE_TYPE_MOBILE) 41 | || responseString.startsWith(KEY_VALUE_RESPONSE_TYPE_MOBILE_WITH_SEPARATOR); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/protocol/SerializableBeaconValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.dynatrace.openkit.protocol; 19 | 20 | /** 21 | * Represents a single value which can be serialized to a corresponding beacon representation. 22 | */ 23 | public interface SerializableBeaconValue { 24 | 25 | /** 26 | * Returns the value of this instance in the form how it will be written to the beacon 27 | */ 28 | String asBeaconValue(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/protocol/http/HttpResponseHttpURLConnectionAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.dynatrace.openkit.protocol.http; 19 | 20 | import com.dynatrace.openkit.api.http.HttpResponse; 21 | 22 | import java.io.IOException; 23 | import java.net.HttpURLConnection; 24 | import java.net.URL; 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | public class HttpResponseHttpURLConnectionAdapter implements HttpResponse { 29 | 30 | private final HttpURLConnection httpURLConnection; 31 | 32 | public HttpResponseHttpURLConnectionAdapter(HttpURLConnection httpURLConnection) { 33 | this.httpURLConnection = httpURLConnection; 34 | } 35 | 36 | @Override 37 | public URL getRequestUrl() { 38 | return httpURLConnection.getURL(); 39 | } 40 | 41 | @Override 42 | public String getRequestMethod() { 43 | return httpURLConnection.getRequestMethod(); 44 | } 45 | 46 | @Override 47 | public int getResponseCode() { 48 | try { 49 | return httpURLConnection.getResponseCode(); 50 | } catch (IOException e) { 51 | return Integer.MIN_VALUE; 52 | } 53 | } 54 | 55 | @Override 56 | public String getResponseMessage() { 57 | try { 58 | return httpURLConnection.getResponseMessage(); 59 | } catch (IOException e) { 60 | return null; 61 | } 62 | } 63 | 64 | @Override 65 | public Map> getHeaders() { 66 | return httpURLConnection.getHeaderFields(); 67 | } 68 | 69 | @Override 70 | public String getHeader(String name) { 71 | return httpURLConnection.getHeaderField(name); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/protocol/http/NullHttpRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.dynatrace.openkit.protocol.http; 19 | 20 | import com.dynatrace.openkit.api.http.HttpRequest; 21 | import com.dynatrace.openkit.api.http.HttpRequestInterceptor; 22 | 23 | public class NullHttpRequestInterceptor implements HttpRequestInterceptor { 24 | 25 | /** 26 | * Sole instance of this class. 27 | */ 28 | public static final NullHttpRequestInterceptor INSTANCE = new NullHttpRequestInterceptor(); 29 | 30 | /** 31 | * Use {@link #INSTANCE} to retrieve the sole instance of this class. 32 | */ 33 | private NullHttpRequestInterceptor() { 34 | } 35 | 36 | @Override 37 | public void intercept(HttpRequest httpRequest) { 38 | // intentionally empty, due to null object pattern 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/protocol/http/NullHttpResponseInterceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.dynatrace.openkit.protocol.http; 19 | 20 | import com.dynatrace.openkit.api.http.HttpResponse; 21 | import com.dynatrace.openkit.api.http.HttpResponseInterceptor; 22 | 23 | public class NullHttpResponseInterceptor implements HttpResponseInterceptor { 24 | 25 | /** 26 | * Sole instance of this class. 27 | */ 28 | public static final NullHttpResponseInterceptor INSTANCE = new NullHttpResponseInterceptor(); 29 | 30 | /** 31 | * Use {@link #INSTANCE} to retrieve the sole instance of this class. 32 | */ 33 | private NullHttpResponseInterceptor() { 34 | } 35 | 36 | @Override 37 | public void intercept(HttpResponse httpResponse) { 38 | // intentionally empty, due to null object pattern 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/protocol/ssl/SSLStrictTrustManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.protocol.ssl; 18 | 19 | import com.dynatrace.openkit.api.SSLTrustManager; 20 | 21 | import javax.net.ssl.HostnameVerifier; 22 | import javax.net.ssl.HttpsURLConnection; 23 | import javax.net.ssl.TrustManager; 24 | import javax.net.ssl.TrustManagerFactory; 25 | import javax.net.ssl.X509TrustManager; 26 | import java.security.KeyStore; 27 | import java.security.KeyStoreException; 28 | import java.security.NoSuchAlgorithmException; 29 | 30 | /** 31 | * Implementation of {@link SSLTrustManager} trusting only valid certificates. 32 | *

33 | * This is the default strategy in SSL certificate validation and should NOT be changed. 34 | *

35 | */ 36 | public class SSLStrictTrustManager implements SSLTrustManager { 37 | 38 | private X509TrustManager cachedTrustManager = null; 39 | private String defaultAlgorithm = null; 40 | 41 | @Override 42 | public X509TrustManager getX509TrustManager() { 43 | 44 | String tmfDefaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm(); 45 | if (defaultAlgorithm == null || !defaultAlgorithm.equals(tmfDefaultAlgorithm)) { 46 | // not initialized yet or default algorithm was changed 47 | // the default algorithm may be changed during runtime by calling 48 | // Security.setProperty with property name "ssl.TrustManagerFactory.algorithm". 49 | cachedTrustManager = getX509TrustManager(tmfDefaultAlgorithm); 50 | defaultAlgorithm = tmfDefaultAlgorithm; 51 | } 52 | 53 | return cachedTrustManager; 54 | } 55 | 56 | private static X509TrustManager getX509TrustManager(String algorithm) { 57 | 58 | try { 59 | TrustManagerFactory factory = TrustManagerFactory.getInstance(algorithm); 60 | factory.init((KeyStore) null); // default keystore 61 | 62 | // get the first X509TrustManager instance 63 | for (TrustManager trustManager : factory.getTrustManagers()) { 64 | if (trustManager instanceof X509TrustManager) { 65 | return (X509TrustManager) trustManager; 66 | } 67 | } 68 | } catch (NoSuchAlgorithmException | KeyStoreException e) { 69 | // intentionally left empty 70 | } 71 | 72 | return null; 73 | } 74 | 75 | @Override 76 | public HostnameVerifier getHostnameVerifier() { 77 | // get the default hostname verifier 78 | // note this might be altered using HttpsURLConnection.setDefaultHostnameVerifier 79 | return HttpsURLConnection.getDefaultHostnameVerifier(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/DefaultHTTPClientProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.providers; 18 | 19 | import com.dynatrace.openkit.api.Logger; 20 | import com.dynatrace.openkit.core.configuration.HTTPClientConfiguration; 21 | import com.dynatrace.openkit.protocol.HTTPClient; 22 | 23 | /** 24 | * Implementation of an HTTPClientProvider which creates a HTTP client for executing status check and beacon send requests. 25 | */ 26 | public class DefaultHTTPClientProvider implements HTTPClientProvider { 27 | 28 | private final Logger logger; 29 | 30 | public DefaultHTTPClientProvider(Logger logger) { 31 | this.logger = logger; 32 | } 33 | 34 | @Override 35 | public HTTPClient createClient(HTTPClientConfiguration configuration) { 36 | return new HTTPClient(logger, configuration); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/DefaultRandomNumberGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.providers; 18 | 19 | import java.util.Random; 20 | 21 | /** 22 | * Default implementation for providing a random number. 23 | */ 24 | public class DefaultRandomNumberGenerator implements RandomNumberGenerator { 25 | 26 | private final Random random = new Random(); 27 | 28 | @Override 29 | public long nextPositiveLong() { 30 | return random.nextLong() & Long.MAX_VALUE; 31 | } 32 | 33 | @Override 34 | public int nextPercentageValue() { 35 | return random.nextInt(100); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/DefaultSessionIDProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.providers; 18 | 19 | import java.util.Random; 20 | 21 | public class DefaultSessionIDProvider implements SessionIDProvider { 22 | 23 | private int initialIntegerOffset; 24 | 25 | DefaultSessionIDProvider(int initialOffset) { 26 | this.initialIntegerOffset = initialOffset; 27 | } 28 | 29 | public DefaultSessionIDProvider() { 30 | this(new Random().nextInt(Integer.MAX_VALUE)); 31 | } 32 | 33 | @Override 34 | public synchronized int getNextSessionID() { 35 | if (initialIntegerOffset == Integer.MAX_VALUE) { 36 | initialIntegerOffset = 0; 37 | } 38 | initialIntegerOffset = initialIntegerOffset + 1; 39 | return initialIntegerOffset; 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/DefaultThreadIDProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.providers; 18 | 19 | /** 20 | * Simple ThreadIDProvider implementation for getting the current thread ID. 21 | */ 22 | public class DefaultThreadIDProvider implements ThreadIDProvider { 23 | 24 | @Override 25 | public int getThreadID() { 26 | long threadID64 = Thread.currentThread().getId(); 27 | return convertNativeThreadIDToPositiveInteger(threadID64); 28 | } 29 | 30 | /** 31 | * Converts a native thread id to a positive integer Thread.currentThread().getId() 32 | * 33 | *

34 | * Thread.currentThread().getId() returns a long value. 35 | * The Beacon protocol requires the thread id to be a positive integer value. By using the xor operation 36 | * between higher and lower 32 bits of the long value we get an integer value. The returned integer 37 | * can be negative though. 38 | * Therefore the most significant bit is forced to '0' by a bitwise-and operation with an integer 39 | * where all bits except for the most significant bit are set to '1'. 40 | *

41 | * 42 | * @param nativeThreadID the native thread id returned by 43 | * @return a positive integer value calculated from the native thread id 44 | */ 45 | public static int convertNativeThreadIDToPositiveInteger(long nativeThreadID) { 46 | return (int)((nativeThreadID ^ (nativeThreadID >>> 32)) & 0x7fffffff ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/DefaultTimingProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.providers; 18 | 19 | public class DefaultTimingProvider implements TimingProvider { 20 | 21 | /** 22 | * Factor used to convert between milliseconds and nanoseconds. 23 | */ 24 | static final long MILLIS_TO_NANOS_FACTOR = 1000L * 1000L; 25 | 26 | /** 27 | * Reference timestamp in nanoseconds. 28 | */ 29 | private final long referenceTimestampNanos; 30 | 31 | public DefaultTimingProvider() { 32 | referenceTimestampNanos = (System.currentTimeMillis() * MILLIS_TO_NANOS_FACTOR) - System.nanoTime(); 33 | } 34 | 35 | @Override 36 | public long provideTimestampInMilliseconds() { 37 | return (referenceTimestampNanos + System.nanoTime()) / MILLIS_TO_NANOS_FACTOR; 38 | } 39 | 40 | @Override 41 | public long provideTimestampInNanoseconds() { 42 | return referenceTimestampNanos + System.nanoTime(); 43 | } 44 | 45 | @Override 46 | public void sleep(long milliseconds) throws InterruptedException { 47 | 48 | Thread.sleep(milliseconds); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/FixedRandomNumberGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.providers; 18 | 19 | public class FixedRandomNumberGenerator implements RandomNumberGenerator { 20 | 21 | private final long randomNumber; 22 | private final int randomPercentage; 23 | 24 | public FixedRandomNumberGenerator(RandomNumberGenerator rng) { 25 | randomNumber = rng.nextPositiveLong(); 26 | randomPercentage = rng.nextPercentageValue(); 27 | } 28 | 29 | @Override 30 | public long nextPositiveLong() { 31 | return randomNumber; 32 | } 33 | 34 | @Override 35 | public int nextPercentageValue() { 36 | return randomPercentage; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/FixedSessionIdProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.providers; 18 | 19 | public class FixedSessionIdProvider implements SessionIDProvider { 20 | 21 | private final int sessionId; 22 | 23 | public FixedSessionIdProvider(SessionIDProvider sessionIDProvider) { 24 | sessionId = sessionIDProvider.getNextSessionID(); 25 | } 26 | 27 | @Override 28 | public int getNextSessionID() { 29 | return sessionId; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/HTTPClientProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.providers; 18 | 19 | import com.dynatrace.openkit.core.configuration.HTTPClientConfiguration; 20 | import com.dynatrace.openkit.protocol.HTTPClient; 21 | 22 | /** 23 | * Interface for providing an HTTP client. Mostly needed for testing purposes. 24 | */ 25 | public interface HTTPClientProvider { 26 | 27 | /** 28 | * Returns an HTTPClient based on the provided configuration. 29 | */ 30 | HTTPClient createClient(HTTPClientConfiguration configuration); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/HttpURLConnectionWrapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.providers; 18 | 19 | import java.io.IOException; 20 | import java.net.HttpURLConnection; 21 | 22 | /** 23 | * Interface wrapping {@link HttpURLConnection} creation. Implementations can support connection retry. 24 | */ 25 | public interface HttpURLConnectionWrapper { 26 | 27 | /** 28 | * Get a HttpURLConnection generated from the implementation specifics 29 | * 30 | * @return {@link HttpURLConnection} which is generated 31 | */ 32 | HttpURLConnection getHttpURLConnection() throws IOException; 33 | 34 | 35 | /** 36 | * Returns retry allowed status 37 | * 38 | * @return {@code true} if retry is allowed and {@code false} if retry is not allowed 39 | */ 40 | boolean isRetryAllowed(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/RandomNumberGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.providers; 18 | 19 | /** 20 | * Generator for random numbers 21 | */ 22 | public interface RandomNumberGenerator { 23 | 24 | /** 25 | * Returns a positive random long number (including {@code 0}). 26 | */ 27 | long nextPositiveLong(); 28 | 29 | /** 30 | * Returns a positive random integer number in range [{@code 0}, {@code 100}). 31 | */ 32 | int nextPercentageValue(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/SessionIDProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.providers; 18 | 19 | /** 20 | * Interface providing consecutive numbers starting at a random offset 21 | */ 22 | public interface SessionIDProvider { 23 | 24 | /** 25 | * Provide the next sessionID 26 | * All positive integers greater than 0 can be used as sessionID 27 | * 28 | * @return the id that will be used for the next session 29 | */ 30 | int getNextSessionID(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/ThreadIDProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.providers; 18 | 19 | /** 20 | * Interface that provides the thread id 21 | */ 22 | public interface ThreadIDProvider { 23 | /** 24 | * Return s the current thread id 25 | * 26 | * @return 27 | */ 28 | int getThreadID(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/providers/TimingProvider.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.providers; 18 | 19 | /** 20 | * Interface providing timing related functionality. 21 | */ 22 | public interface TimingProvider { 23 | 24 | /** 25 | * Provide the current timestamp in milliseconds. 26 | */ 27 | long provideTimestampInMilliseconds(); 28 | 29 | /** 30 | * Provide the current timestamp in nanoseconds. 31 | */ 32 | long provideTimestampInNanoseconds(); 33 | 34 | /** 35 | * Sleep given amount of milliseconds. 36 | * 37 | * @throws InterruptedException When the sleep call gets interrupted. 38 | */ 39 | void sleep(long milliseconds) throws InterruptedException; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/util/json/constants/JSONLiterals.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.util.json.constants; 18 | 19 | import java.util.regex.Pattern; 20 | 21 | /** 22 | * Class storing the JSON literals. 23 | */ 24 | public class JSONLiterals { 25 | 26 | /** boolean true literal */ 27 | public static final String BOOLEAN_TRUE_LITERAL = "true"; 28 | /** boolean false literal */ 29 | public static final String BOOLEAN_FALSE_LITERAL = "false"; 30 | /** null literal */ 31 | public static final String NULL_LITERAL = "null"; 32 | 33 | /** regex pattern for parsing number literals */ 34 | public static final Pattern NUMBER_PATTERN = Pattern.compile("^-?(0|[1-9]\\d*)(\\.\\d+)?([eE][+-]?\\d+)?$"); 35 | 36 | /** 37 | * Default constructor. 38 | * 39 | *

40 | * This ctor should be private, since this class contains only constants. 41 | *

42 | */ 43 | private JSONLiterals() { 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/util/json/lexer/LexerException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.util.json.lexer; 18 | 19 | /** 20 | * Exception class thrown by the lexical analyzer in case of error. 21 | */ 22 | public class LexerException extends Exception { 23 | 24 | /** 25 | * Constructor taking an exception message. 26 | * 27 | * @param message The message describing the cause of this exception. 28 | */ 29 | public LexerException(String message) { 30 | super(message); 31 | } 32 | 33 | /** 34 | * Constructor taking an exception message and a nested {@link Throwable}. 35 | * 36 | * @param message The message describing the cause of this exception. 37 | * @param throwable The nested {@link Throwable} originally causing this exception. 38 | */ 39 | public LexerException(String message, Throwable throwable) { 40 | super(message, throwable); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/util/json/objects/JSONNullValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.util.json.objects; 18 | 19 | import com.dynatrace.openkit.util.json.constants.JSONLiterals; 20 | 21 | /** 22 | * JSON value class representing a null value. 23 | */ 24 | public class JSONNullValue extends JSONValue { 25 | 26 | /** 27 | * The sole instance of this class. 28 | */ 29 | public static final JSONNullValue NULL = new JSONNullValue(); 30 | 31 | /** 32 | * Constructor. 33 | * 34 | *

35 | * To avoid object churn, use {@link #NULL}, which is the only instance of this class. 36 | *

37 | */ 38 | private JSONNullValue() { 39 | } 40 | 41 | @Override 42 | public boolean isNull() { 43 | return true; 44 | } 45 | 46 | @Override 47 | void writeJSONString(JSONValueWriter writer, JSONOutputConfig config) { 48 | writer.insertValue(JSONLiterals.NULL_LITERAL); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/util/json/objects/JSONOutputConfig.java: -------------------------------------------------------------------------------- 1 | package com.dynatrace.openkit.util.json.objects; 2 | 3 | /** 4 | * Determines the content of the output string when json is converted 5 | */ 6 | public enum JSONOutputConfig { 7 | /** 8 | * Outputs all valid json values 9 | */ 10 | DEFAULT, 11 | /** 12 | * Outpus all valid json values but will ignore null values 13 | */ 14 | IGNORE_NULL 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/util/json/objects/JSONStringValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.util.json.objects; 18 | 19 | /** 20 | * JSON value class representing a string value. 21 | */ 22 | public class JSONStringValue extends JSONValue { 23 | 24 | /** The underlying string value */ 25 | private final String stringValue; 26 | 27 | /** 28 | * Constructor taking the underlying string value. 29 | * 30 | *

31 | * To create an instance of {@link JSONStringValue} use the factory method {@link #fromString(String)}. 32 | *

33 | * 34 | * @param stringValue The string value of this JSON string. 35 | */ 36 | private JSONStringValue(String stringValue) { 37 | this.stringValue = stringValue; 38 | } 39 | 40 | /** 41 | * Factory method to create a {@link JSONStringValue} and initialize it with given string. 42 | * 43 | * @param stringValue The string value used for initializing this instance. 44 | * 45 | * @return Newly created {@link JSONStringValue} or {@code null} if argument is {@code null}. 46 | */ 47 | public static JSONStringValue fromString(String stringValue) { 48 | return stringValue == null ? null : new JSONStringValue(stringValue); 49 | } 50 | 51 | @Override 52 | public boolean isString() { 53 | return true; 54 | } 55 | 56 | /** 57 | * Get the underlying string. 58 | * 59 | * @return String value. 60 | */ 61 | public String getValue() { 62 | return stringValue; 63 | } 64 | 65 | @Override 66 | void writeJSONString(JSONValueWriter writer, JSONOutputConfig config) { 67 | writer.insertStringValue(getValue()); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/util/json/parser/JSONParserState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.util.json.parser; 18 | 19 | public enum JSONParserState { 20 | INIT, // initial state of the JSON parser 21 | IN_ARRAY_START, // state when start of array was encountered 22 | IN_ARRAY_VALUE, // state in array, after value has been parsed 23 | IN_ARRAY_DELIMITER, // state in array, after delimiter has been parsed 24 | IN_OBJECT_START, // state when start of object was encountered 25 | IN_OBJECT_KEY, // state in object, after key has been parsed 26 | IN_OBJECT_COLON, // state in object, after key value delimiter (":") has been parsed 27 | IN_OBJECT_VALUE, // state in object, after value has been parsed 28 | IN_OBJECT_DELIMITER, // state in object, after comma delimiter has been parsed 29 | END, // end state of the JSON parser 30 | ERROR // error state 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/dynatrace/openkit/util/json/parser/ParserException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.util.json.parser; 18 | 19 | /** 20 | * Exception class thrown by the JSON parser in case of error. 21 | */ 22 | public class ParserException extends Exception { 23 | 24 | /** 25 | * Constructor taking an exception message. 26 | * 27 | * @param message The message describing the cause of this exception. 28 | */ 29 | public ParserException(String message) { 30 | super(message); 31 | } 32 | 33 | /** 34 | * Constructor taking an exception message and a nested {@link Throwable}. 35 | * 36 | * @param message The message describing the cause of this exception. 37 | * @param throwable The nested {@link Throwable} originally causing this exception. 38 | */ 39 | public ParserException(String message, Throwable throwable) { 40 | super(message, throwable); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/CrashReportingLevelTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit; 18 | 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.junit.runners.Parameterized; 22 | 23 | import java.util.Arrays; 24 | import java.util.Collection; 25 | 26 | import static org.hamcrest.Matchers.is; 27 | import static org.junit.Assert.assertThat; 28 | 29 | @RunWith(Parameterized.class) 30 | public class CrashReportingLevelTest { 31 | 32 | @Parameterized.Parameter 33 | public int expectedValue; 34 | 35 | @Parameterized.Parameter(1) 36 | public CrashReportingLevel crashReportingLevel; 37 | 38 | @Parameterized.Parameters 39 | public static Collection parameters() { 40 | return Arrays.asList(new Object[][] { 41 | {0, CrashReportingLevel.OFF}, 42 | {1, CrashReportingLevel.OPT_OUT_CRASHES}, 43 | {2, CrashReportingLevel.OPT_IN_CRASHES} 44 | }); 45 | } 46 | 47 | @Test 48 | public void hasCorrectValue() { 49 | assertThat(crashReportingLevel.getIntValue(), is(expectedValue)); 50 | assertThat(crashReportingLevel.asBeaconValue(), is(String.valueOf(expectedValue))); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/DataCollectionLevelTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit; 18 | 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.junit.runners.Parameterized; 22 | import org.junit.runners.Parameterized.Parameter; 23 | import org.junit.runners.Parameterized.Parameters; 24 | 25 | import java.util.Arrays; 26 | import java.util.Collection; 27 | 28 | import static org.hamcrest.Matchers.is; 29 | import static org.junit.Assert.assertThat; 30 | 31 | @RunWith(Parameterized.class) 32 | public class DataCollectionLevelTest { 33 | 34 | @Parameter 35 | public int expectedValue; 36 | 37 | @Parameter(1) 38 | public DataCollectionLevel dataCollectionLevel; 39 | 40 | @Parameters 41 | public static Collection parameters() { 42 | return Arrays.asList(new Object[][] { 43 | {0, DataCollectionLevel.OFF}, 44 | {1, DataCollectionLevel.PERFORMANCE}, 45 | {2, DataCollectionLevel.USER_BEHAVIOR} 46 | }); 47 | } 48 | 49 | @Test 50 | public void hasCorrectValue() { 51 | assertThat(dataCollectionLevel.getIntValue(), is(expectedValue)); 52 | assertThat(dataCollectionLevel.asBeaconValue(), is(String.valueOf(expectedValue))); 53 | } 54 | 55 | @Test 56 | public void asBeaconValueReturnsCorrectValue() { 57 | // when, then 58 | assertThat(DataCollectionLevel.OFF.asBeaconValue(), is("0")); 59 | assertThat(DataCollectionLevel.PERFORMANCE.asBeaconValue(), is("1")); 60 | assertThat(DataCollectionLevel.USER_BEHAVIOR.asBeaconValue(), is("2")); 61 | } 62 | 63 | @Test 64 | public void defaultValueIsUserBehavior() { 65 | // when, then 66 | assertThat(DataCollectionLevel.defaultValue(), is(DataCollectionLevel.USER_BEHAVIOR)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/core/communication/AbstractBeaconSendingStateTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.communication; 18 | 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | 22 | import static org.hamcrest.Matchers.is; 23 | import static org.junit.Assert.assertThat; 24 | import static org.mockito.Mockito.doCallRealMethod; 25 | import static org.mockito.Mockito.doThrow; 26 | import static org.mockito.Mockito.mock; 27 | import static org.mockito.Mockito.times; 28 | import static org.mockito.Mockito.verify; 29 | import static org.mockito.Mockito.verifyNoMoreInteractions; 30 | 31 | public class AbstractBeaconSendingStateTest { 32 | 33 | private AbstractBeaconSendingState mockState; 34 | private BeaconSendingContext mockContext; 35 | 36 | @Before 37 | public void setUp() { 38 | mockState = mock(AbstractBeaconSendingState.class); 39 | doCallRealMethod().when(mockState).execute(org.mockito.Mockito.any(BeaconSendingContext.class)); 40 | mockContext = mock(BeaconSendingContext.class); 41 | } 42 | 43 | @Test 44 | public void aTestBeaconSendingStateExecutes() throws InterruptedException { 45 | 46 | // when calling execute 47 | mockState.execute(mockContext); 48 | 49 | // then verify doExecute was called 50 | verify(mockState, times(1)).doExecute(mockContext); 51 | 52 | // also verify that shutdown requested is queried, but nothing else 53 | verify(mockContext, times(1)).isShutdownRequested(); 54 | verifyNoMoreInteractions(mockContext); 55 | } 56 | 57 | 58 | @Test 59 | public void aTestBeaconSendingStateExecutesButIsInterrupted() throws InterruptedException { 60 | 61 | // when calling execute leads to an InterruptedException 62 | doThrow(new InterruptedException()).when(mockState).doExecute(mockContext); 63 | mockState.execute(mockContext); 64 | 65 | /* 66 | check and reset interrupted flag 67 | if the flag is not reset, subsequent tests might fail 68 | */ 69 | assertThat(Thread.interrupted(), is(true)); 70 | 71 | // then verify doExecute was called 72 | verify(mockState, times(1)).doExecute(mockContext); 73 | 74 | // also verify that shutdown requested is queried, but nothing else 75 | verify(mockState, times(1)).onInterrupted(mockContext); 76 | verify(mockContext, times(1)).isShutdownRequested(); 77 | verify(mockContext, times(1)).requestShutdown(); 78 | verifyNoMoreInteractions(mockContext); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/core/communication/BeaconSendingTerminalStateTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.communication; 18 | 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | 22 | import static org.hamcrest.Matchers.equalTo; 23 | import static org.hamcrest.Matchers.instanceOf; 24 | import static org.hamcrest.Matchers.is; 25 | import static org.hamcrest.Matchers.notNullValue; 26 | import static org.hamcrest.Matchers.sameInstance; 27 | import static org.junit.Assert.assertThat; 28 | import static org.mockito.Mockito.mock; 29 | import static org.mockito.Mockito.times; 30 | import static org.mockito.Mockito.verify; 31 | import static org.mockito.Mockito.verifyNoMoreInteractions; 32 | 33 | public class BeaconSendingTerminalStateTest { 34 | 35 | private BeaconSendingContext stateContext; 36 | 37 | @Before 38 | public void setUp() { 39 | 40 | stateContext = mock(BeaconSendingContext.class); 41 | } 42 | 43 | @Test 44 | public void isTerminalStateIsTrueForTheTerminalState() { 45 | 46 | // given 47 | BeaconSendingTerminalState target = new BeaconSendingTerminalState(); 48 | 49 | // when/then 50 | assertThat(target.isTerminalState(), is(true)); 51 | } 52 | 53 | @Test 54 | public void theShutdownStateIsAlwaysTheSameReference() { 55 | 56 | // given 57 | BeaconSendingTerminalState target = new BeaconSendingTerminalState(); 58 | 59 | // when 60 | AbstractBeaconSendingState obtained = target.getShutdownState(); 61 | 62 | // then 63 | assertThat(obtained, is(notNullValue())); 64 | assertThat(obtained, is(instanceOf(BeaconSendingTerminalState.class))); 65 | assertThat((BeaconSendingTerminalState) obtained, is(sameInstance(target))); 66 | } 67 | 68 | @Test 69 | public void toStringReturnsTheStateName() { 70 | 71 | // given 72 | BeaconSendingTerminalState target = new BeaconSendingTerminalState(); 73 | 74 | // then 75 | assertThat(target.toString(), is(equalTo("Terminal"))); 76 | } 77 | 78 | @Test 79 | public void executeRequestsShutdown() { 80 | 81 | // given 82 | BeaconSendingTerminalState target = new BeaconSendingTerminalState(); 83 | 84 | // when executing the state 85 | target.execute(stateContext); 86 | 87 | // verify shutdown is requested now 88 | verify(stateContext, times(1)).requestShutdown(); 89 | verify(stateContext, times(1)).isShutdownRequested(); 90 | verifyNoMoreInteractions(stateContext); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/core/objects/LeafActionImplTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.Action; 20 | import com.dynatrace.openkit.api.Logger; 21 | import com.dynatrace.openkit.protocol.Beacon; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | 25 | import static org.hamcrest.Matchers.equalTo; 26 | import static org.hamcrest.Matchers.is; 27 | import static org.hamcrest.Matchers.notNullValue; 28 | import static org.hamcrest.Matchers.sameInstance; 29 | import static org.junit.Assert.assertThat; 30 | import static org.mockito.Mockito.mock; 31 | import static org.mockito.Mockito.when; 32 | 33 | public class LeafActionImplTest { 34 | 35 | private static final String ACTION_NAME = "TestAction"; 36 | 37 | private Logger logger; 38 | private RootActionImpl rootAction; 39 | private Beacon beacon; 40 | 41 | @Before 42 | public void setUp() { 43 | logger = mock(Logger.class); 44 | when(logger.isInfoEnabled()).thenReturn(true); 45 | when(logger.isDebugEnabled()).thenReturn(true); 46 | 47 | rootAction = mock(RootActionImpl.class); 48 | 49 | beacon = mock(Beacon.class); 50 | } 51 | 52 | @Test 53 | public void getParentActionReturnsValuePassedInConstructor() { 54 | // given 55 | LeafActionImpl target = new LeafActionImpl(logger, rootAction, ACTION_NAME, beacon); 56 | 57 | // when 58 | Action obtained = target.getParentAction(); 59 | 60 | // then 61 | assertThat(obtained, is(notNullValue())); 62 | assertThat(obtained, is(sameInstance((Action)rootAction))); 63 | } 64 | 65 | @Test 66 | public void toStringReturnsAppropriateResult() { 67 | // given 68 | when(beacon.getSessionNumber()).thenReturn(21); 69 | when(beacon.createID()).thenReturn(1, 2, 3, 100); 70 | when(rootAction.getActionID()).thenReturn(42); 71 | 72 | LeafActionImpl target = new LeafActionImpl(logger, rootAction, ACTION_NAME, beacon); 73 | 74 | // when 75 | String obtained = target.toString(); 76 | 77 | // then 78 | assertThat(obtained, is(equalTo("LeafActionImpl [sn=21, id=1, name=" + ACTION_NAME + ", pa=42] "))); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/core/objects/NullSessionTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.core.objects; 18 | 19 | import com.dynatrace.openkit.api.RootAction; 20 | import com.dynatrace.openkit.api.WebRequestTracer; 21 | import org.junit.Test; 22 | 23 | import java.net.URLConnection; 24 | 25 | import static org.hamcrest.Matchers.instanceOf; 26 | import static org.hamcrest.Matchers.is; 27 | import static org.hamcrest.Matchers.sameInstance; 28 | import static org.junit.Assert.assertThat; 29 | import static org.mockito.Mockito.mock; 30 | 31 | public class NullSessionTest { 32 | 33 | @Test 34 | public void enterActionReturnsNullRootAction() { 35 | // given 36 | NullSession target = NullSession.INSTANCE; 37 | 38 | // when 39 | RootAction obtained = target.enterAction("action name"); 40 | 41 | // then 42 | assertThat(obtained, instanceOf(NullRootAction.class)); 43 | assertThat((NullRootAction)obtained, is(sameInstance(NullRootAction.INSTANCE))); 44 | } 45 | 46 | @Test 47 | public void traceWebRequestWithConnectionUrlReturnsNullWebRequestTracer() { 48 | // given 49 | NullSession target = NullSession.INSTANCE; 50 | 51 | // when 52 | WebRequestTracer obtained = target.traceWebRequest(mock(URLConnection.class)); 53 | 54 | // then 55 | assertThat(obtained, instanceOf(NullWebRequestTracer.class)); 56 | assertThat((NullWebRequestTracer)obtained, is(sameInstance(NullWebRequestTracer.INSTANCE))); 57 | } 58 | 59 | @Test 60 | public void traceWebRequestWithUrlStringReturnsNullWebRequestTracer() { 61 | // given 62 | NullSession target = NullSession.INSTANCE; 63 | 64 | // when 65 | WebRequestTracer obtained = target.traceWebRequest("https://localhost"); 66 | 67 | // then 68 | assertThat(obtained, instanceOf(NullWebRequestTracer.class)); 69 | assertThat((NullWebRequestTracer)obtained, is(sameInstance(NullWebRequestTracer.INSTANCE))); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/core/util/PercentEncoderTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.util; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.hamcrest.Matchers.equalTo; 22 | import static org.hamcrest.Matchers.is; 23 | import static org.hamcrest.Matchers.nullValue; 24 | import static org.junit.Assert.assertThat; 25 | 26 | public class PercentEncoderTest { 27 | 28 | /** 29 | * All unreserved characters based on RFC-3986 30 | */ 31 | private static final String UNRESERVED_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~"; 32 | 33 | @Test 34 | public void rfc3986UnreservedCharactersAreNotEncoded() { 35 | // when 36 | String obtained = PercentEncoder.encode(UNRESERVED_CHARACTERS, "UTF-8"); 37 | 38 | // then 39 | assertThat(obtained, is(equalTo(UNRESERVED_CHARACTERS))); 40 | } 41 | 42 | @Test 43 | public void reservedCharactersArePercentEncoded() { 44 | // when 45 | String obtained = PercentEncoder.encode("+()/\\&%$#@!`?<>[]{}", "UTF-8"); 46 | 47 | // then 48 | String expected = "%2B%28%29%2F%5C%26%25%24%23%40%21%60%3F%3C%3E%5B%5D%7B%7D"; // precomputed using Python 49 | assertThat(obtained, is(equalTo(expected))); 50 | } 51 | 52 | @Test 53 | public void mixingReservedAndUnreservedCharactersWorks() { 54 | // when 55 | String obtained = PercentEncoder.encode("a+bc()~/\\&0_", "UTF-8"); 56 | 57 | // then 58 | String expected = "a%2Bbc%28%29~%2F%5C%260_"; // precomputed using Python 59 | assertThat(obtained, is(equalTo(expected))); 60 | } 61 | 62 | @Test 63 | public void charactersOutsideOfAsciiRangeAreEncodedFirst() { 64 | // when 65 | String obtained = PercentEncoder.encode("aösÖ€dÁF", "UTF-8"); 66 | 67 | // then 68 | String expected = "a%C3%B6s%C3%96%E2%82%ACd%C3%81F"; 69 | assertThat(obtained, is(equalTo(expected))); 70 | } 71 | 72 | @Test 73 | public void itIsPossibleToMarkAdditionalCharactersAsReserved() { 74 | // when 75 | String additionalReservedCharacters = "€0_"; 76 | String obtained = PercentEncoder.encode("0123456789-._~", "UTF-8", additionalReservedCharacters.toCharArray()); 77 | 78 | // then 79 | String expected = "%30123456789-.%5F~"; 80 | assertThat(obtained, is(equalTo(expected))); 81 | } 82 | 83 | @Test 84 | public void nullIsReturnedIfEncodingIsNecessaryButIsNotKnown() { 85 | // when 86 | String obtained = PercentEncoder.encode("a€b", "this-is-really-no-valid-encoding"); 87 | 88 | // then 89 | assertThat(obtained, is(nullValue())); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/core/util/StringUtilTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.dynatrace.openkit.core.util; 19 | 20 | import org.junit.Test; 21 | 22 | import static org.hamcrest.Matchers.equalTo; 23 | import static org.hamcrest.Matchers.is; 24 | import static org.hamcrest.Matchers.not; 25 | import static org.junit.Assert.assertNotSame; 26 | import static org.junit.Assert.assertThat; 27 | 28 | public class StringUtilTest { 29 | 30 | @Test 31 | public void hashNullString() { 32 | // given, when 33 | long hash = StringUtil.to64BitHash(null); 34 | 35 | // then 36 | assertThat(hash, is(equalTo(0L))); 37 | } 38 | 39 | @Test 40 | public void hashEmptyString() { 41 | // given 42 | String emptString = ""; 43 | 44 | // when 45 | long hash = StringUtil.to64BitHash(emptString); 46 | 47 | //then 48 | assertThat(hash, is(equalTo(0L))); 49 | } 50 | 51 | @Test 52 | public void differentStringsDifferentHash() { 53 | // given 54 | String firstString = "some string"; 55 | String secondString = "some other string"; 56 | 57 | // when 58 | long firstHash = StringUtil.to64BitHash(firstString); 59 | long secondHash = StringUtil.to64BitHash(secondString); 60 | 61 | //then 62 | assertThat(firstHash, not(equalTo(secondHash))); 63 | } 64 | 65 | @Test 66 | public void equalStringSameHash() { 67 | // given 68 | String firstString = "str"; 69 | String secondString = String.valueOf(new char[]{'s', 't', 'r'}); 70 | 71 | // when 72 | long firstHash = StringUtil.to64BitHash(firstString); 73 | long secondHash = StringUtil.to64BitHash(secondString); 74 | 75 | // then 76 | assertNotSame(firstString, secondString); 77 | assertThat(firstString, is(equalTo(secondString))); 78 | assertThat(firstHash, is(equalTo(secondHash))); 79 | } 80 | 81 | @Test 82 | public void caseSensitiveStringsDifferentHash() { 83 | // given 84 | String lowerCase = "value"; 85 | String upperCase = "Value"; 86 | 87 | // when 88 | long lowerCaseHash = StringUtil.to64BitHash(lowerCase); 89 | long upperCaseHash = StringUtil.to64BitHash(upperCase); 90 | 91 | // 92 | assertThat(lowerCaseHash, not(equalTo(upperCaseHash))); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/protocol/EventPayloadMatcher.java: -------------------------------------------------------------------------------- 1 | package com.dynatrace.openkit.protocol; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.mockito.ArgumentMatcher; 6 | 7 | /** 8 | * @author matthias.hochrieser 9 | */ 10 | public class EventPayloadMatcher implements ArgumentMatcher { 11 | 12 | private final String expectedEventPayload; 13 | 14 | public EventPayloadMatcher(String expectedEventPayload){ 15 | this.expectedEventPayload = expectedEventPayload; 16 | } 17 | 18 | @Override 19 | public boolean matches(String argument) { 20 | String actualEventPayload = (String) argument; 21 | 22 | if(expectedEventPayload.contentEquals(actualEventPayload)){ 23 | return true; 24 | } 25 | 26 | // Check if both of them are not null 27 | if(expectedEventPayload == null ^ actualEventPayload == null){ 28 | return false; 29 | } 30 | 31 | // Check for beginning of event payload 32 | if(!(expectedEventPayload.startsWith("et=98&pl=") && actualEventPayload.startsWith("et=98&pl="))){ 33 | return false; 34 | } 35 | 36 | String expectedPayload = expectedEventPayload.substring(expectedEventPayload.indexOf("pl=") + "pl=".length()); 37 | expectedPayload = removeEncodedBrackets(expectedPayload); 38 | 39 | String actualPayload = actualEventPayload.substring(actualEventPayload.indexOf("pl=") + "pl=".length()); 40 | actualPayload = removeEncodedBrackets(actualPayload); 41 | 42 | String[] expectedPayloadValues = expectedPayload.split("%2C"); 43 | Arrays.sort(expectedPayloadValues); 44 | 45 | String[] actualPayloadValues = actualPayload.split("%2C"); 46 | Arrays.sort(actualPayloadValues); 47 | 48 | return Arrays.equals(expectedPayloadValues, actualPayloadValues); 49 | } 50 | 51 | private String removeEncodedBrackets(String payload){ 52 | String editedPayload = payload.replaceAll("%7B", ""); 53 | editedPayload = editedPayload.replaceAll("%7D", ""); 54 | return editedPayload; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/protocol/EventTypeTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.protocol; 18 | 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.junit.runners.Parameterized; 22 | import org.junit.runners.Parameterized.Parameter; 23 | import org.junit.runners.Parameterized.Parameters; 24 | 25 | import java.util.Arrays; 26 | import java.util.Collection; 27 | 28 | import static org.hamcrest.Matchers.is; 29 | import static org.junit.Assert.assertThat; 30 | 31 | @RunWith(Parameterized.class) 32 | public class EventTypeTest { 33 | 34 | @Parameter 35 | public int expectedValue; 36 | 37 | @Parameter(1) 38 | public EventType eventType; 39 | 40 | @Parameters(name = "expected: {0}, EventType: {1}") 41 | public static Collection parameters() { 42 | return Arrays.asList(new Object[][]{ 43 | {1, EventType.ACTION}, 44 | {10, EventType.NAMED_EVENT}, 45 | {11, EventType.VALUE_STRING}, 46 | {12, EventType.VALUE_INT}, 47 | {13, EventType.VALUE_DOUBLE}, 48 | {18, EventType.SESSION_START}, 49 | {19, EventType.SESSION_END}, 50 | {30, EventType.WEB_REQUEST}, 51 | {40, EventType.ERROR}, 52 | {42, EventType.EXCEPTION}, 53 | {50, EventType.CRASH}, 54 | {60, EventType.IDENTIFY_USER} 55 | }); 56 | } 57 | 58 | @Test 59 | public void eventTypeValue() { 60 | assertThat(eventType.protocolValue(), is(expectedValue)); 61 | assertThat(eventType.asBeaconValue(), is(String.valueOf(expectedValue))); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/protocol/http/NullHttpRequestInterceptorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.protocol.http; 18 | 19 | import com.dynatrace.openkit.api.http.HttpRequest; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import static org.mockito.Mockito.mock; 24 | import static org.mockito.Mockito.verifyNoInteractions; 25 | 26 | public class NullHttpRequestInterceptorTest { 27 | 28 | private HttpRequest mockHttpRequest; 29 | 30 | @Before 31 | public void setUp() { 32 | mockHttpRequest = mock(HttpRequest.class); 33 | } 34 | 35 | @Test 36 | public void interceptDoesNotInteractWithHttpRequest() { 37 | // given 38 | NullHttpRequestInterceptor target = NullHttpRequestInterceptor.INSTANCE; 39 | 40 | // when 41 | target.intercept(mockHttpRequest); 42 | 43 | // then 44 | verifyNoInteractions(mockHttpRequest); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/protocol/http/NullHttpResponseInterceptorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.protocol.http; 18 | 19 | import com.dynatrace.openkit.api.http.HttpResponse; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import static org.mockito.Mockito.mock; 24 | import static org.mockito.Mockito.verifyNoInteractions; 25 | 26 | public class NullHttpResponseInterceptorTest { 27 | 28 | private HttpResponse mockHttpResponse; 29 | 30 | @Before 31 | public void setUp() { 32 | mockHttpResponse = mock(HttpResponse.class); 33 | } 34 | 35 | @Test 36 | public void interceptDoesNotInteractWithHttpResponse() { 37 | // given 38 | NullHttpResponseInterceptor target = NullHttpResponseInterceptor.INSTANCE; 39 | 40 | // when 41 | target.intercept(mockHttpResponse); 42 | 43 | // then 44 | verifyNoInteractions(mockHttpResponse); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/providers/DefaultHttpClientProviderTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.providers; 18 | 19 | import com.dynatrace.openkit.api.Logger; 20 | import com.dynatrace.openkit.core.configuration.HTTPClientConfiguration; 21 | import com.dynatrace.openkit.protocol.HTTPClient; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | 25 | import static org.hamcrest.Matchers.is; 26 | import static org.hamcrest.Matchers.notNullValue; 27 | import static org.junit.Assert.assertThat; 28 | import static org.mockito.Mockito.mock; 29 | import static org.mockito.Mockito.when; 30 | 31 | public class DefaultHttpClientProviderTest { 32 | 33 | private Logger mockLogger; 34 | 35 | @Before 36 | public void setUp() { 37 | mockLogger = mock(Logger.class); 38 | } 39 | 40 | @Test 41 | public void createClientReturnsNewHttpClient() { 42 | // given 43 | HTTPClientConfiguration configuration = mock(HTTPClientConfiguration.class); 44 | when(configuration.getBaseURL()).thenReturn("https://localhost:9999/1"); 45 | when(configuration.getApplicationID()).thenReturn("some cryptic appID"); 46 | 47 | DefaultHTTPClientProvider target = new DefaultHTTPClientProvider(mockLogger); 48 | 49 | // when 50 | HTTPClient obtained = target.createClient(configuration); 51 | 52 | // then 53 | assertThat(obtained, is(notNullValue())); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/providers/DefaultRandomNumberGeneratorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.dynatrace.openkit.providers; 17 | 18 | import org.junit.Test; 19 | 20 | import static org.hamcrest.Matchers.greaterThanOrEqualTo; 21 | import static org.hamcrest.Matchers.lessThan; 22 | import static org.junit.Assert.assertThat; 23 | 24 | public class DefaultRandomNumberGeneratorTest { 25 | 26 | @Test 27 | public void nextPositiveLongReturnsPositiveLongValue() { 28 | // given 29 | DefaultRandomNumberGenerator target = new DefaultRandomNumberGenerator(); 30 | 31 | for (int i = 0; i < 100; i++) { 32 | // when 33 | long obtained = target.nextPositiveLong(); 34 | 35 | // then 36 | assertThat(obtained, greaterThanOrEqualTo(0L)); 37 | } 38 | } 39 | 40 | @Test 41 | public void nextPercentageValueReturnsPercentageValue() { 42 | // given 43 | DefaultRandomNumberGenerator target = new DefaultRandomNumberGenerator(); 44 | 45 | for (int i = 0; i < 100; i++) { 46 | // when 47 | int obtained = target.nextPercentageValue(); 48 | 49 | // then 50 | assertThat(obtained, greaterThanOrEqualTo(0)); 51 | assertThat(obtained, lessThan(100)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/providers/DefaultSessionIDProviderTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.providers; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.hamcrest.Matchers.equalTo; 22 | import static org.hamcrest.Matchers.greaterThan; 23 | import static org.hamcrest.Matchers.is; 24 | import static org.junit.Assert.assertThat; 25 | 26 | public class DefaultSessionIDProviderTest { 27 | 28 | @Test 29 | public void defaultSessionIDProviderInitializedWithTimestampReturnsANonNegativeInteger() { 30 | // given 31 | // default constructor uses a random number generated from the current system timestamp 32 | DefaultSessionIDProvider provider = new DefaultSessionIDProvider(); 33 | 34 | //when 35 | int actual = provider.getNextSessionID(); 36 | 37 | // then 38 | assertThat(actual, is(greaterThan(0))); 39 | } 40 | 41 | @Test 42 | public void defaultSessionIDProviderProvidesConsecutiveNumbers() { 43 | //given 44 | DefaultSessionIDProvider provider = new DefaultSessionIDProvider(Integer.MAX_VALUE / 2); 45 | 46 | // when 47 | int firstSessionID = provider.getNextSessionID(); 48 | int secondSessionID = provider.getNextSessionID(); 49 | 50 | // then 51 | assertThat(secondSessionID, is(firstSessionID + 1)); 52 | } 53 | 54 | @Test 55 | public void aProviderInitializedWithMaxIntValueProvidesMinSessionIdValueAtNextCall() { 56 | //given 57 | DefaultSessionIDProvider provider = new DefaultSessionIDProvider(Integer.MAX_VALUE); 58 | 59 | //when 60 | int actual = provider.getNextSessionID(); 61 | 62 | //then 63 | assertThat(actual, is(equalTo(1))); 64 | } 65 | 66 | @Test 67 | public void aProviderInitializedWithZeroProvidesMinSessionIdValueAtNextCall() { 68 | //given 69 | DefaultSessionIDProvider provider = new DefaultSessionIDProvider(0); 70 | 71 | //when 72 | int actual = provider.getNextSessionID(); 73 | 74 | //then 75 | assertThat(actual, is(equalTo(1))); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/providers/DefaultThreadIDProviderTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.providers; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.hamcrest.Matchers.equalTo; 22 | import static org.hamcrest.Matchers.is; 23 | import static org.junit.Assert.assertThat; 24 | 25 | public class DefaultThreadIDProviderTest { 26 | @Test 27 | public void currentThreadIDIsReturned() { 28 | // given 29 | ThreadIDProvider provider = new DefaultThreadIDProvider(); 30 | 31 | long threadID64 = Thread.currentThread().getId(); 32 | int threadHash = (int)((threadID64 ^ (threadID64 >>> 32)) & 0x7fffffff ); 33 | // then 34 | assertThat(provider.getThreadID(), is(equalTo(threadHash))); 35 | } 36 | 37 | @Test 38 | public void convertNativeThreadIDToPositiveIntegerVerifyXorBitPatterns() { 39 | // given 40 | long testValue = 0x0000000600000005L; // bytes 0101 and 0110 -> xor resulting in 0011 41 | 42 | // when 43 | int result = DefaultThreadIDProvider.convertNativeThreadIDToPositiveInteger(testValue); 44 | // then 45 | assertThat(result, is(equalTo(3))); 46 | } 47 | 48 | @Test 49 | public void convertNativeThreadIDToPositiveIntegerVerifyMaskMSBFirst() { 50 | // given 51 | long testValue = 1L << 31; 52 | 53 | // when 54 | int result = DefaultThreadIDProvider.convertNativeThreadIDToPositiveInteger(testValue); 55 | // then 56 | assertThat(result, is(equalTo(0))); 57 | } 58 | 59 | @Test 60 | public void convertNativeThreadIDToPositiveIntegerVerifyMaskMSBSecond() { 61 | // given 62 | long testValue = 1L << 63; 63 | 64 | // when 65 | int result = DefaultThreadIDProvider.convertNativeThreadIDToPositiveInteger(testValue); 66 | // then 67 | assertThat(result, is(equalTo(0))); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/providers/DefaultTimingProviderTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.providers; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.hamcrest.Matchers.greaterThanOrEqualTo; 22 | import static org.hamcrest.Matchers.lessThanOrEqualTo; 23 | import static org.junit.Assert.assertThat; 24 | 25 | public class DefaultTimingProviderTest { 26 | 27 | @Test 28 | public void provideTimeStampInMillisecondsReturnsCurrentTime() { 29 | // given 30 | DefaultTimingProvider target = new DefaultTimingProvider(); 31 | 32 | // when 33 | long timeBefore = System.currentTimeMillis(); 34 | long obtained = target.provideTimestampInMilliseconds(); 35 | long timeAfter = System.currentTimeMillis(); 36 | 37 | // then 38 | assertThat(obtained, greaterThanOrEqualTo(timeBefore)); 39 | assertThat(obtained, lessThanOrEqualTo(timeAfter)); 40 | } 41 | 42 | @Test 43 | public void sleepSuspendsForSpecifiedTime() throws Exception { 44 | // given 45 | long sleepTimeInMillis = 2; 46 | DefaultTimingProvider target = new DefaultTimingProvider(); 47 | 48 | // when 49 | long timeInNanosBefore = System.nanoTime(); 50 | target.sleep(sleepTimeInMillis); 51 | long sleptTimeInNanos = System.nanoTime() - timeInNanosBefore; 52 | 53 | // then 54 | assertThat(sleptTimeInNanos, greaterThanOrEqualTo(sleepTimeInMillis * DefaultTimingProvider.MILLIS_TO_NANOS_FACTOR)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/providers/FixedRandomNumberGeneratorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.dynatrace.openkit.providers; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.hamcrest.Matchers.is; 22 | import static org.junit.Assert.assertThat; 23 | import static org.mockito.Mockito.mock; 24 | import static org.mockito.Mockito.when; 25 | 26 | public class FixedRandomNumberGeneratorTest { 27 | 28 | @Test 29 | public void nextPositiveLongReturnsAlwaysTheSameNumber() { 30 | // given 31 | long randomNumber = 1234567890; 32 | RandomNumberGenerator mockRng = mock(RandomNumberGenerator.class); 33 | when(mockRng.nextPositiveLong()).thenReturn(randomNumber, 1L, 2L, 4L, 5L); 34 | 35 | FixedRandomNumberGenerator target = new FixedRandomNumberGenerator(mockRng); 36 | 37 | for (int i = 0; i < 100; i++) { 38 | // when 39 | long obtained = target.nextPositiveLong(); 40 | 41 | // then 42 | assertThat(obtained, is(randomNumber)); 43 | } 44 | } 45 | 46 | @Test 47 | public void nextPercentageValueReturnsAlwaysTheSameNumber() { 48 | // given 49 | int randomPercentage = 42; 50 | RandomNumberGenerator mockRng = mock(RandomNumberGenerator.class); 51 | when(mockRng.nextPercentageValue()).thenReturn(randomPercentage, 1, 2, 4, 5); 52 | 53 | FixedRandomNumberGenerator target = new FixedRandomNumberGenerator(mockRng); 54 | 55 | for (int i = 0; i < 100; i++) { 56 | // when 57 | int obtained = target.nextPercentageValue(); 58 | 59 | // then 60 | assertThat(obtained, is(randomPercentage)); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/providers/FixedSessionIdProviderTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.dynatrace.openkit.providers; 17 | 18 | import org.junit.Test; 19 | 20 | import static org.hamcrest.Matchers.is; 21 | import static org.junit.Assert.assertThat; 22 | import static org.mockito.Mockito.mock; 23 | import static org.mockito.Mockito.when; 24 | 25 | public class FixedSessionIdProviderTest { 26 | 27 | @Test 28 | public void getNextSessionIdReturnsAlwaysTheSameNumber() { 29 | // given 30 | int sessionId = 777; 31 | SessionIDProvider sessionIdProvider = mock(SessionIDProvider.class); 32 | when(sessionIdProvider.getNextSessionID()).thenReturn(sessionId, 1, 2, 3, 4); 33 | 34 | FixedSessionIdProvider target = new FixedSessionIdProvider(sessionIdProvider); 35 | 36 | for (int i = 0; i < 100; i++) { 37 | // when 38 | int obtained = target.getNextSessionID(); 39 | 40 | // then 41 | assertThat(obtained, is(sessionId)); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/util/json/objects/JSONNullValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.util.json.objects; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.hamcrest.Matchers.is; 22 | import static org.junit.Assert.assertThat; 23 | 24 | public class JSONNullValueTest { 25 | 26 | @Test 27 | public void isNullReturnsTrue() { 28 | // then 29 | assertThat(JSONNullValue.NULL.isNull(), is(true)); 30 | } 31 | 32 | @Test 33 | public void isBooleanReturnsFalse() { 34 | // then 35 | assertThat(JSONNullValue.NULL.isBoolean(), is(false)); 36 | } 37 | 38 | @Test 39 | public void isNumberReturnsFalse() { 40 | // then 41 | assertThat(JSONNullValue.NULL.isNumber(), is(false)); 42 | } 43 | 44 | @Test 45 | public void isStringReturnsFalse() { 46 | // then 47 | assertThat(JSONNullValue.NULL.isString(), is(false)); 48 | } 49 | 50 | @Test 51 | public void isArrayReturnsFalse() { 52 | // then 53 | assertThat(JSONNullValue.NULL.isArray(), is(false)); 54 | } 55 | 56 | @Test 57 | public void isObjectReturnsFalse() { 58 | // then 59 | assertThat(JSONNullValue.NULL.isObject(), is(false)); 60 | } 61 | 62 | @Test 63 | public void nullJsonString() { 64 | assertThat(JSONNullValue.NULL.toString(), is("null")); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/util/json/objects/JSONStringValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.util.json.objects; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.hamcrest.Matchers.equalTo; 22 | import static org.hamcrest.Matchers.is; 23 | import static org.hamcrest.Matchers.nullValue; 24 | import static org.junit.Assert.assertThat; 25 | 26 | public class JSONStringValueTest { 27 | 28 | @Test 29 | public void isNullReturnsFalse() { 30 | // then 31 | assertThat(JSONStringValue.fromString("").isNull(), is(false)); 32 | } 33 | 34 | @Test 35 | public void isBooleanReturnsFalse() { 36 | // then 37 | assertThat(JSONStringValue.fromString("").isBoolean(), is(false)); 38 | } 39 | 40 | @Test 41 | public void isNumberReturnsFalse() { 42 | // then 43 | assertThat(JSONStringValue.fromString("").isNumber(), is(false)); 44 | } 45 | 46 | @Test 47 | public void isStringReturnsTrue() { 48 | // then 49 | assertThat(JSONStringValue.fromString("").isString(), is(true)); 50 | } 51 | 52 | @Test 53 | public void isArrayReturnsFalse() { 54 | // then 55 | assertThat(JSONStringValue.fromString("").isArray(), is(false)); 56 | } 57 | 58 | @Test 59 | public void isObjectReturnsFalse() { 60 | // then 61 | assertThat(JSONStringValue.fromString("").isObject(), is(false)); 62 | } 63 | 64 | @Test 65 | public void fromStringReturnsNullIfArgumentIsNull() { 66 | // then 67 | assertThat(JSONStringValue.fromString(null), is(nullValue())); 68 | } 69 | 70 | @Test 71 | public void getValueGivesValueOfFactoryMethodArgument() { 72 | // then 73 | assertThat(JSONStringValue.fromString("").getValue(), is(equalTo(""))); 74 | assertThat(JSONStringValue.fromString("a").getValue(), is(equalTo("a"))); 75 | assertThat(JSONStringValue.fromString("foobar").getValue(), is(equalTo("foobar"))); 76 | } 77 | 78 | @Test 79 | public void emptyValueJsonString() { 80 | assertThat(JSONStringValue.fromString("").toString(), is("\"\"")); 81 | } 82 | 83 | @Test 84 | public void anyValueJsonString(){ 85 | assertThat(JSONStringValue.fromString("any").toString(), is("\"any\"")); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/util/json/objects/JSONValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.util.json.objects; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.hamcrest.Matchers.is; 22 | import static org.junit.Assert.assertThat; 23 | 24 | public class JSONValueTest { 25 | 26 | @Test 27 | public void isNullReturnsFalse() { 28 | // then 29 | assertThat(new JSONStubValue().isNull(), is(false)); 30 | } 31 | 32 | @Test 33 | public void isBooleanReturnsFalse() { 34 | // then 35 | assertThat(new JSONStubValue().isBoolean(), is(false)); 36 | } 37 | 38 | @Test 39 | public void isNumberReturnsFalse() { 40 | // then 41 | assertThat(new JSONStubValue().isNumber(), is(false)); 42 | } 43 | 44 | @Test 45 | public void isStringReturnsFalse() { 46 | // then 47 | assertThat(new JSONStubValue().isString(), is(false)); 48 | } 49 | 50 | @Test 51 | public void isArrayReturnsFalse() { 52 | // then 53 | assertThat(new JSONStubValue().isArray(), is(false)); 54 | } 55 | 56 | @Test 57 | public void isObjectReturnsFalse() { 58 | // then 59 | assertThat(new JSONStubValue().isObject(), is(false)); 60 | } 61 | 62 | /** 63 | * Stub class for testing JSONValue. 64 | */ 65 | private static final class JSONStubValue extends JSONValue { 66 | @Override 67 | void writeJSONString(JSONValueWriter writer, JSONOutputConfig config) { 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/dynatrace/openkit/util/json/objects/JSONValueWriterTest.java: -------------------------------------------------------------------------------- 1 | package com.dynatrace.openkit.util.json.objects; 2 | 3 | import static org.hamcrest.Matchers.is; 4 | import static org.junit.Assert.assertThat; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | 9 | /** 10 | * @author matthias.hochrieser 11 | */ 12 | public class JSONValueWriterTest { 13 | 14 | JSONValueWriter writer; 15 | 16 | @Before 17 | public void init() { 18 | writer = new JSONValueWriter(); 19 | } 20 | 21 | @Test 22 | public void checkOpenArrayCharacter() { 23 | writer.openArray(); 24 | 25 | // then 26 | assertThat(writer.toString(), is("[")); 27 | } 28 | 29 | @Test 30 | public void checkCloseArrayCharacter() { 31 | writer.closeArray(); 32 | 33 | // then 34 | assertThat(writer.toString(), is("]")); 35 | } 36 | 37 | @Test 38 | public void checkOpenObjectCharacter() { 39 | writer.openObject(); 40 | 41 | // then 42 | assertThat(writer.toString(), is("{")); 43 | } 44 | 45 | @Test 46 | public void checkCloseObjectCharacter() { 47 | writer.closeObject(); 48 | 49 | // then 50 | assertThat(writer.toString(), is("}")); 51 | } 52 | 53 | @Test 54 | public void checkElementSeperatorCharacter() { 55 | writer.insertElementSeperator(); 56 | 57 | // then 58 | assertThat(writer.toString(), is(",")); 59 | } 60 | 61 | @Test 62 | public void checkKeyValueSeperatorCharacter() { 63 | writer.insertKeyValueSeperator(); 64 | 65 | // then 66 | assertThat(writer.toString(), is(":")); 67 | } 68 | 69 | @Test 70 | public void checkValueFormatting() { 71 | writer.insertValue("false"); 72 | 73 | // then 74 | assertThat(writer.toString(), is("false")); 75 | } 76 | 77 | @Test 78 | public void checkStringValueFormatting() { 79 | writer.insertStringValue("false"); 80 | 81 | // then 82 | assertThat(writer.toString(), is("\"false\"")); 83 | } 84 | 85 | @Test 86 | public void checkKeyFormatting() { 87 | writer.insertKey("Key"); 88 | 89 | // then 90 | assertThat(writer.toString(), is("\"Key\"")); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/test7/java/com/dynatrace/openkit/core/communication/AbstractBeaconSendingStateTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.core.communication; 18 | 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | 22 | import static org.hamcrest.Matchers.is; 23 | import static org.junit.Assert.assertThat; 24 | import static org.mockito.Mockito.doCallRealMethod; 25 | import static org.mockito.Mockito.doThrow; 26 | import static org.mockito.Mockito.mock; 27 | import static org.mockito.Mockito.times; 28 | import static org.mockito.Mockito.verify; 29 | import static org.mockito.Mockito.verifyNoMoreInteractions; 30 | 31 | public class AbstractBeaconSendingStateTest { 32 | 33 | private AbstractBeaconSendingState mockState; 34 | private BeaconSendingContext mockContext; 35 | 36 | @Before 37 | public void setUp() { 38 | mockState = mock(AbstractBeaconSendingState.class); 39 | doCallRealMethod().when(mockState).execute(org.mockito.Matchers.any(BeaconSendingContext.class)); 40 | mockContext = mock(BeaconSendingContext.class); 41 | } 42 | 43 | @Test 44 | public void aTestBeaconSendingStateExecutes() throws InterruptedException { 45 | 46 | // when calling execute 47 | mockState.execute(mockContext); 48 | 49 | // then verify doExecute was called 50 | verify(mockState, times(1)).doExecute(mockContext); 51 | 52 | // also verify that shutdown requested is queried, but nothing else 53 | verify(mockContext, times(1)).isShutdownRequested(); 54 | verifyNoMoreInteractions(mockContext); 55 | } 56 | 57 | 58 | @Test 59 | public void aTestBeaconSendingStateExecutesButIsInterrupted() throws InterruptedException { 60 | 61 | // when calling execute leads to an InterruptedException 62 | doThrow(new InterruptedException()).when(mockState).doExecute(mockContext); 63 | mockState.execute(mockContext); 64 | 65 | /* 66 | check and reset interrupted flag 67 | if the flag is not reset, subsequent tests might fail 68 | */ 69 | assertThat(Thread.interrupted(), is(true)); 70 | 71 | // then verify doExecute was called 72 | verify(mockState, times(1)).doExecute(mockContext); 73 | 74 | // also verify that shutdown requested is queried, but nothing else 75 | verify(mockState, times(1)).onInterrupted(mockContext); 76 | verify(mockContext, times(1)).isShutdownRequested(); 77 | verify(mockContext, times(1)).requestShutdown(); 78 | verifyNoMoreInteractions(mockContext); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/test7/java/com/dynatrace/openkit/protocol/EventPayloadMatcher.java: -------------------------------------------------------------------------------- 1 | package com.dynatrace.openkit.protocol; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.mockito.ArgumentMatcher; 6 | 7 | /** 8 | * @author matthias.hochrieser 9 | */ 10 | class EventPayloadMatcher extends ArgumentMatcher { 11 | 12 | private final String expectedEventPayload; 13 | 14 | public EventPayloadMatcher(String expectedEventPayload){ 15 | this.expectedEventPayload = expectedEventPayload; 16 | } 17 | 18 | @Override 19 | public boolean matches(Object argument) { 20 | String actualEventPayload = (String) argument; 21 | 22 | if(expectedEventPayload.contentEquals(actualEventPayload)){ 23 | return true; 24 | } 25 | 26 | // Check if both of them are not null 27 | if(expectedEventPayload == null ^ actualEventPayload == null){ 28 | return false; 29 | } 30 | 31 | // Check for beginning of event payload 32 | if(!(expectedEventPayload.startsWith("et=98&pl=") && actualEventPayload.startsWith("et=98&pl="))){ 33 | return false; 34 | } 35 | 36 | String expectedPayload = expectedEventPayload.substring(expectedEventPayload.indexOf("pl=") + "pl=".length()); 37 | expectedPayload = removeEncodedBrackets(expectedPayload); 38 | 39 | String actualPayload = actualEventPayload.substring(actualEventPayload.indexOf("pl=") + "pl=".length()); 40 | actualPayload = removeEncodedBrackets(actualPayload); 41 | 42 | String[] expectedPayloadValues = expectedPayload.split("%2C"); 43 | Arrays.sort(expectedPayloadValues); 44 | 45 | String[] actualPayloadValues = actualPayload.split("%2C"); 46 | Arrays.sort(actualPayloadValues); 47 | 48 | return Arrays.equals(expectedPayloadValues, actualPayloadValues); 49 | } 50 | 51 | private String removeEncodedBrackets(String payload){ 52 | String editedPayload = payload.replaceAll("%7B", ""); 53 | editedPayload = editedPayload.replaceAll("%7D", ""); 54 | return editedPayload; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test7/java/com/dynatrace/openkit/protocol/http/NullHttpRequestInterceptorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.protocol.http; 18 | 19 | import com.dynatrace.openkit.api.http.HttpRequest; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import static org.mockito.Mockito.mock; 24 | import static org.mockito.Mockito.verifyZeroInteractions; 25 | 26 | public class NullHttpRequestInterceptorTest { 27 | 28 | private HttpRequest mockHttpRequest; 29 | 30 | @Before 31 | public void setUp() { 32 | mockHttpRequest = mock(HttpRequest.class); 33 | } 34 | 35 | @Test 36 | public void interceptDoesNotInteractWithHttpRequest() { 37 | // given 38 | NullHttpRequestInterceptor target = NullHttpRequestInterceptor.INSTANCE; 39 | 40 | // when 41 | target.intercept(mockHttpRequest); 42 | 43 | // then 44 | verifyZeroInteractions(mockHttpRequest); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test7/java/com/dynatrace/openkit/protocol/http/NullHttpResponseInterceptorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018-2021 Dynatrace LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.dynatrace.openkit.protocol.http; 18 | 19 | import com.dynatrace.openkit.api.http.HttpResponse; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import static org.mockito.Mockito.mock; 24 | import static org.mockito.Mockito.verifyZeroInteractions; 25 | 26 | public class NullHttpResponseInterceptorTest { 27 | 28 | private HttpResponse mockHttpResponse; 29 | 30 | @Before 31 | public void setUp() { 32 | mockHttpResponse = mock(HttpResponse.class); 33 | } 34 | 35 | @Test 36 | public void interceptDoesNotInteractWithHttpResponse() { 37 | // given 38 | NullHttpResponseInterceptor target = NullHttpResponseInterceptor.INSTANCE; 39 | 40 | // when 41 | target.intercept(mockHttpResponse); 42 | 43 | // then 44 | verifyZeroInteractions(mockHttpResponse); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /version.properties: -------------------------------------------------------------------------------- 1 | version=3.4.0-SNAPSHOT --------------------------------------------------------------------------------