Skip to content

Commit 18d6af5

Browse files
author
Roberto Sora
committed
Refactor http successfull request logs in one line
1 parent 207128d commit 18d6af5

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

Diff for: arduino-core/src/cc/arduino/utils/network/HttpConnectionManager.java

+29-28
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,52 @@
1717
import java.util.function.Consumer;
1818

1919
public class HttpConnectionManager {
20-
private static Logger log = LoggerFactory.getLogger(HttpConnectionManager.class);
20+
private static Logger log = LoggerFactory
21+
.getLogger(HttpConnectionManager.class);
2122
private final URL requestURL;
2223
private final String userAgent;
2324
private int connectTimeout;
2425

25-
2626
public HttpConnectionManager(URL requestURL) {
2727
this.requestURL = requestURL;
28-
final String defaultUserAgent = String.format(
29-
"ArduinoIDE/%s (%s; %s; %s; %s) Java/%s (%s)",
30-
BaseNoGui.VERSION_NAME,
31-
System.getProperty("os.name"),
32-
System.getProperty("os.version"),
33-
System.getProperty("os.arch"),
34-
System.getProperty("user.language"),
35-
System.getProperty("java.version"),
36-
System.getProperty("java.vendor")
37-
);
28+
final String defaultUserAgent = String
29+
.format("ArduinoIDE/%s (%s; %s; %s; %s) Java/%s (%s)",
30+
BaseNoGui.VERSION_NAME, System.getProperty("os.name"),
31+
System.getProperty("os.version"), System.getProperty("os.arch"),
32+
System.getProperty("user.language"),
33+
System.getProperty("java.version"),
34+
System.getProperty("java.vendor"));
3835
this.userAgent = PreferencesData.get("http.user_agent", defaultUserAgent);
3936
try {
40-
this.connectTimeout =
41-
Integer.parseInt(
42-
PreferencesData.get("http.connection_timeout", "5000"));
37+
this.connectTimeout = Integer
38+
.parseInt(PreferencesData.get("http.connection_timeout", "5000"));
4339
} catch (NumberFormatException e) {
4440
log.warn(
45-
"Cannot parse the http.connection_timeout configuration switch to default 5000 milliseconds", e.getCause());
41+
"Cannot parse the http.connection_timeout configuration switch to default 5000 milliseconds",
42+
e.getCause());
4643
this.connectTimeout = 5000;
4744
}
4845

4946
}
5047

51-
public HttpURLConnection makeConnection(Consumer<HttpURLConnection> beforeConnection)
52-
throws IOException, NoSuchMethodException, ScriptException, URISyntaxException {
48+
public HttpURLConnection makeConnection(
49+
Consumer<HttpURLConnection> beforeConnection)
50+
throws IOException, NoSuchMethodException, ScriptException,
51+
URISyntaxException {
5352
return makeConnection(this.requestURL, 0, beforeConnection);
5453
}
5554

56-
5755
public HttpURLConnection makeConnection()
58-
throws IOException, NoSuchMethodException, ScriptException, URISyntaxException {
59-
return makeConnection(this.requestURL, 0, (c) -> {});
56+
throws IOException, NoSuchMethodException, ScriptException,
57+
URISyntaxException {
58+
return makeConnection(this.requestURL, 0, (c) -> {
59+
});
6060
}
6161

6262
private HttpURLConnection makeConnection(URL requestURL, int movedTimes,
63-
Consumer<HttpURLConnection> beforeConnection) throws IOException, URISyntaxException, ScriptException, NoSuchMethodException {
64-
log.info("Prepare http request to " + requestURL);
63+
Consumer<HttpURLConnection> beforeConnection)
64+
throws IOException, URISyntaxException, ScriptException,
65+
NoSuchMethodException {
6566
if (movedTimes > 3) {
6667
log.warn("Too many redirect " + requestURL);
6768
throw new IOException("Too many redirect " + requestURL);
@@ -85,21 +86,21 @@ private HttpURLConnection makeConnection(URL requestURL, int movedTimes,
8586
connection.setConnectTimeout(connectTimeout);
8687
beforeConnection.accept(connection);
8788

88-
// Connect
89-
log.info("Connect to {} with method {}", requestURL, connection.getRequestMethod());
90-
9189
connection.connect();
9290
int resp = connection.getResponseCode();
9391

9492
if (resp == HttpURLConnection.HTTP_MOVED_PERM
9593
|| resp == HttpURLConnection.HTTP_MOVED_TEMP) {
9694

9795
URL newUrl = new URL(connection.getHeaderField("Location"));
98-
log.info("The response code was a 301,302 so try again with the new URL " + newUrl);
96+
log.info("The response code was a 301,302 so try again with the new URL "
97+
+ newUrl);
9998

10099
return this.makeConnection(newUrl, movedTimes + 1, beforeConnection);
101100
}
102-
log.info("The response code {}, headers {}", resp, StringUtils.join(connection.getHeaderFields()));
101+
log.info("Executed {} successfully to {} code {}, headers {}",
102+
connection.getRequestMethod(), requestURL, resp,
103+
StringUtils.join(connection.getHeaderFields()));
103104

104105
return connection;
105106
}

0 commit comments

Comments
 (0)