Results 1 to 8 of 8

Thread: how to expose sip/Servlet as Spring beans ?

  1. #1
    Join Date
    Mar 2007
    Posts
    7

    Default how to expose sip/Servlet as Spring beans ?

    I want to expose a sip/servlet as a bean managed by spring framwork.
    something like
    <beans>
    <bean id="mysipservlet" class="com.basic.mysipservlet">
    <property name="host" value="basic.org">
    </bean>
    <bean id="myhttpservlet" class="com.basic.myhttpservlet">
    <property name="sipservlet" ref="mysipservlet"/>
    </bean>
    </bean>

    the pb is the sip servlet instance is managed by the sip servlet container and not by spring, wich spring's interface have to be implemented by my sip servlet (like setBean("mysipservlet",this)) ? wich Spring API should be used to programmaticaly expose my sipservlet instance as a spring bean ?

    Best regards
    Bruno
    ps:my sipservlet use actualy spring beans via getBean in his init method.

  2. #2
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    So your goal is to remove the getBean() calls and make it Spring independent at the end?

    Jörg

  3. #3
    Join Date
    Mar 2007
    Posts
    7

    Default

    actually the Spring ContextListener is declare in my web.xml descriptor. it load all bean resources and specially a mysipservlet bean (spring create an instance). however this bean is already loaded by the sipservlet container and declare in an other descriptor (eg sip.xml) but Spring didn't see this instance and i am face to 2 instances of my sipservlet bean.
    so how spring could hook the sip/servlet container ? or how my sipservlet could be collaborate to spring container ?

    i am looking to Factory-bean and a getInstance() method to retrieve my sip servlet intance ....

    Bruno

  4. #4
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    I think you have two options. If you just need access to Spring application context in your Sip servlet you can use Spring's WebApplicationContextUtils to retrieve it.

    If you really need it the other way around (the Sip servlet in your Spring application context) then there are options as well. But it heavily depends on how you can retrieve this servlet at all. If you know how to access it in plain Java code, I'm sure you can replace it with Spring and make it somehow Spring managed or at least usable in your application context.

    Jörg

  5. #5
    Join Date
    Mar 2007
    Posts
    7

    Default

    thank jorg

    actualy from my sip servlet i use webapplicationcontextutils to retrieve spring beans.

    my pb is actually in the other way.My first implmentation was access to my sip servlet as a static way mysipservlet.link() so i think factory-bean way will be a good way to investigate (in my sip servlet i have a getInstance method wich return getServletContext.getAttribute("mysipservlet"), however, my sipservlet instance comes after spring initialisation so the getinstance fail due to a null pointer

    i continue to investigate

  6. #6
    Join Date
    Mar 2007
    Posts
    7

    Default

    hi jorg,

    my sipservlet singleton is created outside of Spring container but in the same servlet context (deployed in the same package). With the lazy-init option, my httpservlet can wait for mysipservlet init but when spring call mysipservlet 's getInstance method, i am face to a null pointer when i call getServletContext().
    myspiservlet environnement is based on ServletContext (eg lookup sipFactory) so my question is :"From Spring context, how to lookup ServletContext ? witch api provide getServletContext() ?

    best regards
    Bruno

  7. #7
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Hi Bruno,

    it's hard to give real advices without knowing the details. Especially as I haven't worked with sip yet.

    But to answer your specific question regarding access to the servlet context: Have a look for ServletContextAware or its alternatives ServletContextFactoryBean, ServletContextAttributeFactoryBean or ServletContextParameterFactoryBean.

    Hope this helps,

    Joerg

  8. #8
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    There seems to be another thread with a similar topic.

    Jörg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •