Failed to get ofla Ruby example work on red5 >= 1.0.2 #86

Open
qqshfox opened this Issue May 27, 2015 · 1 comment

Projects

None yet

2 participants

@qqshfox
qqshfox commented May 27, 2015

I'm trying to play with the ofla demo. The java version and the python work without any problem. Then I want to run the ruby example (I've replaced org.red5.server.api.IScopeHandler with org.red5.server.api.scope.IScopeHandler in webapps/oflaDemo/WEB-INF/red5-web.xml), I got these errors:

(PS. The same example worked on both 1.0.0 and 1.0.1. I tried removing all the libs in 1.0.1 and replacing them with the ones from 1.0.2 except quartz. It still worked. Then I tried to do the same thing to plugins. But I can't get it work since I don't know how to upgrade the entire project to tomcat 7 from 6.)

Context init...
Logger name for context: oflaDemo
五月 27, 2015 12:37:58 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-nio-0.0.0.0-5080"]
[INFO] [main] org.apache.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-0.0.0.0-5080"]
[INFO] [main] org.red5.server.tomcat.TomcatLoader - Dedicated RTMPT server configuration was not specified
[INFO] [main] org.red5.server.ContextLoader - JEE server was found: TomcatLoader [serviceEngineName=red5Engine]
Bootstrap complete
Bootstrap exit
[INFO] [Launcher:/oflaDemo] org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Wed May 27 12:37:58 CST 2015]; parent: org.springframework.context.support.FileSystemXmlApplicationContext@416c58f5
[INFO] [Launcher:/oflaDemo] org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/red5-web.xml]
[INFO] [Launcher:/oflaDemo] org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from ServletContext resource [/WEB-INF/red5-web.properties]
[INFO] [Launcher:/oflaDemo] org.red5.server.Context - Setting parent bean factory as core
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(String.java:646)
    at org.jruby.org.objectweb.asm.Frame.a(Unknown Source)
    at org.jruby.org.objectweb.asm.MethodWriter.visitTypeInsn(Unknown Source)
    at org.jruby.compiler.impl.SkinnyMethodAdapter.checkcast(SkinnyMethodAdapter.java:525)
    at org.jruby.internal.runtime.methods.InvocationMethodFactory.getCompiledMethodOffline(InvocationMethodFactory.java:484)
    at org.jruby.internal.runtime.methods.InvocationMethodFactory.getCompiledMethod(InvocationMethodFactory.java:253)
    at org.jruby.javasupport.util.RuntimeHelpers.constructNormalMethod(RuntimeHelpers.java:1916)
    at org.jruby.javasupport.util.RuntimeHelpers.def(RuntimeHelpers.java:355)
    at .class_1$RUBY$Application(:72)
    at .__file__(:19)
    at .load()
    at org.jruby.Ruby.runScript(Ruby.java:697)
    at org.jruby.Ruby.runScript(Ruby.java:690)
    at org.jruby.Ruby.runNormally(Ruby.java:597)
    at org.springframework.scripting.jruby.JRubyScriptUtils.createJRubyObject(JRubyScriptUtils.java:82)
    at org.springframework.scripting.jruby.JRubyScriptFactory.getScriptedObject(JRubyScriptFactory.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.scripting.support.ScriptFactoryPostProcessor.postProcessBeforeInstantiation(ScriptFactoryPostProcessor.java:337)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:958)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:930)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:465)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.red5.server.tomcat.TomcatLoader$1.run(TomcatLoader.java:484)
Exception in thread "Launcher:/oflaDemo" java.lang.RuntimeException: Failed to load webapplication context class
    at org.red5.server.tomcat.TomcatLoader$1.run(TomcatLoader.java:512)
Caused by: org.springframework.beans.factory.BeanCreationException: 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]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scriptedObject.web.handler' defined in ServletContext resource [/WEB-INF/red5-web.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.Object org.springframework.scripting.jruby.JRubyScriptFactory.getScriptedObject(org.springframework.scripting.ScriptSource,java.lang.Class[]) throws java.io.IOException,org.springframework.scripting.ScriptCompilationException] threw exception; nested exception is org.springframework.scripting.ScriptCompilationException: Could not compile script [class path resource [main.rb]]: String index out of range: 0; nested exception is org.jruby.exceptions.RaiseException: (LoadError) String index out of range: 0
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)


    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.red5.server.tomcat.TomcatLoader$1.run(TomcatLoader.java:484)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'web.handler' defined in ServletContext resource [/WEB-INF/red5-web.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scriptedObject.web.handler' defined in ServletContext resource [/WEB-INF/red5-web.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.Object org.springframework.scripting.jruby.JRubyScriptFactory.getScriptedObject(org.springframework.scripting.ScriptSource,java.lang.Class[]) throws java.io.IOException,org.springframework.scripting.ScriptCompilationException] threw exception; nested exception is org.springframework.scripting.ScriptCompilationException: Could not compile script [class path resource [main.rb]]: String index out of range: 0; nested exception is org.jruby.exceptions.RaiseException: (LoadError) String index out of range: 0
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:471)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    ... 13 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scriptedObject.web.handler' defined in ServletContext resource [/WEB-INF/red5-web.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.Object org.springframework.scripting.jruby.JRubyScriptFactory.getScriptedObject(org.springframework.scripting.ScriptSource,java.lang.Class[]) throws java.io.IOException,org.springframework.scripting.ScriptCompilationException] threw exception; nested exception is org.springframework.scripting.ScriptCompilationException: Could not compile script [class path resource [main.rb]]: String index out of range: 0; nested exception is org.jruby.exceptions.RaiseException: (LoadError) String index out of range: 0
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:597)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.scripting.support.ScriptFactoryPostProcessor.postProcessBeforeInstantiation(ScriptFactoryPostProcessor.java:337)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:958)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:930)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:465)
    ... 18 more
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public java.lang.Object org.springframework.scripting.jruby.JRubyScriptFactory.getScriptedObject(org.springframework.scripting.ScriptSource,java.lang.Class[]) throws java.io.IOException,org.springframework.scripting.ScriptCompilationException] threw exception; nested exception is org.springframework.scripting.ScriptCompilationException: Could not compile script [class path resource [main.rb]]: String index out of range: 0; nested exception is org.jruby.exceptions.RaiseException: (LoadError) String index out of range: 0
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
    ... 30 more
