• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Dynatrace / openkit-java / #421079375

pending completion
#421079375

push

github-actions

openkitdt
<a href="https://github.com/Dynatrace/openkit-java/commit/<a class=hub.com/Dynatrace/openkit-java/commit/ed2274a4e4a28843476d42db8f7285a0099e911c">ed2274a4e<a href="https://github.com/Dynatrace/openkit-java/commit/ed2274a4e4a28843476d42db8f7285a0099e911c">&quot;&gt;Pull request #253: RUM-9059 Fixing HTTPClienTest for Java7

Merge in OP/openkit-java from feature/RUM-9059-mockito-4.x-update-destroyed-compatibility-with-java-7-for-open-kit-java to main

* commit &#39;</a><a class="double-link" href="https://github.com/Dynatrace/openkit-java/commit/<a class="double-link" href="https://github.com/Dynatrace/openkit-java/commit/923e0932da7ec3711020378f886a407411ad1015">923e0932d</a>">923e0932d</a><a href="https://github.com/Dynatrace/openkit-java/commit/ed2274a4e4a28843476d42db8f7285a0099e911c">&#39;:
  RUM-9059 Fixing HTTPClienTest for Java7

GitOrigin-RevId: 87bb8509b">87bb8509b</a>

4148 of 4352 relevant lines covered (95.31%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/src/main/java/com/dynatrace/openkit/core/objects/WebRequestTracerURLConnection.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.net.URLConnection;
24

25
/**
26
 * Inherited class of {@link WebRequestTracerBaseImpl} which can be used for tracing and timing of a web request provided as a URLConnection.
27
 */
28
public class WebRequestTracerURLConnection extends WebRequestTracerBaseImpl {
29

30
    /**
31
     * Creates web request tag with a URLConnection
32
     *
33
     * <p>
34
     *     The required Dynatrace tag is applied automatically, if not done yet.
35
     * </p>
36
     *
37
     * @param logger The logger used to log information
38
     * @param parent The parent object, to which this web request tracer belongs to
39
     * @param beacon {@link Beacon} for data sending and tag creation
40
     * @param connection The URL connection to trace
41
     */
42
    public WebRequestTracerURLConnection(Logger logger,
43
                                         OpenKitComposite parent,
44
                                         Beacon beacon,
45
                                         URLConnection connection) {
46
        super(logger, parent, extractURLParts(connection), beacon);
1✔
47
        setTagOnConnection(connection);
1✔
48
    }
1✔
49

50
    /**
51
     * Extract URL parts of interest from given url connection.
52
     *
53
     * <p>
54
     *     The URL parts of interest are
55
     *     <ul>
56
     *         <li>scheme</li>
57
     *         <li>host</li>
58
     *         <li>port</li>
59
     *         <li>path</li>
60
     *     </ul>
61
     * </p>
62
     *
63
     * @param connection The url connection from which to get the URL to trace
64
     * @return The {@code url} substring containing scheme, host, port, path
65
     */
66
    private static String extractURLParts(URLConnection connection) {
67
        if (connection == null || connection.getURL() == null) {
1✔
68
            return WebRequestTracerBaseImpl.UNKNOWN_URL;
1✔
69
        }
70

71
        return connection.getURL().toString().split("\\?", 2)[0];
1✔
72
    }
73

74
    /**
75
     * Set the Dynatrace tag on the provided URLConnection
76
     *
77
     * @param connection The URL connection.
78
     */
79
    private void setTagOnConnection(URLConnection connection) {
80
        if (connection == null) {
1✔
81
            return;
×
82
        }
83

84
        // check if header is already set
85
        String existingTag = connection.getRequestProperty(OpenKitConstants.WEBREQUEST_TAG_HEADER);
1✔
86
        if (existingTag == null) {
1✔
87
            // if not yet set -> set it now
88
            try {
89
                connection.setRequestProperty(OpenKitConstants.WEBREQUEST_TAG_HEADER, getTag());
1✔
90
            } catch (Exception e) {
×
91
                // if it does not work -> simply ignore
92
            }
1✔
93
        }
94
    }
1✔
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc