Passing configuration parameters into Red5 application

 

Passing parameters through red5-web.properties

In this second type of method, we consider passing val;ues through the red5-web.properties file, taking help of red5-web.xml.

Consider the same example as above with the setter function expecting value from outside. So we will store the value in red5-web.properties file first as shown below.

webapp.contextPath=/myapp
webapp.virtualHosts=localhost, 127.0.0.1, 192.168.1.2
webapp.database=mydb.sqlite

Next thing is to tell red5-web.xml to pull variable value from red5-web.properties. Notice below how the application’s handler bean is instructed to do so.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!--
Defines a properties file for dereferencing variables
-->
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/red5-web.properties" />
</bean>

<!--
Defines the web context
-->
<bean id="web.context" class="org.red5.server.Context"
    autowire="byType" />

<!--
Defines the web scopes
-->
<bean id="web.scope" class="org.red5.server.WebScope"
     init-method="register">
    <property name="server" ref="red5.server" />
    <property name="parent" ref="global.scope" />
    <property name="context" ref="web.context" />
    <property name="handler" ref="web.handler" />
    <property name="contextPath" value="${webapp.contextPath}" />
    <property name="virtualHosts" value="${webapp.virtualHosts}" />
</bean>

<!--
Defines the web handler which acts as an applications endpoint
-->
<bean id="web.handler" class="org.red5.core.Application" singleton="true">
    <property name="database" value="${webapp.database}"/>
</bean>

</beans>

This is how the red5-web.xml inserts data from red5-web.properties into the bean definition.

<bean id="web.handler" class="org.red5.core.Application" singleton="true">
    <property name="database" value="${webapp.database}"/>
</bean>

If you want to pass parameters into a Red5 service handler class of your own, then the method is similar. The service handler must have a bean definition in red5-web.xml and the property must be passed in as shown for the application bean.

<bean id="ServiceClass.service" class="path.to.my.ServiceClass" singleton="true">
    <property name="propertyname" value="somevalue"/>  
</bean>

Special note:

You can pass a reference to your application adapter into your service class by using the syntax shown below.

<bean id="ServiceClass.service" class="path.to.my.ServiceClass" singleton="true">
    <property name="application" ref="web.handler"/>   
</bean>

And to receive this value in your service class, you must have a setter function setup as shown below:

protected Application application;
public void setApplication(Application app)
{
    this.application = app;
}

If you have trouble getting emails from this domain, please check your email spam & mark messages from flashvisions.com as 'Not Spam'

Comments are closed