|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
JBossMapMessageSender.java | - | 68.2% | 66.7% | 68% |
|
1 |
package com.diasparsoftware.javax.jms;
|
|
2 |
|
|
3 |
import java.util.Map;
|
|
4 |
|
|
5 |
import javax.jms.*;
|
|
6 |
import javax.naming.*;
|
|
7 |
|
|
8 |
import com.diasparsoftware.java.util.*;
|
|
9 |
|
|
10 |
public class JBossMapMessageSender implements MapMessageSender { |
|
11 |
public static final String QUEUE_CONNECTION_FACTORY_JNDI_NAME = |
|
12 |
"ConnectionFactory";
|
|
13 |
|
|
14 | 11 |
public void sendMapMessage( |
15 |
String destinationQueueName, |
|
16 |
Map messageContent) { |
|
17 |
|
|
18 | 11 |
try {
|
19 | 11 |
Context context = new InitialContext();
|
20 | 11 |
QueueConnectionFactory queueConnectionFactory = |
21 |
(QueueConnectionFactory) context.lookup( |
|
22 |
QUEUE_CONNECTION_FACTORY_JNDI_NAME); |
|
23 |
|
|
24 | 11 |
QueueConnection connection = |
25 |
queueConnectionFactory.createQueueConnection(); |
|
26 |
|
|
27 | 11 |
Queue submitOrderQueue = |
28 |
(Queue) context.lookup(destinationQueueName); |
|
29 |
|
|
30 | 11 |
QueueSession session = |
31 |
connection.createQueueSession( |
|
32 |
false,
|
|
33 |
QueueSession.AUTO_ACKNOWLEDGE); |
|
34 |
|
|
35 | 11 |
connection.start(); |
36 |
|
|
37 | 11 |
final MapMessage message = session.createMapMessage(); |
38 |
|
|
39 | 11 |
addMessageContentToMessage(messageContent, message); |
40 |
|
|
41 | 11 |
QueueSender sender = session.createSender(submitOrderQueue); |
42 | 11 |
sender.send(message); |
43 |
|
|
44 | 11 |
connection.stop(); |
45 | 11 |
session.close(); |
46 | 11 |
connection.close(); |
47 |
} |
|
48 |
catch (NamingException e) {
|
|
49 | 0 |
throw new MessagingException("Unable to send message", e); |
50 |
} |
|
51 |
catch (JMSException e) {
|
|
52 | 0 |
throw new MessagingException("Unable to send message", e); |
53 |
} |
|
54 |
} |
|
55 |
|
|
56 | 11 |
private void addMessageContentToMessage( |
57 |
Map messageContent, |
|
58 |
final MapMessage message) { |
|
59 |
|
|
60 | 11 |
CollectionUtil |
61 |
.forEachDo(messageContent, new MapEntryClosure() {
|
|
62 | 0 |
public void eachMapEntry(Object key, Object value) { |
63 | 0 |
try {
|
64 | 0 |
message.setObject((String) key, value); |
65 |
} |
|
66 |
catch (JMSException wrapped) {
|
|
67 | 0 |
IllegalArgumentException wrapper = |
68 |
new IllegalArgumentException(
|
|
69 |
"Unable to set message property <"
|
|
70 |
+ key |
|
71 |
+ "> with value <"
|
|
72 |
+ value |
|
73 |
+ ">");
|
|
74 | 0 |
wrapper.initCause(wrapped); |
75 | 0 |
throw wrapper;
|
76 |
} |
|
77 |
} |
|
78 |
}); |
|
79 |
} |
|
80 |
} |
|