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

Commit c9d2414

Browse files
committed
fixes from code inspection
1 parent f38fcdd commit c9d2414

File tree

11 files changed

+34
-30
lines changed

11 files changed

+34
-30
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
<dependency>
120120
<groupId>org.yaml</groupId>
121121
<artifactId>snakeyaml</artifactId>
122-
<version>1.24</version>
122+
<version>1.23</version>
123123
</dependency>
124124
</dependencies>
125125
</project>

samples/weblogicLoggingExporter.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# domain config directory.
1212
# If file doesn't exist, will use all the defaults.
1313

14-
# The index name for weblogic loggings used in elastic search. By default it is set to "wls";
14+
# The index name for weblogic logs used in elastic search. By default it is set to "wls";
1515
# Elastic Search restricts the index name to be lower case only. Exporter will automatically convert this to all lower case.
1616
# and gives a warning.
1717
weblogicLoggingIndexName: wls
@@ -48,7 +48,7 @@ weblogicLoggingExporterBulkSize: 2
4848

4949
# Filters that will be applied to all the messages.
5050
# More than 1 filter can be specified, messages MUST satisfy all the filter condition before it will be exported.
51-
# If FilterServers is specified, then that filter will be applied only to messages thats generated by the specified servers.
51+
# If FilterServers is specified, then that filter will be applied only to messages that is generated by the specified servers.
5252
# More than one server is allowed.
5353
# If no FilterServers is specified, it will be applied to all messages.
5454
# WLDF includes a query language for constructing log filter expressions.
@@ -58,7 +58,7 @@ weblogicLoggingExporterBulkSize: 2
5858
weblogicLoggingExporterFilters:
5959
- FilterExpression: MSGID != 'BEA-000449'
6060

61-
# example of filter, this filter will only be applied to messages thats generated by Server-0
61+
# example of filter, this filter will only be applied to messages that is generated by Server-0
6262
#- FilterExpression: "(MACHINE = 'machine1') OR (SEVERITY >= Warning)"
6363
# FilterServers: Server-0
6464

src/main/java/weblogic/logging/exporter/LogExportHandler.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import weblogic.logging.exporter.config.Config;
2727
import weblogic.logging.exporter.config.FilterConfig;
2828

