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

box / box-java-sdk / #7023

15 May 2026 10:51AM UTC coverage: 12.506% (-0.01%) from 12.52%
#7023

push

github

web-flow
feat(boxsdkgen): Sanitize request body in `BoxAPIError` (box/box-codegen#948) (#1845)

0 of 41 new or added lines in 5 files covered. (0.0%)

20 existing lines in 10 files now uncovered.

8368 of 66914 relevant lines covered (12.51%)

0.13 hits per line

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

0.0
/src/main/java/com/box/sdkgen/box/errors/RequestInfo.java
1
package com.box.sdkgen.box.errors;
2

3
import com.box.sdkgen.internal.logging.DataSanitizer;
4
import java.util.Map;
5
import java.util.stream.Collectors;
6
import okhttp3.Request;
7
import okhttp3.RequestBody;
8
import okio.Buffer;
9

10
public class RequestInfo {
11

12
  public final String method;
13

14
  public final String url;
15

16
  public final Map<String, String> queryParams;
17

18
  public final Map<String, String> headers;
19

20
  public String body;
21

22
  public String contentType;
23

24
  public RequestInfo(
25
      String method, String url, Map<String, String> queryParams, Map<String, String> headers) {
×
26
    this.method = method;
×
27
    this.url = url;
×
28
    this.queryParams = queryParams;
×
29
    this.headers = headers;
×
30
  }
×
31

32
  protected RequestInfo(Builder builder) {
×
33
    this.method = builder.method;
×
34
    this.url = builder.url;
×
35
    this.queryParams = builder.queryParams;
×
36
    this.headers = builder.headers;
×
37
    this.body = builder.body;
×
NEW
38
    this.contentType = builder.contentType;
×
UNCOV
39
  }
×
40

41
  public String getMethod() {
42
    return method;
×
43
  }
44

45
  public String getUrl() {
46
    return url;
×
47
  }
48

49
  public Map<String, String> getQueryParams() {
50
    return queryParams;
×
51
  }
52

53
  public Map<String, String> getHeaders() {
54
    return headers;
×
55
  }
56

57
  public String getBody() {
58
    return body;
×
59
  }
60

61
  public String getContentType() {
NEW
62
    return contentType;
×
63
  }
64

65
  public static class Builder {
66

67
    protected final String method;
68

69
    protected final String url;
70

71
    protected final Map<String, String> queryParams;
72

73
    protected final Map<String, String> headers;
74

75
    protected String body;
76

77
    protected String contentType;
78

79
    public Builder(
80
        String method, String url, Map<String, String> queryParams, Map<String, String> headers) {
×
81
      this.method = method;
×
82
      this.url = url;
×
83
      this.queryParams = queryParams;
×
84
      this.headers = headers;
×
85
    }
×
86

87
    public Builder body(String body) {
88
      this.body = body;
×
89
      return this;
×
90
    }
91

92
    public Builder contentType(String contentType) {
NEW
93
      this.contentType = contentType;
×
NEW
94
      return this;
×
95
    }
96

97
    public RequestInfo build() {
98
      return new RequestInfo(this);
×
99
    }
100
  }
101

102
  public static RequestInfo fromRequest(Request request) {
NEW
103
    return fromRequest(request, null);
×
104
  }
105

106
  public static RequestInfo fromRequest(Request request, String contentType) {
UNCOV
107
    Builder requestInfoBuilder =
×
108
        new Builder(
109
                request.method(),
×
110
                request.url().toString(),
×
111
                request.url().queryParameterNames().stream()
×
112
                    .collect(
×
113
                        Collectors.toMap(name -> name, name -> request.url().queryParameter(name))),
×
114
                request.headers().toMultimap().entrySet().stream()
×
115
                    .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().get(0))))
×
NEW
116
            .body(getRequestBodyAsString(request.body()))
×
NEW
117
            .contentType(contentType);
×
118

119
    return new RequestInfo(requestInfoBuilder);
×
120
  }
121

122
  private static String getRequestBodyAsString(RequestBody requestBody) {
123
    try {
124
      if (requestBody != null) {
×
125
        Buffer buffer = new Buffer();
×
126
        requestBody.writeTo(buffer);
×
127
        return buffer.readUtf8();
×
128
      }
129
    } catch (Exception e) {
×
130
      return null;
×
131
    }
×
132
    return null;
×
133
  }
134

135
  String print(DataSanitizer dataSanitizer) {
UNCOV
136
    Map<String, String> sanitizedHeaders =
×
137
        dataSanitizer == null ? headers : dataSanitizer.sanitizeHeaders(headers);
×
138
    String sanitizedBody;
NEW
139
    if (dataSanitizer == null || body == null) {
×
NEW
140
      sanitizedBody = body;
×
141
    } else {
NEW
142
      sanitizedBody = dataSanitizer.sanitizeStringBody(body, contentType);
×
143
    }
UNCOV
144
    return "RequestInfo{"
×
145
        + "\n\tmethod='"
146
        + method
147
        + '\''
148
        + ", \n\turl='"
149
        + url
150
        + '\''
151
        + ", \n\tqueryParams="
152
        + queryParams
153
        + ", \n\theaders="
154
        + sanitizedHeaders
155
        + ", \n\tbody='"
156
        + sanitizedBody
157
        + '\''
158
        + '}';
159
  }
160
}
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

© 2026 Coveralls, Inc