resource template icon

Writing a Custom Resource Template

Version: 17.07

Suppose you want to write a custom processing element or a connector and within that component, a complex set of resources are used. In this case, the user has to add each resource one by one into the XPML file. This is an arduous and an unintuitive task. In-order to overcome this problem, you can write a resource template.

Suppose if I were to write a JMS ingress and egress connectors which uses ActiveMQ and in-order to use those connectors, following resources should be present in the XPML file

<x:resource id="activeMq-ConnectionFactory">
    <beanclass="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="tcp://localhost:61616"/>
    </bean>
</x:resource>

<x:resource id="activeMq-jmxTxnManager">
    <bean class="org.springframework.jms.connection.JmsTransactionManager">
        <constructor-arg index="0" type="javax.jms.ConnectionFactory"
            ref="activeMq-springCachingConnectionFactory"/>
    </bean>
</x:resource>

<x:resource id="activeMq-ultraTxnmanager">
    <bean class="org.adroitlogic.x.base.trp.UltraPlatformTransactionManager">
        <property name="txnManager" ref="activeMq-jmxTxnManager"/>
    </bean>
</x:resource>

<x:resource id="activeMq-jmsTemplate">
    <bean class="org.springframework.jms.core.JmsTemplate">
        <constructor-arg index="0" type="javax.jms.ConnectionFactory"
         ref="activeMq-springCachingConnectionFactory"/>
    </bean>
</x:resource>

<x:resource id="activeMq-springCachingConnectionFactory">
    <bean class="org.springframework.jms.connection.CachingConnectionFactory">
         <constructor-arg index="0" type="javax.jms.ConnectionFactory"
                ref="activeMq-ConnectionFactory"/>
    </bean>
</x:resource>

Instead of asking the user to specify all the above resources, you could provide a template and obtain only the brokerURL from the user.

Below is a sample Java class for the resource template. The ResourceTemplate annotation indicates that this class is a resource template and it will be picked up by the UltraStudio.

The class MUST implement the XResourceTemplate interface and override the getXmlConfiguration() method. This method will be invoked by UltraStudio to obtain the string which should be appended to the XPML file. Hence, this string MUST return a complete resource configuration.

@ResourceTemplate(displayName = "Active MQ JMS")
public class ActiveMQJmsConfiguration implements XResourceTemplate {

    @Parameter(displayName = "Broker URL",
            description = "Specify the URL of the broker",
            inputType = InputType.TEXT_BOX,
            placeHolder = "tcp://localhost:61616")
    private String brokerURL = "localhost";


    @Override
    public String getXmlConfiguration() {return String.format(CONFIG, brokerURL);}


    public String getBrokerURL() {return brokerURL;}

    public void setBrokerURL(String brokerURL) {this.brokerURL = brokerURL;}


    private static final String CONFIG = "\n" +
            "   <x:resource id=\"activeMq-ConnectionFactory\">\n"+
            "      <bean class=\"org.apache.activemq.ActiveMQConnectionFactory\">\n"+
            "         <property name=\"brokerURL\" value=\"%s\"/>\n"+
            "     </bean>\n"
    // rest of the configuration

}

After compiling the template class, within the XPML design view, when you click the Custom template button, you will be presented with a dropdown which contains a list of resource template. After selecting the template we have created, you will be shown a modal as depicted in below figure.

resource template
In this topic
In this topic
Contact Us