Skip to content

Commit

Permalink
Cleaned up changes to Asn1EncodedDataRouter class
Browse files Browse the repository at this point in the history
  • Loading branch information
dmccoystephenson committed Mar 13, 2024
1 parent e25246c commit e4210eb
Showing 1 changed file with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public void processEncodedTim(ServiceRequest request, JSONObject consumedObj) {

String hexEncodedTim = mfObj.getString(BYTES);
logger.debug("Encoded message - phase 1: {}", hexEncodedTim);
logger.debug("Is header present? {}", isHeaderPresent(hexEncodedTim));
//use Asnc1 library to decode the encoded tim returned from ASNC1; another class two blockers: decode the tim and decode the message-sign

if (odeProperties.dataSigningEnabled()) {
Expand Down Expand Up @@ -231,7 +230,7 @@ public void processEncodedTim(ServiceRequest request, JSONObject consumedObj) {
// if header is present, strip it
if (isHeaderPresent(hexEncodedTim)) {
String header = hexEncodedTim.substring(0, hexEncodedTim.indexOf("001F") + 4);
logger.debug("Stripping header from message: {}", header);
logger.debug("Stripping header from unsigned message: {}", header);
hexEncodedTim = stripHeader(hexEncodedTim);
mfObj.remove(BYTES);
mfObj.put(BYTES, hexEncodedTim);
Expand All @@ -244,15 +243,13 @@ public void processEncodedTim(ServiceRequest request, JSONObject consumedObj) {

if (null != request.getSnmp() && null != request.getRsus() && null != hexEncodedTim) {
logger.info("Sending message to RSUs...");
logger.debug("Is header present? {}", isHeaderPresent(hexEncodedTim));
asn1CommandManager.sendToRsus(request, hexEncodedTim);
}

if (request.getSdw() != null) {
// Case 2 only

logger.debug("Publishing message for round 2 encoding!");
logger.debug("Is header present? {}", isHeaderPresent(hexEncodedTim));
String xmlizedMessage = asn1CommandManager.packageSignedTimIntoAsd(request, hexEncodedTim);

stringMsgProducer.send(odeProperties.getKafkaTopicAsn1EncoderInput(), null, xmlizedMessage);
Expand Down Expand Up @@ -332,20 +329,23 @@ public void processEncodedTimUnsecured(ServiceRequest request, JSONObject consum
String encodedTim = mfObj.getString(BYTES);

// if header is present, strip it
logger.debug("Is header present? {}", isHeaderPresent(encodedTim));
if (isHeaderPresent(encodedTim)) {
String header = encodedTim.substring(0, encodedTim.indexOf("001F") + 4);
logger.debug("Stripping header from message: {}", header);
logger.debug("Stripping header from unsigned message: {}", header);
encodedTim = stripHeader(encodedTim);
mfObj.remove(BYTES);
mfObj.put(BYTES, encodedTim);
dataObj.remove(MESSAGE_FRAME);
dataObj.put(MESSAGE_FRAME, mfObj);
consumedObj.remove(AppContext.PAYLOAD_STRING);
consumedObj.put(AppContext.PAYLOAD_STRING, dataObj);
}

logger.debug("Encoded message - phase 2: {}", encodedTim);
logger.debug("Is header present? {}", isHeaderPresent(encodedTim));

// only send message to rsu if snmp, rsus, and message frame fields are present
if (null != request.getSnmp() && null != request.getRsus() && null != encodedTim) {
logger.debug("Encoded message phase 3: {}", encodedTim);
logger.debug("Is header present? {}", isHeaderPresent(encodedTim));
asn1CommandManager.sendToRsus(request, encodedTim);
}
}
Expand All @@ -357,11 +357,7 @@ public void processEncodedTimUnsecured(ServiceRequest request, JSONObject consum
* Checks if header is present in encoded message
*/
private boolean isHeaderPresent(String encodedTim) {
boolean toReturn = encodedTim.indexOf("001F") > 0;
if (toReturn) {
logger.warn("Header found in encoded message: {}", encodedTim);
}
return toReturn;
return encodedTim.indexOf("001F") > 0;
}

/**
Expand Down

0 comments on commit e4210eb

Please sign in to comment.