Skip to content

Commit

Permalink
Merge pull request #210 from icatproject/threadsafe_jms_session
Browse files Browse the repository at this point in the history
try-with-resource JMS Session to send messages. Fixes #202 - again!
  • Loading branch information
stuartpullinger committed Jan 3, 2019
2 parents 5013858 + 5125fee commit 17d616b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -105,7 +105,7 @@
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
<version>1.3.3</version>
</dependency>

<dependency>
Expand Down
Expand Up @@ -42,7 +42,7 @@ private void init() {
.lookup(propertyHandler.getJmsTopicConnectionFactory());
topicConnection = topicConnectionFactory.createTopicConnection();
topic = (Topic) ic.lookup("jms/ICAT/Topic");
logger.info("Transmitter created");
logger.info("Notification Transmitter created");
} catch (JMSException | NamingException e) {
logger.error(fatal, "Problem with JMS " + e);
throw new IllegalStateException(e.getMessage());
Expand All @@ -56,7 +56,7 @@ private void exit() {
if (topicConnection != null) {
topicConnection.close();
}
logger.info("Transmitter closing down");
logger.info("Notification Transmitter closing down");
} catch (JMSException e) {
throw new IllegalStateException(e.getMessage());
}
Expand All @@ -65,16 +65,19 @@ private void exit() {
public void processMessage(NotificationMessage notificationMessage) throws JMSException {
Message message = notificationMessage.getMessage();
if (message != null) {
Session jmsSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer jmsProducer = jmsSession.createProducer(topic);
ObjectMessage jmsg = jmsSession.createObjectMessage();
jmsg.setStringProperty("entity", message.getEntityName());
jmsg.setStringProperty("operation", message.getOperation());
jmsg.setObject(message.getEntityId());
jmsProducer.send(jmsg);
logger.debug("Sent jms message " + message.getOperation() + " " + message.getEntityName() + " "
try ( Session jmsSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE) )
{
MessageProducer jmsProducer = jmsSession.createProducer(topic);
ObjectMessage jmsg = jmsSession.createObjectMessage();
jmsg.setStringProperty("entity", message.getEntityName());
jmsg.setStringProperty("operation", message.getOperation());
jmsg.setObject(message.getEntityId());
jmsProducer.send(jmsg);
logger.debug("Sent jms notification message " + message.getOperation() + " " + message.getEntityName() + " "
+ message.getEntityId());
jmsSession.close();
} catch (JMSException e) {
logger.error("Failed to send jms notification message ");
}
}

}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/icatproject/core/manager/Transmitter.java
Expand Up @@ -62,8 +62,8 @@ private void exit() {
}

public void processMessage(String operation, String ip, String body, long startMillis) {
try {
Session jmsSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
try ( Session jmsSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE) )
{
TextMessage jmsg = jmsSession.createTextMessage(body);
jmsg.setStringProperty("operation", operation);
jmsg.setStringProperty("ip", ip);
Expand All @@ -72,7 +72,6 @@ public void processMessage(String operation, String ip, String body, long startM
MessageProducer jmsProducer = jmsSession.createProducer(topic);
jmsProducer.send(jmsg);
logger.debug("Sent jms message " + operation + " " + ip);
jmsSession.close();
} catch (JMSException e) {
logger.error("Failed to send jms message " + operation + " " + ip);
}
Expand Down
7 changes: 7 additions & 0 deletions src/site/xhtml/release-notes.xhtml
Expand Up @@ -6,6 +6,13 @@

<h1>ICAT Server Release Notes</h1>

<h2>4.9.3</h2>
<p>Bug fixes</p>
<ul>
<li>Make the message transmitters more fault-tolerant.</li>
<li>Upgrade commons-fileupload from 1.3 to 1.3.3 because of security vulnerabilities (<a href="https://nvd.nist.gov/vuln/detail/CVE-2016-3092">CVE-2016-3092</a>, <a href="https://nvd.nist.gov/vuln/detail/CVE-2016-1000031">CVE-2016-1000031</a>, <a href="https://nvd.nist.gov/vuln/detail/CVE-2014-0050">CVE-2014-0050</a>).</li>
</ul>

<h2>4.9.2</h2>
<p>Bug fixes</p>
<ul>
Expand Down

0 comments on commit 17d616b

Please sign in to comment.