Created
July 23, 2017 19:52
-
-
Save sajithdilshan/b0b4fab55bcc46c8795e9a1b9bcbdafd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.adroitlogic.x.annotation.config.Parameter; | |
import org.adroitlogic.x.api.config.InputType; | |
import org.adroitlogic.x.api.template.ResourceTemplate; | |
import org.adroitlogic.x.api.template.XResourceTemplate; | |
import java.util.UUID; | |
@ResourceTemplate(displayName = "ActiveMQ JMS") | |
public class ActiveMQJmsConfiguration implements XResourceTemplate { | |
@Parameter(displayName = "Resource ID Prefix", description = "Specify the ID prefix for configuration resources", | |
inputType = InputType.TEXT_BOX, placeHolder = "MQ1") | |
private String beanPrefix; | |
@Parameter(displayName = "Broker URL", description = "Specify the URL of the broker", inputType = InputType.TEXT_BOX, | |
placeHolder = "tcp://localhost:61616", propertyName = "brokerURL") | |
private String brokerURL = "localhost"; | |
@Parameter(displayName = "Username", description = "Specify the username for the broker", inputType = InputType.TEXT_BOX, | |
isOptional = true, propertyName = "userName") | |
private String userName; | |
@Parameter(displayName = "Password", description = "Specify the password for the above mentioned user", | |
inputType = InputType.TEXT_BOX, isOptional = true, propertyName = "password") | |
private String password; | |
@Override | |
public String getXmlConfiguration() { | |
if (beanPrefix == null) { | |
beanPrefix = UUID.randomUUID().toString(); | |
} | |
String newConfig = CONFIG.replaceAll("BEANPREFIX", beanPrefix); | |
String auth = ""; | |
if (userName != null) { | |
auth = String.format(AUTH, userName, password); | |
} | |
return String.format(newConfig, brokerURL, auth); | |
} | |
private static final String AUTH = | |
" <property name=\"userName\" value=\"%s\"/>\n" + | |
" <property name=\"password\" value=\"%s\"/>\n"; | |
private static final String CONFIG = "\n" + | |
" <x:resource id=\"BEANPREFIX-activeMQ-ConnectionFactory\">\n" + | |
" <bean class=\"org.apache.activemq.ActiveMQConnectionFactory\">\n" + | |
" <property name=\"brokerURL\" value=\"%s\"/>\n" + | |
"%s" + | |
" </bean>\n" + | |
" </x:resource>\n" + | |
" <x:resource id=\"BEANPREFIX-activeMQ-jmxTxnManager\">\n" + | |
" <bean class=\"org.springframework.jms.connection.JmsTransactionManager\">\n" + | |
" <constructor-arg index=\"0\" type=\"javax.jms.ConnectionFactory\" ref=\"BEANPREFIX-activeMQ-springCachingConnectionFactory\"/>\n" + | |
" </bean>\n" + | |
" </x:resource>\n" + | |
" <x:resource id=\"BEANPREFIX-activeMQ-ultraTxnManager\">\n" + | |
" <bean class=\"org.adroitlogic.x.base.trp.UltraPlatformTransactionManager\">\n" + | |
" <property name=\"txnManager\" ref=\"BEANPREFIX-activeMQ-jmxTxnManager\"/>\n" + | |
" </bean>\n" + | |
" </x:resource>\n" + | |
" <x:resource id=\"BEANPREFIX-activeMQ-jmsTemplate\">\n" + | |
" <bean class=\"org.springframework.jms.core.JmsTemplate\">\n" + | |
" <constructor-arg index=\"0\" type=\"javax.jms.ConnectionFactory\" ref=\"BEANPREFIX-activeMQ-springCachingConnectionFactory\"/>\n" + | |
" </bean>\n" + | |
" </x:resource>\n" + | |
" <x:resource id=\"BEANPREFIX-activeMQ-springCachingConnectionFactory\">\n" + | |
" <bean class=\"org.springframework.jms.connection.CachingConnectionFactory\">\n" + | |
" <constructor-arg index=\"0\" type=\"javax.jms.ConnectionFactory\" ref=\"BEANPREFIX-activeMQ-ConnectionFactory\"/>\n" + | |
" </bean>\n" + | |
" </x:resource>"; | |
public String getBrokerURL() { | |
return brokerURL; | |
} | |
public void setBrokerURL(String brokerURL) { | |
this.brokerURL = brokerURL; | |
} | |
public String getUserName() { | |
return userName; | |
} | |
public void setUserName(String userName) { | |
this.userName = userName; | |
} | |
public String getPassword() { | |
return password; | |
} | |
public void setPassword(String password) { | |
this.password = password; | |
} | |
public String getBeanPrefix() { | |
return beanPrefix; | |
} | |
public void setBeanPrefix(String beanPrefix) { | |
this.beanPrefix = beanPrefix; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment