Red5 dual spring contexts with Jax-ws

56 views
Skip to first unread message

pejot

unread,
May 21, 2013, 6:29:18 AM5/21/13
to red5in...@googlegroups.com
Hi,

I am trying to integrate Jersey JAX-WS with a Red5 Application. I am aware this might not be the best way to do it but this is a legacy app.

The problem I am facing is how to make the two context work with each other.

Normally you would just have a red5-web.xml and make the application start by the context loader of tomcat (I assume). 
The problem is, that when I need to register the context via web.xml to make jersey run I'm getting:


Exception in thread "Launcher:/app" java.lang.RuntimeException: Failed to load webapplication context class.
 at org
.red5.server.tomcat.TomcatLoader$1.run(TomcatLoader.java:531)
Caused by: java.lang.ClassNotFoundException: org/springframework/web/context/support/XmlWebApplicationContext
 at java
.lang.Class.forName0(Native Method)
 at java
.lang.Class.forName(Class.java:266)
 at org
.red5.server.tomcat.TomcatLoader$1.run(TomcatLoader.java:528)




the concerning part of web.xml itself is:

<listener>
 
<listener-class>
 org.springframework.web.context.ContextLoaderListener
 
</listener-class>
 
</listener>


 
<filter>
 
<filter-name>LoggerContextFilter</filter-name>
 
<filter-class>org.red5.logging.LoggerContextFilter</filter-class>
 
</filter>


 
<filter-mapping>
 
<filter-name>LoggerContextFilter</filter-name>
 
<url-pattern>/*</url-pattern>
 
</filter-mapping>


 
<servlet>
 
<servlet-name>fromrest</servlet-name>
 
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
 
<init-param>
 
<param-name>com.sun.jersey.config.property.packages</param-name>
 
<param-value>com.app</param-value>
 
</init-param>
 
<load-on-startup>0</load-on-startup>
 
</servlet>


 
<servlet-mapping>
 
<servlet-name>fromrest</servlet-name>
 
<url-pattern>/*</url-pattern>
 
</servlet-mapping>



The whole Idea is to make jersey rest classes auto configurable with beans that are normally used within the normal application context without using statics or singletons or stuff like that.

Would appreciate any hints.

cheers,
pejot

Mondain

unread,
May 21, 2013, 9:45:58 AM5/21/13
to red5in...@googlegroups.com
Red5 doesn't support the use of ContextLoaderListener due to the way it starts / runs. Anything you need will have to be setup in your red5-web.xml or you'll have to extend the Jersey servlet yourself to support grabbing the ApplicationContext as needed once everything has started up.

Paul



--
 
---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to red5interest...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
http://gregoire.org/
http://code.google.com/p/red5/

pejot

unread,
May 24, 2013, 8:20:29 AM5/24/13
to red5in...@googlegroups.com
Hi Paul,

thanks for your answer. I realize that's not super red5 related, but is there a way to programmatically start the jersey servlets from the red5 cotnext ?

Cheers,
Piotr

Mondain

unread,
May 24, 2013, 10:34:29 AM5/24/13
to red5in...@googlegroups.com
Off the top of my head, you'd probably have to do it from inside the TomcatLoader; it would be similar to how we start the RTMPT servlets.

Paul

pejot

unread,
May 24, 2013, 11:23:32 AM5/24/13
to red5in...@googlegroups.com
Will figure it out,

thanks Paul and enjoy the long weekend :)

Cheers,
Piotr

Michiel Trimpe

unread,
Jun 13, 2013, 8:50:10 AM6/13/13
to red5in...@googlegroups.com
It's probably too late for the OP, but I thought I'd share my setup once which turns the existing Red5 contexts into a 'normal' Spring context setup.

I've taken my existing code, stripped it from irrelevant details and attached the remaining the code to this email.

The main gist of it all is to specify a locatorFactorySelector in your web.xml and add the WarLoaderServlet as a listener like this:

    <context-param>
        <param-name>locatorFactorySelector</param-name>
        <param-value>classpath:/config/contextFactory.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.red5.server.war.WarLoaderServlet</listener-class>
    </listener>

And then specify all your spring context there like this:

    <bean name="default.context" class="org.springframework.context.support.ClassPathXmlApplicationContext">
        <constructor-arg>
           <list>
               <value>classpath:/red5/defaultContext.xml</value>
               <value>classpath:/red5/red5-common.xml</value>
               <value>classpath:/red5/red5-core.xml</value>
               <value>classpath:/red5/red5.xml</value>
               <value>classpath:/your/main/service/context/here.xml</value>
               <value>classpath:/config/default.xml</value>
           </list>
       </constructor-arg>
   </bean>

And place an empty beanRefContext.xml in the root of your classpath because the WarLoaderServlet expects it there.

The only disadvantage is that you'll need to manually keep your red5-*.xml's in sync since copying them directly from Red5's WAR distribution often breaks.

Cheers,

Michiel from VideoView.com

red5-spring-context.zip

pejot

unread,
Jun 13, 2013, 10:08:52 AM6/13/13
to red5in...@googlegroups.com
Hi Michiel,


thanks very much for the code snippets. The WAR deployment is secondary to me as there is not so much pressure not to restart the server, so think I can prepare something with ANT. 

Will definitely try this.


Thanks,
Piotr
Reply all
Reply to author
Forward
0 new messages