Skip to content

Commit

Permalink
try this way
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Plotnikov committed Oct 9, 2023
1 parent 0193f64 commit 3d3ffd8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
63 changes: 34 additions & 29 deletions src/main/java/com/exactpro/th2/FixHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,6 @@ public void onOutgoingUpdateTag(@NotNull ByteBuf message, @NotNull Map<String, S

if (beginString == null) {
beginString = firstField(message).insertPrevious(BEGIN_STRING_TAG, settings.getBeginString());
} else if (!settings.getBeginString().equals(beginString.getValue())) {
beginString.setValue(settings.getBeginString());
}

FixField bodyLength = findField(message, BODY_LENGTH_TAG, US_ASCII, beginString);
Expand All @@ -777,61 +775,68 @@ public void onOutgoingUpdateTag(@NotNull ByteBuf message, @NotNull Map<String, S
FixField checksum = findLastField(message, CHECKSUM_TAG);

if (checksum == null) { // Length is updated at the of the current method
lastField(message).insertNext(CHECKSUM_TAG, STUBBING_VALUE); //stubbing until finish checking message
checksum = lastField(message).insertNext(CHECKSUM_TAG, STUBBING_VALUE); //stubbing until finish checking message
}

FixField msgSeqNum = findField(message, MSG_SEQ_NUM_TAG, US_ASCII, bodyLength);

String msgSeqNumValue = Integer.toString(this.msgSeqNum.incrementAndGet());
if (msgSeqNum == null) {
int msgSeqNumValue = this.msgSeqNum.incrementAndGet();

if (msgType != null) {
msgSeqNum = msgType.insertNext(MSG_SEQ_NUM_TAG, msgSeqNumValue);
msgSeqNum = msgType.insertNext(MSG_SEQ_NUM_TAG, Integer.toString(msgSeqNumValue));
} else {
msgSeqNum = bodyLength.insertNext(MSG_SEQ_NUM_TAG, msgSeqNumValue);
msgSeqNum = bodyLength.insertNext(MSG_SEQ_NUM_TAG, Integer.toString(msgSeqNumValue));
}
} else {
msgSeqNum.setValue(msgSeqNumValue);
}

FixField senderCompID = findField(message, SENDER_COMP_ID_TAG, US_ASCII, bodyLength);

if (senderCompID == null) {
senderCompID = msgSeqNum.insertNext(SENDER_COMP_ID_TAG, settings.getSenderCompID());
} else if (!settings.getSenderCompID().equals(senderCompID.getValue())) {
senderCompID.setValue(settings.getSenderCompID());
} else {
String value = senderCompID.getValue();

if (value == null || value.isEmpty() || value.equals("null")) {
senderCompID.setValue(settings.getSenderCompID());
}
}

FixField targetCompID = findField(message, TARGET_COMP_ID_TAG, US_ASCII, bodyLength);

if (targetCompID == null) {
targetCompID = senderCompID.insertNext(TARGET_COMP_ID_TAG, settings.getTargetCompID());
} else if (!settings.getTargetCompID().equals(targetCompID.getValue())) {
targetCompID.setValue(settings.getTargetCompID());
}

FixField senderSubID = findField(message, SENDER_SUB_ID_TAG, US_ASCII, bodyLength);
if (senderSubID == null) {
if (settings.getSenderSubID() != null) {
targetCompID.insertNext(SENDER_SUB_ID_TAG, settings.getSenderSubID());
}
} else {
if (settings.getSenderSubID() == null) {
senderSubID.clear();
} else if (!settings.getSenderSubID().equals(senderSubID.getValue())) {
senderSubID.setValue(settings.getSenderSubID());
String value = targetCompID.getValue();

if (value == null || value.isEmpty() || value.equals("null")) {
targetCompID.setValue(settings.getTargetCompID());
}
}

LOGGER.info("Body length field: {}", new String(bodyLength.getBytes()));
if (settings.getSenderSubID() != null) {
FixField senderSubID = findField(message, SENDER_SUB_ID_TAG, US_ASCII, bodyLength);

if (senderSubID == null) {
senderSubID = targetCompID.insertNext(SENDER_SUB_ID_TAG, settings.getSenderSubID());
} else {
String value = senderSubID.getValue();

if (value == null || value.isEmpty() || value.equals("null")) {
senderSubID.setValue(settings.getSenderSubID());
}
}
}
FixField sendingTime = findField(message, SENDING_TIME_TAG, US_ASCII, bodyLength);
LOGGER.info("Message before adding sending time: {}", message.toString(StandardCharsets.UTF_8));

if (sendingTime == null) {
LOGGER.info("Sending time tag value 1: {}", new String(targetCompID.getBytes()));
targetCompID.insertNext(SENDING_TIME_TAG, getTime());
} else {
LOGGER.info("Sending time tag value 2: {}", new String(sendingTime.getBytes()));
sendingTime.setValue(getTime());
LOGGER.info("Sending time tag value 3: {}", new String(sendingTime.getBytes()));
String value = sendingTime.getValue();

if (value == null || value.isEmpty() || value.equals("null")) {
sendingTime.setValue(getTime());
}
}

updateLength(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fun ByteBuf.firstField(charset: Charset = UTF_8): FixField? = FixField.atOffset(
@JvmOverloads
fun ByteBuf.lastField(charset: Charset = UTF_8): FixField? = FixField.atOffset(this, writerIndex() - 1, charset)

val K_LOGGER = KotlinLogging.logger { }
@JvmOverloads
inline fun ByteBuf.forEachField(
charset: Charset = UTF_8,
Expand All @@ -53,12 +52,9 @@ inline fun ByteBuf.forEachField(
) {
var field = start

field?.bytes?.let { K_LOGGER.info { "Processing field: ${String(it)}" } }

while (field != null) {
action(field)
field = field.next()
field?.bytes?.let { K_LOGGER.info { "Processing field: ${String(it)}" } }
}
}

Expand Down

0 comments on commit 3d3ffd8

Please sign in to comment.