1 package com.trendmicro.grid.acl.ds.msmq;
2
3 import net.sf.tinyjee.collections.Filter;
4 import net.sf.tinyjee.collections.FilteredCollection;
5 import net.sf.tinyjee.config.*;
6 import net.sf.tinyjee.config.documentation.ResourceDocumentation;
7 import net.sf.tinyjee.config.documentation.SectionDocumentation;
8
9 import java.util.Arrays;
10 import java.util.Collection;
11 import java.util.Collections;
12
13
14
15
16
17
18
19 @SectionDocumentation(
20 name = MSMQPropertySection.NAME_SECTION,
21 description = "Configures the data binding against the MSMQ Message Bus."
22 )
23 @ResourceDocumentation(
24 name = MSMQPropertySection.NAME_CONNECTION,
25 description = "Defines an outgoing connection to the MSMQ server using the HTTP " +
26 "transport protocol.\n" +
27 "\n" +
28 "Adjust the value of 'msmqhost' to match the hostname or hostname:port of " +
29 "the IIS server hosting the 'HTTPMSMQBridge' module. The complete address " +
30 "must point to the custom bridge application in order to make the MSQM connection " +
31 "functional."
32 )
33 public class MSMQPropertySection extends PropertySection implements ConfigurationBuilder {
34
35 private static final long serialVersionUID = -4111897772847377832L;
36
37 public static final String NAME_SECTION = "gacl-msmq-messagebus";
38 public static final String NAME_CONNECTION = "gacl-msmq";
39
40 public static final String KEY_TARGET_QUEUE_PREFIX = "targetQueue:";
41 public static final String QUEUE_PROCESS_REQUEST = "process.requests";
42
43 public static String getTargetQueueKey(String queueName) {
44 return KEY_TARGET_QUEUE_PREFIX.concat(queueName);
45 }
46
47 public static String getTargetQueue(String queueName) {
48 String key = getTargetQueueKey(queueName);
49 return ConfigurationContext.getInstance().getConfiguration().getPropertyValue(key);
50 }
51
52 public static Collection<Connection> getMSMQConnections() {
53 Configuration config = ConfigurationContext.getInstance().getConfiguration();
54 return new FilteredCollection<Connection>(config.getActiveConnections(), new Filter<Connection>() {
55 public boolean accept(Connection value) {
56 return NAME_CONNECTION.equals(value.getName());
57 }
58 });
59 }
60
61 public MSMQPropertySection() {
62 super(NAME_SECTION);
63
64
65 addProperty(getTargetQueueKey(QUEUE_PROCESS_REQUEST), "al_out");
66 }
67
68
69
70
71 public Collection<PropertySection> buildDefaultSections() {
72 return Collections.singleton((PropertySection) new MSMQPropertySection());
73 }
74
75
76
77
78 @Override
79 public Collection<? extends Resource> buildDefaultResources() {
80 Connection devConnection = createConnection();
81 return Arrays.asList(devConnection);
82 }
83
84 private Connection createConnection() {
85 return new Connection(
86 Connection.Protocol.http, Connection.Type.outgoing, NAME_CONNECTION,
87 "http://${msmqbridgehost}/HTTPMSMQBridge/", 80);
88 }
89 }
90