I recall seeing a question from a user about accessing servlet parameters from their Red5 application, so I have created a small demo which shows how to not only access sevlet parameters from Red5 apps but the other way around as well.
Retrieve a servlet context parameter from inside a Red5 application (AppContext -> Servlet)
1. Grab a reference to the application context
ApplicationContext appCtx = getContext().getApplicationContext();
2. Get the servlet context
ServletContext ctx = ((XmlWebApplicationContext) appCtx).getServletContext();
3. Get the context parameter
String param = ctx.getInitParameter("myparam");
Retrieve an application context parameter from a inside a servlet (Servlet -> AppContext)
1. Get the servlet context
ServletContext ctx = getServletContext();
2. Grab a reference to the application context
ApplicationContext appCtx = ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
3. Get the bean holding the parameter
MyBean bean = appCtx.getBean("mybean"); String param = bean.getParameter("myparam");
Sample project files: parameterdemo.zip
Instructions:
Unzip the demo and create a new directory named parameterdemo in your red5/webapps directory, then restart your server.
Open your browser and go here: http://localhost/parameterdemo/myservlet?paramName=myparam
You should see "Hello World"
To test the Red5 application you will need to create a Flex or Flash application that connects to: rtmp://localhost/parameterdemo
Then simply call "getParameter" passing a parameter name you want the value of. The name must match a context param in the web.xml file.
�
Tags: context, param, property, servlet, spring, webapp