Caused by: org.springframework.scripting.ScriptCompilationException: Could not compile script [class path resource [main.rb]]: String index out of range: 0; nested exception is org.jruby.exceptions.RaiseException: (LoadError) String index out of range: 0
    at org.springframework.scripting.jruby.JRubyScriptFactory.getScriptedObject(JRubyScriptFactory.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
    ... 31 more
Caused by: org.jruby.exceptions.RaiseException: (LoadError) String index out of range: 0

The ruby example

# JRuby - style

require 'java'
module RedFive
  include_package "org.red5.server.api"
  include_package "org.red5.server.api.scope"
  include_package "org.red5.server.api.stream"
  include_package "org.red5.server.api.stream.support"
  include_package "org.red5.server.adapter"
  include_package "org.red5.server.stream"
end

#
# application.rb - a translation into Ruby of the ofla demo application, a red5 example.
#
# @author Paul Gregoire
#

class Application < RedFive::ApplicationAdapter

  attr_reader :appScope, :serverStream
  attr_writer :appScope, :serverStream

  def initialize
    #call super to init the superclass, in this case a Java class
    super
    puts "Initializing ruby application"
  end

  def appStart(app)
    puts "Ruby appStart"
    @appScope = app
    return true
  end

  def appConnect(conn, params)
    puts "Ruby appConnect"
    measureBandwidth(conn)
    puts "Ruby appConnect 2"
    if conn.instance_of?(RedFive::IStreamCapableConnection)
      puts "Got stream capable connection"
      sbc = RedFive::SimpleBandwidthConfigure.new
      sbc.setMaxBurst(8388608)
      sbc.setBurst(8388608)
      sbc.setOverallBandwidth(8388608)
      conn.setBandwidthConfigure(sbc)
    end
    return super
  end

  def appDisconnect(conn)
    puts "Ruby appDisconnect"
    if appScope == conn.getScope && @serverStream != nil
      @serverStream.close
    end
    super
  end

  def toString
    return "Ruby toString"
  end

  def setScriptContext(scriptContext)
    puts "Ruby application setScriptContext"
  end

  def method_missing(m, *args)
    super unless @value.respond_to?(m)
    return @value.send(m, *args)
  end

end

I tried to replace this file with:

puts 'init'

class Foo
end

def baz
end

I got this error:

init
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(String.java:646)
    at org.jruby.org.objectweb.asm.Frame.a(Unknown Source)
    at org.jruby.org.objectweb.asm.MethodWriter.visitTypeInsn(Unknown Source)
    at org.jruby.compiler.impl.SkinnyMethodAdapter.checkcast(SkinnyMethodAdapter.java:525)
    at org.jruby.internal.runtime.methods.InvocationMethodFactory.getCompiledMethodOffline(InvocationMethodFactory.java:484)
    at org.jruby.internal.runtime.methods.InvocationMethodFactory.getCompiledMethod(InvocationMethodFactory.java:253)
    at org.jruby.javasupport.util.RuntimeHelpers.constructNormalMethod(RuntimeHelpers.java:1916)
    at org.jruby.javasupport.util.RuntimeHelpers.def(RuntimeHelpers.java:355)
    at .__file__(:6)
    at .load()

it seems that the jruby vm works, it can print the text successfully. But it can't understand the function definition syntax. I tried upgrade the jruby to 1.7.20. It didn't work, either. I tried running the script directly using the jruby jar, no error happened.

$ java -jar lib/jruby-1.6.8.jar webapps/oflaDemo/WEB-INF/classes/main.rb
init

I really don't know where I am going wrong. I've uploaded the example to https://github.com/qqshfox/red5-1.0.5-ruby.
It would be great if anyone can guide me with this. Thank you!

@mondain
Member
mondain commented Jul 22, 2015

Leaving a note about JRuby so it doesn't get lost by the time I get back to this issue: http://blog.jruby.org/2015/07/jruby_9000/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment