Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra logging first draft #836

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions quickfixj-base/src/main/java/quickfix/DataDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package quickfix;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
Expand Down Expand Up @@ -73,6 +75,8 @@ public class DataDictionary {
private static final String JDK_DOCUMENT_BUILDER_FACTORY_NAME = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
private static final Supplier<DocumentBuilderFactory> DEFAULT_DOCUMENT_BUILDER_FACTORY_SUPPLIER = createDocumentBuilderFactorySupplier();

protected static final Logger LOG = LoggerFactory.getLogger(DataDictionary.class);

private static Supplier<DocumentBuilderFactory> createDocumentBuilderFactorySupplier() {
return () -> {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
Expand Down Expand Up @@ -670,7 +674,7 @@ private void iterate(ValidationSettings settings, FieldMap map, String msgType,

if (hasVersion) {
checkValidFormat(settings, field);
checkValue(field);
checkValue(settings, field);
}

if (beginString != null) {
Expand Down Expand Up @@ -720,8 +724,15 @@ boolean checkFieldFailure(ValidationSettings settings, int field, boolean messag
boolean fail;
if (field < USER_DEFINED_TAG_MIN) {
fail = !messageField && !settings.allowUnknownMessageFields;
if (settings.fieldValidationLogging && !messageField && settings.allowUnknownMessageFields) {
LOG.warn("Unknown Message Field {} detected", field);
}
} else {
fail = !messageField && settings.checkUserDefinedFields;
if (settings.fieldValidationLogging && !messageField && settings.checkUserDefinedFields) {
LOG.warn("Unknown User Defined Field {} detected", field);
}

}
return fail;
}
Expand Down Expand Up @@ -788,10 +799,14 @@ private void checkValidFormat(ValidationSettings settings, StringField field) th
}
}

private void checkValue(StringField field) throws IncorrectTagValue {
private void checkValue(ValidationSettings settings, StringField field) throws IncorrectTagValue {
int tag = field.getField();
if (hasFieldValue(tag) && !isFieldValue(tag, field.getValue())) {
throw new IncorrectTagValue(tag);
if (settings.fieldValidationLogging) {
LOG.warn("Unknown Enum value {} for tag {} is detected", field.getValue(), tag);
} else {
throw new IncorrectTagValue(tag);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions quickfixj-base/src/main/java/quickfix/ValidationSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ValidationSettings {
boolean checkUserDefinedFields = true;
boolean checkUnorderedGroupFields = true;
boolean allowUnknownMessageFields = false;
boolean fieldValidationLogging = false;

public ValidationSettings() {}

Expand All @@ -34,6 +35,7 @@ public ValidationSettings(ValidationSettings validationSettings) {
this.checkUserDefinedFields = validationSettings.checkUserDefinedFields;
this.checkUnorderedGroupFields = validationSettings.checkUnorderedGroupFields;
this.allowUnknownMessageFields = validationSettings.allowUnknownMessageFields;
this.fieldValidationLogging = validationSettings.fieldValidationLogging;
}

/**
Expand Down Expand Up @@ -65,6 +67,10 @@ public boolean isAllowUnknownMessageFields() {
return allowUnknownMessageFields;
}

public boolean isFieldValidationLogging() {
return fieldValidationLogging;
}

/**
* Controls whether group fields are in the same order
*
Expand Down Expand Up @@ -95,4 +101,8 @@ public void setCheckUserDefinedFields(boolean flag) {
public void setAllowUnknownMessageFields(boolean allowUnknownFields) {
allowUnknownMessageFields = allowUnknownFields;
}

public void setFieldValidationLogging(boolean fieldValidation) {
fieldValidationLogging = fieldValidation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void copyConstructor_retains_settings() {
validationSettings.setCheckFieldsOutOfOrder(false);
validationSettings.setCheckUnorderedGroupFields(false);
validationSettings.setCheckUserDefinedFields(false);
validationSettings.setFieldValidationLogging(true);

ValidationSettings validationSettingsCopy = new ValidationSettings(validationSettings);

Expand All @@ -22,5 +23,6 @@ public void copyConstructor_retains_settings() {
assertEquals(validationSettingsCopy.isCheckFieldsOutOfOrder(), validationSettings.isCheckFieldsOutOfOrder());
assertEquals(validationSettingsCopy.isCheckUnorderedGroupFields(), validationSettings.isCheckUnorderedGroupFields());
assertEquals(validationSettingsCopy.isCheckUserDefinedFields(), validationSettings.isCheckUserDefinedFields());
assertEquals(validationSettingsCopy.isFieldValidationLogging(), validationSettings.isFieldValidationLogging());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ private ValidationSettings createValidationSettings(SessionID sessionID, Session
Session.SETTING_ALLOW_UNKNOWN_MSG_FIELDS));
}

if (settings.isSetting(sessionID, Session.SETTING_FIELD_VALIDATION_LOGGING)) {
validationSettings.setFieldValidationLogging(settings.getBool(sessionID,
Session.SETTING_FIELD_VALIDATION_LOGGING));
}

return validationSettings;
}

Expand Down
2 changes: 2 additions & 0 deletions quickfixj-core/src/main/java/quickfix/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ public class Session implements Closeable {
*/
public static final String SETTING_ALLOW_UNKNOWN_MSG_FIELDS = "AllowUnknownMsgFields";

public static final String SETTING_FIELD_VALIDATION_LOGGING = "FieldValidationLogging";

public static final String SETTING_DEFAULT_APPL_VER_ID = "DefaultApplVerID";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void testFixtDataDictionaryConfiguration() throws Exception {
settings.setString(sessionID, Session.SETTING_APP_DATA_DICTIONARY + "." + FixVersions.BEGINSTRING_FIX40, "FIX40.xml");
settings.setString(sessionID, Session.SETTING_ALLOW_UNKNOWN_MSG_FIELDS, "Y");
settings.setString(sessionID, Session.SETTING_VALIDATE_UNORDERED_GROUP_FIELDS, "N");
settings.setString(sessionID, Session.SETTING_FIELD_VALIDATION_LOGGING, "Y");

try (Session session = factory.create(sessionID, settings)) {

Expand All @@ -113,6 +114,7 @@ public void testFixtDataDictionaryConfiguration() throws Exception {
is(notNullValue()));
assertTrue(session.getValidationSettings().isAllowUnknownMessageFields());
assertFalse(session.getValidationSettings().isCheckUnorderedGroupFields());
assertTrue(session.getValidationSettings().isFieldValidationLogging());
}
}

Expand Down Expand Up @@ -142,6 +144,7 @@ public void testFixtDataDictionaryConfigurationWithDefaultAppDataDictionary() th
is(notNullValue()));
assertTrue(session.getValidationSettings().isAllowUnknownMessageFields());
assertFalse(session.getValidationSettings().isCheckUnorderedGroupFields());
assertFalse(session.getValidationSettings().isFieldValidationLogging());
}
}

Expand Down