Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit 6956bc2

Browse files
author
synapticloop
committed
2 parents 90d1193 + c0ee9d6 commit 6956bc2

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

src/main/java/synapticloop/b2/request/BaseB2Request.java

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
/*
66
* Copyright (c) 2016 Synapticloop.
7-
*
7+
*
88
* All rights reserved.
9-
*
10-
* This code may contain contributions from other parties which, where
11-
* applicable, will be listed in the default build file for the project
9+
*
10+
* This code may contain contributions from other parties which, where
11+
* applicable, will be listed in the default build file for the project
1212
* ~and/or~ in a file named CONTRIBUTORS.txt in the root of the project.
13-
*
14-
* This source code and any derived binaries are covered by the terms and
15-
* conditions of the Licence agreement ("the Licence"). You may not use this
16-
* source code or any derived binaries except in compliance with the Licence.
17-
* A copy of the Licence is available in the file named LICENSE.txt shipped with
13+
*
14+
* This source code and any derived binaries are covered by the terms and
15+
* conditions of the Licence agreement ("the Licence"). You may not use this
16+
* source code or any derived binaries except in compliance with the Licence.
17+
* A copy of the Licence is available in the file named LICENSE.txt shipped with
1818
* this source code or binaries.
1919
*/
2020

@@ -46,6 +46,8 @@
4646
import synapticloop.b2.exception.B2ApiException;
4747
import synapticloop.b2.response.B2AuthorizeAccountResponse;
4848

49+
import static org.apache.http.entity.ContentType.APPLICATION_JSON;
50+
4951
public abstract class BaseB2Request {
5052
private static final Logger LOGGER = LoggerFactory.getLogger(BaseB2Request.class);
5153

@@ -87,7 +89,7 @@ protected BaseB2Request(CloseableHttpClient client, final String url) {
8789
/**
8890
* Instantiate the base B2 request which adds headers with the authorization
8991
* token.
90-
*
92+
*
9193
* @param client Shared HTTP client
9294
* @param b2AuthorizeAccountResponse the authorize account response
9395
* @param url Fully qualified request URI
@@ -99,7 +101,7 @@ protected BaseB2Request(CloseableHttpClient client, B2AuthorizeAccountResponse b
99101
/**
100102
* Instantiate the base B2 request which adds headers with the authorization
101103
* token.
102-
*
104+
*
103105
* @param client Shared HTTP client
104106
* @param b2AuthorizeAccountResponse the authorize account response
105107
* @param url Fully qualified request URI
@@ -115,7 +117,7 @@ protected BaseB2Request(CloseableHttpClient client, B2AuthorizeAccountResponse b
115117

116118
/**
117119
* Add header to request replacing previous if any
118-
*
120+
*
119121
* @param key the key to add
120122
* @param value the value to add
121123
*/
@@ -125,7 +127,7 @@ protected void addHeader(String key, String value) {
125127

126128
/**
127129
* Add query parameter to request replacing previous if any
128-
*
130+
*
129131
* @param key the key to add
130132
* @param value the value to add
131133
*/
@@ -135,7 +137,7 @@ protected void addParameter(String key, String value) {
135137

136138
/**
137139
* Add property to JSON request body
138-
*
140+
*
139141
* @param key the key to add
140142
* @param value the value to add
141143
*/
@@ -145,9 +147,9 @@ protected void addProperty(String key, Object value) {
145147

146148
/**
147149
* Execute an HTTP HEAD request and return the response for further parsing
148-
*
150+
*
149151
* @return the response object
150-
*
152+
*
151153
* @throws B2ApiException if something went wrong with the call
152154
* @throws IOException if there was an error communicating with the API service
153155
*/
@@ -175,7 +177,7 @@ protected CloseableHttpResponse executeHead() throws B2ApiException, IOException
175177

176178
/**
177179
* Execute a GET request, returning the data stream from the response.
178-
*
180+
*
179181
* @return The response from the GET request
180182
*
181183
* @throws B2ApiException if there was an error with the request
@@ -205,9 +207,9 @@ protected CloseableHttpResponse executeGet() throws B2ApiException, IOException
205207

206208
/**
207209
* Execute a POST request returning the response data as a String
208-
*
210+
*
209211
* @return the response data as a string
210-
*
212+
*
211213
* @throws B2ApiException if there was an error with the call, most notably
212214
* a non OK status code (i.e. not 200)
213215
* @throws IOException if there was an error communicating with the API service
@@ -236,11 +238,11 @@ protected CloseableHttpResponse executePost() throws B2ApiException, IOException
236238

237239
/**
238240
* Execute a POST request with the contents of a file.
239-
*
241+
*
240242
* @param entity Content to write
241-
*
243+
*
242244
* @return the string representation of the response
243-
*
245+
*
244246
* @throws B2ApiException if there was an error with the call, most notably
245247
* a non OK status code (i.e. not 200)
246248
* @throws IOException if there was an error communicating with the API service
@@ -265,9 +267,9 @@ protected CloseableHttpResponse executePost(HttpEntity entity) throws B2ApiExcep
265267
/**
266268
* Convert the stringData and integerData Maps to JSON format, to be included
267269
* in the POST body of the request.
268-
*
270+
*
269271
* @return the JSON string of the data
270-
*
272+
*
271273
* @throws IOException if there was an error converting the data.
272274
*/
273275
protected String convertPostData() throws IOException {
@@ -285,11 +287,11 @@ protected String convertPostData() throws IOException {
285287
}
286288

287289
/**
288-
* Return the URI for this request, which adds any parameters found in the
290+
* Return the URI for this request, which adds any parameters found in the
289291
* 'parameters' data structure
290-
*
292+
*
291293
* @return The URI for this request, with properly encoded parameters
292-
*
294+
*
293295
* @throws IOException If there was an error building the URI
294296
*/
295297
protected URI buildUri() throws IOException {
@@ -308,15 +310,15 @@ protected URI buildUri() throws IOException {
308310
}
309311

310312
/**
311-
* Set the headers safely, go through the headers Map and add them to the http
312-
* request with properly encode values. If they already exist on the http
313+
* Set the headers safely, go through the headers Map and add them to the http
314+
* request with properly encode values. If they already exist on the http
313315
* request, it will be ignored.
314-
*
316+
*
315317
* To override what headers are set, this should be done in the constructor
316318
* of the base request object.
317-
*
319+
*
318320
* @param request The HTTP request to set the headers on
319-
*
321+
*
320322
* @throws B2ApiException if there was an error setting the headers
321323
*/
322324
protected void setHeaders(HttpUriRequest request) throws B2ApiException {
@@ -344,9 +346,9 @@ protected CloseableHttpResponse execute(final HttpUriRequest request) throws IOE
344346
/**
345347
* Obfuscate the data by removing the accountId and replacing it with the
346348
* string "[redacted]"
347-
*
349+
*
348350
* @param data the data to obfuscate
349-
*
351+
*
350352
* @return the obfuscated data
351353
*/
352354
private Object obfuscateData(String key, Object data) {

0 commit comments

Comments
 (0)