Skip to content

Commit

Permalink
MOSIP-32461 sonar changes
Browse files Browse the repository at this point in the history
Signed-off-by: Sowmya Ujjappa Banakar <[email protected]>
  • Loading branch information
Sowmya Ujjappa Banakar committed Jun 26, 2024
1 parent adbb8b0 commit 49f2fd1
Showing 1 changed file with 10 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ public Boolean send(MosipQueue mosipQueue, byte[] message, String address) {
* lang.Object, java.lang.Object, java.lang.String, long)
*/
@Override
@SuppressWarnings({ "java:S2095" })
public Boolean send(MosipQueue mosipQueue, byte[] message, String address, int messageTTL) {
regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(),
"", "MosipActiveMqImpl::send()::entry");

boolean flag = false;
initialSetup(mosipQueue);
MessageProducer messageProducer = null;
try {
destination = session.createQueue(address);
messageProducer = session.createProducer(destination);
MessageProducer messageProducer = session.createProducer(destination);
BytesMessage byteMessage = session.createBytesMessage();
byteMessage.writeObject(message);
if(messageTTL > 0)
Expand All @@ -133,26 +133,9 @@ public Boolean send(MosipQueue mosipQueue, byte[] message, String address, int m
+ PlatformErrorMessages.RPR_MQI_UNABLE_TO_SEND_TO_QUEUE.getMessage());
throw new ConnectionUnavailableException(
PlatformErrorMessages.RPR_MQI_UNABLE_TO_SEND_TO_QUEUE.getMessage());
} finally {
if (messageProducer != null) {
try {
messageProducer.close();
} catch (JMSException e) {
regProcLogger.error("*******SEND EXCEPTION *****", "*******SEND EXCEPTION *****",
"*******SEND EXCEPTION *****", ExceptionUtils.getFullStackTrace(e));
regProcLogger.error(LoggerFileConstant.SESSIONID.toString(),
LoggerFileConstant.REGISTRATIONID.toString(), "",
"MosipActiveMqImpl::send():: error with error message "
+ PlatformErrorMessages.RPR_MQI_UNABLE_TO_SEND_TO_QUEUE.getMessage());
throw new ConnectionUnavailableException(
PlatformErrorMessages.RPR_MQI_UNABLE_TO_SEND_TO_QUEUE.getMessage());
}
}

}
}
regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(),
"", "MosipActiveMqImpl::send()::exit");

return flag;
}

Expand All @@ -162,16 +145,16 @@ public Boolean send(MosipQueue mosipQueue, String message, String address) {
}

@Override
@SuppressWarnings({ "java:S2095" })
public Boolean send(MosipQueue mosipQueue, String message, String address, int messageTTL) {
boolean flag = false;
initialSetup(mosipQueue);
MessageProducer messageProducer = null;
try {
// fix for activemq connection issue
if (session == null)
initialSetup(mosipQueue);
destination = session.createQueue(address);
messageProducer = session.createProducer(destination);
MessageProducer messageProducer = session.createProducer(destination);
TextMessage textMessage = session.createTextMessage();
textMessage.setText(message);
if(messageTTL > 0)
Expand All @@ -186,26 +169,11 @@ public Boolean send(MosipQueue mosipQueue, String message, String address, int m
+ PlatformErrorMessages.RPR_MQI_UNABLE_TO_SEND_TO_QUEUE.getMessage());
throw new ConnectionUnavailableException(
PlatformErrorMessages.RPR_MQI_UNABLE_TO_SEND_TO_QUEUE.getMessage());
} finally {
if (messageProducer != null) {
try {
messageProducer.close();
} catch (JMSException e) {
regProcLogger.error("*******SEND EXCEPTION *****", "*******SEND EXCEPTION *****",
"*******SEND EXCEPTION *****", ExceptionUtils.getFullStackTrace(e));
regProcLogger.error(LoggerFileConstant.SESSIONID.toString(),
LoggerFileConstant.REGISTRATIONID.toString(), "",
"MosipActiveMqImpl::send():: error with error message "
+ PlatformErrorMessages.RPR_MQI_UNABLE_TO_SEND_TO_QUEUE.getMessage());
throw new ConnectionUnavailableException(
PlatformErrorMessages.RPR_MQI_UNABLE_TO_SEND_TO_QUEUE.getMessage());
}
}
}
regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(),
"", "MosipActiveMqImpl::send()::exit");

return null;
return flag;
}

/*
Expand All @@ -216,6 +184,7 @@ public Boolean send(MosipQueue mosipQueue, String message, String address, int m
* .lang.Object, java.lang.String)
*/
@Override
@SuppressWarnings({ "java:S2095" })
public byte[] consume(MosipQueue mosipQueue, String address, QueueListener object) {
regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(),
"", "MosipActiveMqImpl::consume()::entry");
Expand All @@ -232,16 +201,15 @@ public byte[] consume(MosipQueue mosipQueue, String address, QueueListener objec
if (destination == null) {
setup(mosipActiveMq);
}
MessageConsumer consumer = null;
MessageConsumer consumer;
try {
if (session == null) {
regProcLogger.error("Session is null. System will retry to create session");
setup(mosipActiveMq);
}
destination = session.createQueue(address);
consumer = session.createConsumer(destination);
consumer = session.createConsumer(destination);
consumer.setMessageListener(QueueListenerFactory.getListener(mosipQueue.getQueueName(), object));
consumer.close();
} catch (JMSException | NullPointerException e) {
regProcLogger.error("*******CONSUME EXCEPTION *****", "*******CONSUME EXCEPTION *****",
"*******CONSUME EXCEPTION *****", ExceptionUtils.getFullStackTrace(e));
Expand All @@ -258,21 +226,7 @@ public byte[] consume(MosipQueue mosipQueue, String address, QueueListener objec
throw new ConnectionUnavailableException(
PlatformErrorMessages.RPR_MQI_UNABLE_TO_CONSUME_FROM_QUEUE.getMessage());
}
}finally{
if (consumer != null) {
try {
consumer.close();
} catch (JMSException e) {
regProcLogger.error("*******CONSUME EXCEPTION *****", "*******CONSUME EXCEPTION *****",
"*******CONSUME EXCEPTION *****", ExceptionUtils.getFullStackTrace(e));
regProcLogger.error(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.REGISTRATIONID.toString(),
"", "MosipActiveMqImpl::consume():: error with error message "
+ PlatformErrorMessages.RPR_MQI_UNABLE_TO_CONSUME_FROM_QUEUE.getMessage());
throw new ConnectionUnavailableException(
PlatformErrorMessages.RPR_MQI_UNABLE_TO_CONSUME_FROM_QUEUE.getMessage());
}
}
}
}
regProcLogger.debug(LoggerFileConstant.SESSIONID.toString(), LoggerFileConstant.USERID.toString(),
"", "MosipActiveMqImpl::consume()::exit");

Expand Down

0 comments on commit 49f2fd1

Please sign in to comment.