29-
public class LogExportHandler extends Handler {
29+
@SuppressWarnings("UnnecessaryContinue")
30+
class LogExportHandler extends Handler {
3031

3132
private static final String DOC_TYPE = "_doc";
3233
private static final String INDEX = " { \"index\" : { }} ";
@@ -36,15 +37,14 @@ public class LogExportHandler extends Handler {
3637
private String elasticSearchHost = Config.DEFAULT_ES_HOST;
3738
private int elasticSearchPort = Config.DEFAULT_ES_PORT;
3839
private int bulkSize = Config.DEFAULT_BULK_SIZE;
39-
private boolean enabled = true;
4040

4141
private String httpHostPort = "http://" + elasticSearchHost + ":" + elasticSearchPort;
4242
private String singleURL = httpHostPort + "/" + indexName + "/" + DOC_TYPE + "/?pretty";
4343
private String bulkURL = httpHostPort + "/" + indexName + "/" + DOC_TYPE + "/_bulk?pretty";
4444

45-
private Client httpClient = ClientBuilder.newClient();
45+
private final Client httpClient = ClientBuilder.newClient();
4646
private List<FilterConfig> filterConfigs = new ArrayList<>();
47-
private List<String> payloadBulkList = new ArrayList<>();
47+
private final List<String> payloadBulkList = new ArrayList<>();
4848

4949
private String domainUID = null;
5050

@@ -217,7 +217,8 @@ private void initialize(Config config) {
217217

218218
elasticSearchHost = config.getHost();
219219
elasticSearchPort = config.getPort();
220-
enabled = config.getEnabled();
220+
@SuppressWarnings("unused")
221+
boolean enabled = config.getEnabled();
221222
String severity = config.getSeverity();
222223
if (severity != null) {
223224
setLevel(WLLevel.getLevel(Severities.severityStringToNum(severity)));
@@ -286,6 +287,7 @@ private void createMappings() {
286287

287288
Result result = executePutOrPostOnUrl(httpHostPort + "/" + indexName, mappings, false);
288289
if (!result.successful) {
290+
//noinspection StatementWithEmptyBody
289291
if (result.getStatus() == HttpURLConnection.HTTP_BAD_REQUEST) {
290292
// ignore. this is the case where the index has been created in elastic search.
291293
} else {

src/main/java/weblogic/logging/exporter/Result.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
* Holder of response received from REST requests invoked using methods in {@link LogExportHandler}
1111
* class
1212
*/
13-
public class Result {
13+
@SuppressWarnings("unused")
14+
class Result {
1415

15-
final String response;
16-
final int status;
16+
private final String response;
17+
private final int status;
1718
final boolean successful;
1819

1920
public Result(String response, int status, boolean successful) {

src/main/java/weblogic/logging/exporter/Startup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Startup {
1515

1616
private static final String DEFAULT_CONFIG_FILE = "config/WebLogicLoggingExporter.yaml";
1717

18-
public static void main(String argv[]) {
18+
public static void main(String[] argv) {
1919
System.out.println("======================= Weblogic Logging Exporter Startup class called");
2020
try {
2121
// Logger logger = LoggingHelper.getDomainLogger();

src/main/java/weblogic/logging/exporter/config/Config.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Config {
2323
public static final int DEFAULT_ES_PORT = 9200;
2424
public static final String DEFAULT_INDEX_NAME = "wls";
2525
public static final int DEFAULT_BULK_SIZE = 1;
26-
public static final String DEFAULT_DOMAIN_UID = "unknown";
26+
private static final String DEFAULT_DOMAIN_UID = "unknown";
2727

2828
private static final String HOST = "ElasticSearchHost";
2929
private static final String PORT = "ElasticSearchPort";
@@ -40,7 +40,7 @@ public class Config {
4040
private int bulkSize = DEFAULT_BULK_SIZE;
4141
private boolean enabled = true;
4242
private String severity = null;
43-
private List<FilterConfig> filterConfigs = new ArrayList<>();
43+
private final List<FilterConfig> filterConfigs = new ArrayList<>();
4444
private String domainUID = DEFAULT_DOMAIN_UID;
4545

4646
private Config() {}
@@ -75,7 +75,7 @@ public static Config loadConfig(File file) {
7575
} catch (Exception ex) {
7676
System.out.println("Error detected in configuration file.");
7777
}
78-
System.out.println("Using default for all paramters");
78+
System.out.println("Using default for all parameters");
7979
return new Config();
8080
}
8181

@@ -121,7 +121,7 @@ private boolean isArrayOfMaps(Object object) {
121121
}
122122

123123
private boolean emptyOrContainsMaps(List list) {
124-
return list.isEmpty() || Map.class.isInstance(list.get(0));
124+
return list.isEmpty() || list.get(0) instanceof Map;
125125
}
126126

127127
private static Config loadConfig(Map<String, Object> yamlConfig) {

src/main/java/weblogic/logging/exporter/config/ConfigurationException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
import java.util.ArrayList;
1010
import java.util.List;
1111

12-
public class ConfigurationException extends RuntimeException {
13-
public static final String BAD_YAML_FORMAT = "Configuration YAML format has errors";
12+
class ConfigurationException extends RuntimeException {
13+
static final String BAD_YAML_FORMAT = "Configuration YAML format has errors";
1414
public static final String NOT_YAML_FORMAT = "Configuration is not in YAML format";
15-
public static final String CONFIG_FILE_NOT_FOUND = "Configuration file cannot be found";
1615

17-
private List<String> context = new ArrayList<>();
16+
private final List<String> context = new ArrayList<>();
1817

1918
ConfigurationException(String description) {
2019
super(description);
2120
}
2221

22+
@SuppressWarnings("unused")
2323
void addContext(String parentContext) {
2424
context.add(0, parentContext);
2525
}

src/main/java/weblogic/logging/exporter/config/FilterConfig.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,20 @@
1818
import weblogic.diagnostics.query.QueryFactory;
1919

2020
public class FilterConfig {
21-
static final String EXPRESSION = "FilterExpression";
22-
static final String SERVERS = "FilterServers";
21+
private static final String EXPRESSION = "FilterExpression";
22+
private static final String SERVERS = "FilterServers";
2323

24-
private static final String[] NO_VALUES = {};
2524
private String expression;
2625
private String[] servers = new String[0];
2726
private Query query = null;
28-
LogVariablesImpl lv = LogVariablesImpl.getInstance();
2927

3028
private FilterConfig(Map<String, Object> map) {
3129
for (String key : map.keySet()) {
3230
switch (key) {
3331
case EXPRESSION:
3432
expression = MapUtils.getStringValue(map, EXPRESSION);
3533
try {
34+
LogVariablesImpl lv = LogVariablesImpl.getInstance();
3635
query = QueryFactory.createQuery(lv, lv, expression);
3736
} catch (QueryException ex) {
3837
System.out.println("Error Parsing expression: " + expression);
@@ -61,7 +60,7 @@ private void setServers(String[] values) {
6160

6261
private void reportDuplicateValues(String[] values, Set<String> uniqueValues) {
6362
ArrayList<String> duplicate = new ArrayList<>(Arrays.asList(values));
64-
for (String unique : uniqueValues) duplicate.remove(duplicate.indexOf(unique));
63+
for (String unique : uniqueValues) duplicate.remove(unique);
6564

6665
throw new ConfigurationException("Duplicate values for " + duplicate);
6766
}

src/main/java/weblogic/logging/exporter/config/MapUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12-
public class MapUtils {
12+
@SuppressWarnings("SameParameterValue")
13+
class MapUtils {
1314

1415
private static final String ILLEGAL_VALUE_FORMAT = "Illegal value for %s: %s. Value must be %s";
1516

src/main/java/weblogic/logging/exporter/config/YamlParserException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/** An exception thrown when there is an error parsing the YAML. */
1212
public class YamlParserException extends ConfigurationException {
13-
private ScannerException scannerException;
13+
private final ScannerException scannerException;
1414

1515
YamlParserException(ScannerException scannerException) {
1616
super(BAD_YAML_FORMAT);

0 commit comments

Comments
 (0)