[Red5] help with beans
Virgil Palitang
virgilp at megameeting.com
Wed Dec 31 12:42:15 PST 2008
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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://osflash.org/pipermail/red5_osflash.org/attachments/20081231/6a95d76b/attachment-0001.html>
More information about the Red5
mailing list