Skip to content

Commit 86d2ae4

Browse files
committed
fixed defects
1 parent fbe694a commit 86d2ae4

21 files changed

+355
-168
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
<plugin>
122122
<groupId>org.apache.maven.plugins</groupId>
123123
<artifactId>maven-release-plugin</artifactId>
124-
<version>2.5</version>
124+
<version>2.3.2</version>
125125
<configuration>
126126
<tagNameFormat>v@{project.version}</tagNameFormat>
127127
</configuration>

release.properties

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/main/java/org/audit4j/core/AsyncAuditEngine.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ protected synchronized void initializeIfNeeded() {
188188
*/
189189
@Override
190190
public void onException(final JMSException arg0) {
191-
// TODO Auto-generated method stub
192-
191+
193192
}
194193

195194
/**

src/main/java/org/audit4j/core/AuditUtil.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
package org.audit4j.core;
2121

22-
import java.io.FileNotFoundException;
23-
import java.io.FileOutputStream;
24-
import java.io.PrintStream;
2522
import java.sql.Timestamp;
2623
import java.text.DateFormat;
2724
import java.text.SimpleDateFormat;
@@ -84,30 +81,6 @@ public static Map<String, String> transformMap(final Map<String, Object> paramMa
8481
return paramStrMap;
8582
}
8683

87-
/**
88-
* Compute target stream.
89-
*
90-
* @param logFile
91-
* the log file
92-
* @return the prints the stream
93-
*/
94-
private static PrintStream computeTargetStream(String logFile) {
95-
if ("System.err".equalsIgnoreCase(logFile))
96-
return System.err;
97-
else if ("System.out".equalsIgnoreCase(logFile)) {
98-
return System.out;
99-
} else {
100-
try {
101-
FileOutputStream fos = new FileOutputStream(logFile);
102-
PrintStream printStream = new PrintStream(fos);
103-
return printStream;
104-
} catch (FileNotFoundException e) {
105-
AuditUtil.report("Could not open [" + logFile + "]. Defaulting to System.err", e);
106-
return System.err;
107-
}
108-
}
109-
}
110-
11184
/**
11285
* Gets the uuid.
11386
*

src/main/java/org/audit4j/core/ConfigUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ static Configuration readConfig() throws ConfigurationException {
146146
}
147147
}
148148

149-
public static void main(String[] args) {
150-
generateConfigFromObject();
149+
static List<String> getHandlerClassNames(List<Handler> handlers){
150+
List<String> handlerClassNameList = new ArrayList<>();
151+
for (Handler handler : handlers) {
152+
handlerClassNameList.add(handler.getClass().getName());
153+
}
154+
return handlerClassNameList;
151155
}
152156
}

src/main/java/org/audit4j/core/Context.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.audit4j.core.exception.ConfigurationException;
2626
import org.audit4j.core.exception.InitializationException;
2727
import org.audit4j.core.exception.TroubleshootException;
28+
import org.audit4j.core.exception.ValidationException;
2829
import org.audit4j.core.handler.Handler;
2930

3031
/**
@@ -44,17 +45,17 @@ public class Context {
4445
* Load config.
4546
*/
4647
private static void loadConfig() {
47-
System.out.println("Loading Configurations..");
48+
Log.info("Loading Configurations...");
4849
try {
4950
conf = ConfigUtil.readConfig();
5051
} catch (ConfigurationException e) {
5152
try {
5253
TroubleshootManager.troubleshootConfiguration(e);
5354
conf = ConfigUtil.readConfig();
5455
} catch (TroubleshootException e2) {
55-
throw new InitializationException("Configuration initialization failed.", e2);
56+
throw new InitializationException("Initialization failed.!!", e2);
5657
} catch (ConfigurationException e1) {
57-
throw new InitializationException("Configuration initialization failed.", e1);
58+
throw new InitializationException("Initialization failed.!!", e1);
5859
}
5960
}
6061
}
@@ -64,25 +65,32 @@ private static void loadConfig() {
6465
*/
6566
private static void init() {
6667
if (!initialized) {
67-
System.out.println("Initializing Audit4j..");
68+
Log.info("Initializing Audit4j...");
6869
loadConfig();
70+
Log.info("Validating Configurations...");
71+
6972
if (conf == null) {
70-
throw new InitializationException("Configuration initialization failed.");
73+
throw new InitializationException("initialization failed.!!");
7174
} else {
75+
try {
76+
ValidationManager.validateConfigurations(conf);
77+
} catch (ValidationException e1) {
78+
throw new InitializationException("initialization failed.!!", e1);
79+
}
7280
for (Map.Entry<String, String> entry : conf.getProperties().entrySet()) {
7381
if (System.getProperties().containsKey(entry.getValue())) {
7482
conf.getProperties().put(entry.getKey(), System.getProperty(entry.getValue()));
7583
}
7684
}
7785

78-
System.out.println("Initializing Handlers..");
86+
Log.info("Initializing Handlers..");
7987
for (Handler handler : conf.getHandlers()) {
8088
try {
8189
handler.setProperties(conf.getProperties());
8290
handler.init();
83-
System.out.println(handler.getClass().getName() + " Initialized.");
91+
Log.info(handler.getClass().getName() + " Initialized.");
8492
} catch (InitializationException e) {
85-
93+
throw new InitializationException("initialization failed.!!", e);
8694
}
8795
}
8896
initialized = true;
@@ -115,9 +123,6 @@ public static List<Handler> getHandlers() {
115123
* @return true, if is initialized
116124
*/
117125
public boolean isInitialized() {
118-
if (null == conf) {
119-
return false;
120-
}
121-
return true;
126+
return initialized;
122127
}
123128
}

src/main/java/org/audit4j/core/CoreConstants.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,27 @@
2323
*/
2424
public final class CoreConstants {
2525

26+
/** The Constant APP_NAME. */
2627
public static final String APP_NAME = "Audit4j";
2728

28-
public static final String RELEASE_VERSION = "1.0.0.RELEASE";
29+
/** The Constant RELEASE_VERSION. */
30+
public static final String RELEASE_VERSION = "1.0.1";
2931

30-
public static final String RELEASE_DATE = "2014-06-15T11:17:21.077Z";
32+
/** The Constant RELEASE_DATE. */
33+
public static final String RELEASE_DATE = "2014-06-20T11:17:21.077Z";
34+
35+
/** The Constant SUPPORT_JAVA_VERSION. */
36+
public static final String SUPPORT_JAVA_VERSION = "7";
37+
38+
/** The Constant AUDIT_EXTENTION. */
39+
public static final String AUDIT_EXTENTION = ".audit";
40+
41+
/** The Constant SITE_URL. */
42+
public static final String SITE_URL = "http://mechanizedspace.com/audit4j/";
43+
44+
/** The Constant CONFIG_FILE_NAME. */
45+
public static final String CONFIG_FILE_NAME = "auit4j.conf.yml";
46+
3147
/** The Constant COLON_CHAR. */
3248
public static final char COLON_CHAR = ':';
3349

@@ -58,15 +74,9 @@ public final class CoreConstants {
5874
/** The Constant NEW_LINE. */
5975
public static final String NEW_LINE = "\n";
6076

61-
/** The Constant AUDIT_EXTENTION. */
62-
public static final String AUDIT_EXTENTION = ".audit";
63-
6477
/** The Constant DEFAULT_ACTOR. */
6578
public static final String DEFAULT_ACTOR = "Audit4j User";
6679

67-
/** The Constant ANNOTATION_INTREGRATION_CLASS. */
68-
public static final String ANNOTATION_INTREGRATION_CLASS = "com.audit4j.intregration.Audit4jAnnotationActivator";
69-
7080
/** The Constant ACTION. */
7181
public static final String ACTION = "action";
7282

@@ -76,17 +86,9 @@ public final class CoreConstants {
7686
/** The Constant IV. */
7787
public static final String IV = "e675f725e675f725";
7888

89+
/** The Constant ENCODE_UTF8. */
7990
public static final String ENCODE_UTF8 = "UTF-8";
8091

81-
public static final String SITE_URL = "http://mechanizedspace.com/audit4j/";
82-
83-
public static final String CONFIG_FILE_NAME = "auit4j.conf.yml";
84-
85-
public static final String INITIAL_CONFIG_FILE = "!Configuration\nreleased: "
86-
+ RELEASE_DATE
87-
+ "\nversion: "
88-
+ RELEASE_VERSION
89-
+ "\nhandlers:\n- !org.audit4j.core.handler.db.GeneralDatabaseAuditHandler {}\nlayout:\n!org.audit4j.core.SimpleLayout {}\nmetaData: !org.audit4j.core.DummyMetaData {}\nproperties:\n- {key: log.file.location, value: user.dir}";
90-
92+
/** The Constant EMBEDED_DB_NAME. */
9193
public static final String EMBEDED_DB_NAME = "audit4j";
9294
}

src/main/java/org/audit4j/core/DummyMetaData.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* @author <a href="mailto:[email protected]">Janith Bandara</a>
77
*/
88
public class DummyMetaData implements MetaData{
9+
10+
/** The Constant serialVersionUID. */
11+
private static final long serialVersionUID = 8550924108774636181L;
912

1013
/* (non-Javadoc)
1114
* @see org.audit4j.core.MetaData#getActor()
Lines changed: 89 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,117 @@
1+
/*
2+
* Copyright 2014 Janith Bandara, This source is a part of Audit4j -
3+
* An open-source audit platform for Enterprise java platform.
4+
* http://mechanizedspace.com/audit4j
5+
* http://audit4j.org
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
120
package org.audit4j.core;
221

22+
import java.io.PrintStream;
23+
import java.io.PrintWriter;
24+
import java.io.StringWriter;
25+
326
/**
4-
* The Class Log.
5-
*
27+
* Default logger for Audit4j internal usage.
28+
*
629
* @author <a href="mailto:[email protected]">Janith Bandara</a>
730
*/
831
public class Log {
932

1033
/** The Constant AUDIT4J_INFO. */
11-
private static final String AUDIT4J_INFO = CoreConstants.APP_NAME + ":INFO";
34+
private static final String APP_INFO = CoreConstants.APP_NAME + ":INFO ";
1235

1336
/** The Constant AUDIT4J_WARN. */
14-
private static final String AUDIT4J_WARN = CoreConstants.APP_NAME + ":WARN";
37+
private static final String APP_WARN = CoreConstants.APP_NAME + ":WARN ";
1538

1639
/** The Constant AUDIT4J_ERROR. */
17-
private static final String AUDIT4J_ERROR = CoreConstants.APP_NAME + ":ERROR";
40+
private static final String APP_ERROR = CoreConstants.APP_NAME + ":ERROR ";
1841

42+
/** The info stream. */
43+
private static PrintStream infoStream = System.out;
44+
45+
/** The warn stream. */
46+
private static PrintStream warnStream = System.err;
47+
48+
/** The error stream. */
49+
private static PrintStream errorStream = System.err;
50+
1951
/**
20-
* Info.
21-
*
22-
* @param message the message
52+
* Write information in the console.
53+
*
54+
* @param message
55+
* the message
2356
*/
24-
public static void info(Object message) {
25-
System.out.println(AUDIT4J_INFO + message.toString());
57+
public static void info(final Object message) {
58+
infoStream.println(APP_INFO + message.toString());
2659
}
2760

61+
62+
2863
/**
29-
* Warn.
64+
* Write warn messasge on console.
65+
*
66+
* @param message
67+
* the message
68+
*/
69+
public static void warn(final Object message) {
70+
warnStream.println(APP_WARN + message.toString());
71+
}
72+
73+
/**
74+
* Write warn message on console with exception.
3075
*
3176
* @param message the message
77+
* @param t the t
3278
*/
33-
public static void warn(Object message) {
34-
System.err.println(AUDIT4J_WARN + message.toString());
79+
public static void warn(final Object message, final Throwable t) {
80+
warnStream.println(APP_WARN + message.toString());
81+
warnStream.println(stackTraceToString(t));
3582
}
36-
83+
3784
/**
38-
* Error.
85+
* Write error message on console.
86+
*
87+
* @param message
88+
* the message
89+
*/
90+
public static void error(final Object message) {
91+
errorStream.println(APP_ERROR + message.toString());
92+
}
93+
94+
/**
95+
* Write error messages on console with exception.
3996
*
4097
* @param message the message
98+
* @param t the t
99+
*/
100+
public static void error(final Object message, final Throwable t) {
101+
errorStream.println(APP_ERROR + message.toString());
102+
errorStream.println(stackTraceToString(t));
103+
}
104+
105+
/**
106+
* Convert Stack trace to string.
107+
*
108+
* @param t the t
109+
* @return the string
41110
*/
42-
public static void error(Object message) {
43-
System.err.println(AUDIT4J_ERROR + message.toString());
111+
private static String stackTraceToString(final Throwable t) {
112+
final StringWriter sw = new StringWriter();
113+
final PrintWriter pw = new PrintWriter(sw);
114+
t.printStackTrace(pw);
115+
return sw.toString();
44116
}
45117
}

src/main/java/org/audit4j/core/SecureLayout.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,19 @@
2121

2222
import org.audit4j.core.dto.AuditEvent;
2323

24+
/**
25+
* The Class SecureLayout.
26+
*
27+
* @author <a href="mailto:[email protected]">Janith Bandara</a>
28+
*/
2429
public class SecureLayout extends SimpleLayout {
2530

31+
/** The Constant serialVersionUID. */
32+
private static final long serialVersionUID = -5678939488854601303L;
33+
34+
/* (non-Javadoc)
35+
* @see org.audit4j.core.SimpleLayout#format(org.audit4j.core.dto.AuditEvent)
36+
*/
2637
@Override
2738
public String format(AuditEvent event) {
2839
String formatText = super.format(event);

0 commit comments

Comments
 (0)