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

hyperwallet / java-sdk / #694

15 May 2025 08:53PM CUT coverage: 96.097%. Remained the same
#694

Pull #220

grmeyer-hw-dev
Prepare to release 1.9.7
Pull Request #220: Deprecate Double to String

5048 of 5253 relevant lines covered (96.1%)

65.7 hits per line

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

31.03
/src/main/java/com/hyperwallet/clientsdk/util/Message.java
1
package com.hyperwallet.clientsdk.util;
2

3
import cc.protea.util.http.Response;
4
import java.io.UnsupportedEncodingException;
5
import java.net.URLEncoder;
6
import java.util.ArrayList;
7
import java.util.HashMap;
8
import java.util.List;
9
import java.util.Map;
10

11
/*
12
 Modified with modifications copyright Richard Stanford
13
 -- Original portions by Joe Ernst --
14
 Copyright 2012 Joe J. Ernst
15
 Licensed under the Apache License, Version 2.0 (the "License");
16
 you may not use this file except in compliance with the License.
17
 You may obtain a copy of the License at
18
 http://www.apache.org/licenses/LICENSE-2.0
19
 Unless required by applicable law or agreed to in writing, software
20
 distributed under the License is distributed on an "AS IS" BASIS,
21
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 See the License for the specific language governing permissions and
23
 limitations under the License.
24
 */
25

26
/**
27
 * This class represents an HTTP Message, which could either be a Request or a Response. Message is an abstract class that contains fields and methods that are common to both types of Messages.
28
 *
29
 * @param <T>
30
 *            A Type that extends Message (either {@link Request} or {@link Response})
31
 */
32
public abstract class Message<T extends Message<T>> {
33
    Map<String, List<String>> headers = new HashMap<String, List<String>>();
72✔
34
    String body;
35

36
    /**
37
     * The default constructor is a no-op constructor.
38
     */
39
    public Message() {
72✔
40
        // No-arg, No-op constructor
41
    }
72✔
42

43
    /**
44
     * Returns the Message body (also known as the Entity body).
45
     *
46
     * @return The body of the HTTP Message. It will typically be HTML, JSON, or XML.
47
     */
48
    public String getBody() {
49
        return this.body;
×
50
    }
51

52
    public Map<String, List<String>> getHeaders() {
53
        return this.headers;
×
54
    }
55

56
    public List<String> getHeaders(final String label) {
57
        if (label == null) {
×
58
            return null;
×
59
        }
60
        for (String key : headers.keySet()) {
×
61
            if (label.equalsIgnoreCase(key)) {
×
62
                return headers.get(key);
×
63
            }
64
        }
×
65
        return null;
×
66
    }
67

68
    public String getHeader(final String label) {
69
        List<String> list = getHeaders(label);
×
70
        if (list == null || list.isEmpty()) {
×
71
            return null;
×
72
        }
73
        return list.get(0);
×
74
    }
75

76
    /**
77
     * Sets the body of the Message.
78
     *
79
     * @param body
80
     *            This is typically the JSON, XML, or Form Parameters being sent to the server.
81
     * @return this Message, to support chained method calls
82
     */
83
    @SuppressWarnings("unchecked")
84
    public T setBody(final String body) {
85
        this.body = body;
44✔
86
        return (T) this;
44✔
87
    }
88

89
    /**
90
     * Adds a single header value to the Message.
91
     *
92
     * @param name
93
     *            The header name.
94
     * @param value
95
     *            The header value
96
     * @return this Message, to support chained method calls
97
     */
98
    @SuppressWarnings("unchecked")
99
    public T addHeader(final String name, final String value) {
100
        List<String> values = new ArrayList<String>();
527✔
101
        values.add(value);
527✔
102

103
        this.headers.put(name, values);
527✔
104
        return (T) this;
527✔
105
    }
106

107
    /**
108
     * Removes the specified header.
109
     *
110
     * @param name
111
     *            The name of the header to remove.
112
     * @return this Message, to support chained method calls
113
     */
114
    @SuppressWarnings("unchecked")
115
    public T removeHeader(final String name) {
116
        this.headers.remove(name);
×
117
        return (T) this;
×
118
    }
119

120
    /**
121
     * Sets all of the headers in one call.
122
     *
123
     * @param headers
124
     *            A Map of headers, where the header name is a String, and the value is a List of one or more values.
125
     * @return this Message, to support chained method calls
126
     */
127
    @SuppressWarnings("unchecked")
128
    public T setHeaders(final Map<String, List<String>> headers) {
129
        this.headers = headers;
×
130
        return (T) this;
×
131
    }
132

133
    String encode(final String in) {
134
        try {
135
            return URLEncoder.encode(in, "UTF-8");
×
136
        } catch (UnsupportedEncodingException e) {
×
137
            return in;
×
138
        }
139
    }
140

141
}
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