[Red5] help with beans

Virgil Palitang virgilp at megameeting.com
Wed Dec 31 14:17:58 PST 2008


That did it.

I knew there was something I was overlooking. 

 

TK rox.

 

________________________________

From: red5-bounces at osflash.org [mailto:red5-bounces at osflash.org] On
Behalf Of Tyler Kocheran
Sent: Wednesday, December 31, 2008 1:43 PM
To: red5 at osflash.org
Subject: Re: [Red5] help with beans

 

I think the following line is creating your problems:

private DriverManagerDataSource ds=(DriverManagerDataSource)
Red5.getConnectionLocal().getScope().getContext().getBean("myDataSource"
);

At startup time, how can you get a connection to a nonexistent client?
;)
Rather than doing that, you should try to run the assignment in the
appStart event listener method. It will give you the same effect. 
You're lucky you're learning all this on 0.8+, I had to learn on 0.7,
which eats all startup exceptions... no fun at all. Hope this helps you
out!

On Wed, Dec 31, 2008 at 12:42 PM, Virgil Palitang
<virgilp at megameeting.com> wrote:

Beans beans beans beans beans!

 

The "Red5 and Spring JDBC"
(http://jira.red5.org/confluence/display/docs/Red5+and+Spring+JDBC)
example isn't working for me. I am attempting to create an extremely
simple version just to verify db connectivity. I'm using Eclipse 3.4.1,
Red5 0.8, on winXP.

 

I have no problems creating an app that has the jdbc driver compiled
into it, however the goal was to get an app that could be a little more
flexible and possibly utilize dbcp.

 

Eclipse builds the app without complaints, but running it on red 5
yields the following error:

2008-12-31 11:38:01,880 [main] ERROR org.red5.server.tomcat.TomcatLoader
- Error setting up context: /springTest due to: Error creating bean with
name 'web.scope' defined in ServletContext resource
[/WEB-INF/red5-web.xml]: Cannot resolve reference to bean 'web.handler'
while setting bean property 'handler'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'web.handler' defined in ServletContext resource
[/WEB-INF/red5-web.xml]: Instantiation of bean failed; nested exception
is org.springframework.beans.BeanInstantiationException: Could not
instantiate bean class [org.red5.core.Application]: Constructor threw
exception; nested exception is java.lang.NullPointerException

 

Included jars:

commons-dbcp-1.2.2.jar

mysql-connector-java-5.1.7-bin.jar

org.springframework.bundle.spring_2.5.6.v200808081800.jar

slf4j-api-1.5.3.jar

spring-jdbc.jar

 

Contents of Application.java:

package org.red5.core;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

import org.red5.server.api.IConnection;

import org.red5.server.api.IScope;

import org.red5.server.api.Red5;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.jdbc.datasource.DriverManagerDataSource;

 

import org.red5.server.adapter.ApplicationAdapter;

 

public class Application extends ApplicationAdapter {

       private Connection con;

       protected static Logger
log=LoggerFactory.getLogger(Application.class);

       private DriverManagerDataSource ds=(DriverManagerDataSource)
Red5.getConnectionLocal().getScope().getContext().getBean("myDataSource"
);

 

       public boolean connect2db() {

              boolean ok=false;

              if (con!=null) {

                     return true;

              }

              try {

                     // con=ds.createConnection();

                     con=ds.getConnection();

                     if (con!=null) { ok=true; }

                     log.debug("Trying to connect.");

              } catch (SQLException e){

                     e.printStackTrace(System.err);

                     log.debug("connect2db() threw
exception:\n"+e.getMessage());

              }

 

              return ok;

       }

 

       @Override

       public boolean connect(IConnection conn, IScope scope, Object[]
params){

              connect2db();

              return true;

       }

 

       public String getTestData(int uid) {

              Statement stmt=null;

              ResultSet results=null;

              String sql="select name, status from mydemo where
uid="+uid;

              String out="";

              log.debug("in getTestData() function");

              if (!connect2db()){

                     out="Not Connected";

                     return out;

              }

              try {

                     stmt=con.createStatement();

                     if (stmt.execute(sql)) {

                            results=stmt.getResultSet();

                     }

                     while(results.next()) {

                           out+="Name: " + results.getString("name")
+"\n";

                           out+="Status: " + results.getString("status")
+"\n";

                           out+="\n";

                     }

              }

              catch (SQLException ex){

                     log.debug("function getTestData threw
exception:\n"+ex.getMessage());

              }

              return out;

       }

}

 

Contents of red5-web.xml:

<?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.PropertyPlaceholderConfi
gurer">

           <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" />

       <!--

       Defines the data source

        -->

       <bean id="myDataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

              <property name="driverClassName"
value="com.mysql.jdbc.Driver"></property>

              <property name="url"
value="jdbc:mysql://192.168.0.8/test"></property>

              <property name="username" value="dbuser"></property>

              <property name="password" value="blahblah"></property>

              <property name="poolPreparedStatements"
value="true"></property>

              <property name="maxActive" value="10"></property>

              <property name="maxIdle" value="5"></property>

       </bean>

</beans>

 

Anyone have any insight on how to get this working?

 

 

P.S. Happy New Year!


_______________________________________________
Red5 mailing list
Red5 at osflash.org
http://osflash.org/mailman/listinfo/red5_osflash.org




-- 
And do this, knowing the time, that now it is high time to awake out of
sleep;
for now our salvation is nearer than when we first believed.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://osflash.org/pipermail/red5_osflash.org/attachments/20081231/c5e8a4d4/attachment-0001.html>


More information about the Red5 mailing list