Skip to content

Commit 4a50960

Browse files
author
a-brandt
committed
fixed sonarlint issue
1 parent 4b38873 commit 4a50960

File tree

5 files changed

+116
-40
lines changed

5 files changed

+116
-40
lines changed

src/main/java/com/arangodb/http/BatchHttpManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public class BatchHttpManager extends HttpManager {
1515

1616
private InvocationObject currentObject;
1717

18+
private boolean batchModeActive = false;
19+
1820
public BatchHttpManager(ArangoConfigure configure) {
1921
super(configure);
2022
}
2123

22-
public boolean batchModeActive = false;
23-
2424
@Override
2525
public HttpResponseEntity execute(HttpRequestEntity requestEntity) throws ArangoException {
2626
if (!this.isBatchModeActive()) {

src/main/java/com/arangodb/http/CURLLogger.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.slf4j.LoggerFactory;
2424

2525
import com.arangodb.http.HttpRequestEntity.RequestType;
26+
import com.arangodb.util.StringUtils;
2627

2728
/**
2829
* @author tamtam180 - kirscheless at gmail.com
@@ -32,10 +33,14 @@ public class CURLLogger {
3233

3334
private static Logger logger = LoggerFactory.getLogger(CURLLogger.class);
3435

36+
private CURLLogger() {
37+
// this is a helper class
38+
}
39+
3540
public static void log(String url, HttpRequestEntity requestEntity, String userAgent, Credentials credencials) {
3641

37-
boolean includeBody = (requestEntity.type == RequestType.POST || requestEntity.type == RequestType.PUT || requestEntity.type == RequestType.PATCH)
38-
&& (requestEntity.bodyText != null && requestEntity.bodyText.length() != 0);
42+
boolean includeBody = (requestEntity.type == RequestType.POST || requestEntity.type == RequestType.PUT
43+
|| requestEntity.type == RequestType.PATCH) && StringUtils.isNotEmpty(requestEntity.bodyText);
3944

4045
StringBuilder buffer = new StringBuilder();
4146

@@ -48,7 +53,7 @@ public static void log(String url, HttpRequestEntity requestEntity, String userA
4853
buffer.append(" --dump -");
4954

5055
// header
51-
if (requestEntity.headers != null && !requestEntity.headers.isEmpty()) {
56+
if (requestEntity.hasHeaders()) {
5257
for (Entry<String, Object> header : requestEntity.headers.entrySet()) {
5358
buffer.append(" -H '").append(header.getKey()).append(":").append(header.getValue()).append("'");
5459
}

src/main/java/com/arangodb/http/HttpManager.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class HttpManager {
100100

101101
private Map<String, InvocationObject> jobs = new HashMap<String, InvocationObject>();
102102

103-
public static enum HttpMode {
103+
public enum HttpMode {
104104
SYNC, ASYNC, FIREANDFORGET
105105
}
106106

@@ -117,12 +117,7 @@ public void init() {
117117
ConnectionSocketFactory plainsf = new PlainConnectionSocketFactory();
118118

119119
// socket factory for HTTPS
120-
SSLConnectionSocketFactory sslsf = null;
121-
if (configure.getSslContext() != null) {
122-
sslsf = new SSLConnectionSocketFactory(configure.getSslContext());
123-
} else {
124-
sslsf = new SSLConnectionSocketFactory(SSLContexts.createSystemDefault());
125-
}
120+
SSLConnectionSocketFactory sslsf = initSSLConnectionSocketFactory();
126121

127122
// register socket factories
128123
Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory> create()
@@ -162,15 +157,16 @@ public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
162157
HeaderElement he = it.nextElement();
163158
String param = he.getName();
164159
String value = he.getValue();
165-
if (value != null && param.equalsIgnoreCase("timeout")) {
160+
if (value != null && "timeout".equalsIgnoreCase(param)) {
166161
try {
167-
return Long.parseLong(value) * 1000;
162+
return Long.parseLong(value) * 1000L;
168163
} catch (NumberFormatException ignore) {
164+
// ignore this exception
169165
}
170166
}
171167
}
172168
// otherwise keep alive for 30 seconds
173-
return 30 * 1000;
169+
return 30L * 1000L;
174170
}
175171

176172
};
@@ -404,11 +400,8 @@ private HttpResponseEntity executeInternal(String baseUrl, HttpRequestEntity req
404400
}
405401
}
406402

407-
HttpRequestBase request = null;
403+
HttpRequestBase request;
408404
switch (requestEntity.type) {
409-
case GET:
410-
request = new HttpGet(url);
411-
break;
412405
case POST:
413406
HttpPost post = new HttpPost(url);
414407
configureBodyParams(requestEntity, post);
@@ -430,6 +423,10 @@ private HttpResponseEntity executeInternal(String baseUrl, HttpRequestEntity req
430423
case DELETE:
431424
request = new HttpDelete(url);
432425
break;
426+
case GET:
427+
default:
428+
request = new HttpGet(url);
429+
break;
433430
}
434431

435432
// common-header
@@ -468,7 +465,7 @@ private HttpResponseEntity executeInternal(String baseUrl, HttpRequestEntity req
468465
if (configure.isEnableCURLLogger()) {
469466
CURLLogger.log(url, requestEntity, userAgent, credentials);
470467
}
471-
HttpResponse response = null;
468+
HttpResponse response;
472469
if (preDefinedResponse != null) {
473470
return preDefinedResponse;
474471
}
@@ -624,12 +621,23 @@ public void addJob(String jobId, InvocationObject invocationObject) {
624621
}
625622

626623
public String getLastJobId() {
627-
return jobIds.size() == 0 ? null : jobIds.get(jobIds.size() - 1);
624+
return jobIds.isEmpty() ? null : jobIds.get(jobIds.size() - 1);
628625
}
629626

630627
public void resetJobs() {
631628
this.jobIds = new ArrayList<String>();
632629
this.jobs.clear();
633630

634631
}
632+
633+
private SSLConnectionSocketFactory initSSLConnectionSocketFactory() {
634+
SSLConnectionSocketFactory sslsf;
635+
if (configure.getSslContext() != null) {
636+
sslsf = new SSLConnectionSocketFactory(configure.getSslContext());
637+
} else {
638+
sslsf = new SSLConnectionSocketFactory(SSLContexts.createSystemDefault());
639+
}
640+
return sslsf;
641+
}
642+
635643
}

src/main/java/com/arangodb/http/HttpRequestEntity.java

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,8 @@
2626
*/
2727
public class HttpRequestEntity {
2828

29-
public static enum RequestType {
30-
GET,
31-
POST,
32-
PUT,
33-
DELETE,
34-
HEAD,
35-
PATCH
29+
public enum RequestType {
30+
GET, POST, PUT, DELETE, HEAD, PATCH
3631
}
3732

3833
public Map<String, Object> headers;
@@ -44,4 +39,72 @@ public static enum RequestType {
4439
public String bodyText;
4540
public HttpEntity entity;
4641

42+
public Map<String, Object> getHeaders() {
43+
return headers;
44+
}
45+
46+
public void setHeaders(Map<String, Object> headers) {
47+
this.headers = headers;
48+
}
49+
50+
public boolean hasHeaders() {
51+
return headers != null && !headers.isEmpty();
52+
}
53+
54+
public RequestType getType() {
55+
return type;
56+
}
57+
58+
public void setType(RequestType type) {
59+
this.type = type;
60+
}
61+
62+
public String getUrl() {
63+
return url;
64+
}
65+
66+
public void setUrl(String url) {
67+
this.url = url;
68+
}
69+
70+
public Map<String, Object> getParameters() {
71+
return parameters;
72+
}
73+
74+
public void setParameters(Map<String, Object> parameters) {
75+
this.parameters = parameters;
76+
}
77+
78+
public String getUsername() {
79+
return username;
80+
}
81+
82+
public void setUsername(String username) {
83+
this.username = username;
84+
}
85+
86+
public String getPassword() {
87+
return password;
88+
}
89+
90+
public void setPassword(String password) {
91+
this.password = password;
92+
}
93+
94+
public String getBodyText() {
95+
return bodyText;
96+
}
97+
98+
public void setBodyText(String bodyText) {
99+
this.bodyText = bodyText;
100+
}
101+
102+
public HttpEntity getEntity() {
103+
return entity;
104+
}
105+
106+
public void setEntity(HttpEntity entity) {
107+
this.entity = entity;
108+
}
109+
47110
}

src/main/java/com/arangodb/http/JsonSequenceEntity.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,40 @@ public JsonSequenceEntity(Iterator<?> it, Gson gson) {
4343
setContentType("binary/octet-stream");
4444
}
4545

46+
@Override
4647
public boolean isRepeatable() {
4748
return false;
4849
}
4950

51+
@Override
5052
public long getContentLength() {
5153
return -1;
5254
}
5355

54-
public InputStream getContent() throws IOException, IllegalStateException {
56+
@Override
57+
public InputStream getContent() throws IOException {
5558
throw new IllegalStateException("cannot support this method.");
5659
}
5760

61+
@Override
5862
public boolean isStreaming() {
5963
return true;
6064
}
6165

66+
@Override
6267
public void writeTo(OutputStream outstream) throws IOException {
6368

6469
if (outstream == null) {
6570
throw new IllegalArgumentException("Output stream may not be null");
6671
}
6772

68-
BufferedWriter writer = null;
69-
try {
70-
writer = new BufferedWriter(new OutputStreamWriter(outstream, "UTF-8"));
71-
while (it.hasNext()) {
72-
Object value = it.next();
73-
gson.toJson(value, writer);
74-
writer.newLine();
75-
}
76-
writer.flush();
77-
} finally {
73+
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outstream, "UTF-8"));
74+
while (it.hasNext()) {
75+
Object value = it.next();
76+
gson.toJson(value, writer);
77+
writer.newLine();
7878
}
79-
79+
writer.flush();
8080
}
8181

8282
}

0 commit comments

Comments
 (0)