Results 1 to 4 of 4

Thread: Accessing the Service from Slice WAR

  1. #1
    Join Date
    Jul 2009
    Location
    Hyderabad India
    Posts
    56

    Default Accessing the Service from Slice WAR

    I am facing another issue with Slices.

    /WEB-INF/applicationContext.xml (which has Spring-DM’s <reference ... />) is not getting loaded even after having the following lines into the slice web.xml.

    Code:
    <context-param>
      <param-name>contextClass</param-name>
       <param-value> 
            com.springsource.server.web.dm.ServerOsgiBundleXmlWebApplicationContext
      </param-value>
    </context-param>
    
    <listener>
    <listener-class>
       org.springframework.web.context.ContextLoaderListener
    </listener-class>
    </listener>
    The same works fine for Host WAR.

    I am attaching the sample WARs for your reference.

    common.jar – Exposes OSGi service (<osgi:service …..>)

    travelAgent.war – Host WAR refers the service exposed by common.jar (<osgi:reference ….>) [works fine]

    flightReservation.war – Slice WAR refers the service exposed by common.jar (<osgi:reference ….>) [Not able to autowire beans defined in applicationContext.xml. It means that applicationContext.xml is not getting loaded. Gives error that “No matching bean found”]

    Please let me know if this is the correct way to refer an OSGi service from slice WAR?
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2005
    Location
    Philadelphia, PA, USA
    Posts
    228

    Default

    Change your config like this:

    web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
    	<servlet>
    		<servlet-name>flights</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                    /WEB-INF/applicationContext.xml,
                    /WEB-INF/flights-servlet.xml
                </param-value>
            </init-param>
            <init-param>
                <param-name>contextClass</param-name>
                <param-value>com.springsource.server.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
            </init-param>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>flights</servlet-name>
    		<url-pattern>*.action</url-pattern>
    	</servlet-mapping>
    
    </web-app>
    Thanks
    Dmitry

  3. #3
    Join Date
    Jul 2009
    Location
    Hyderabad India
    Posts
    56

    Default

    Thanks dsklyut. It worked.

    Is this understanding correct -

    Host can create Root WebApplicationContext using org.springframework.web.context.ContextLoaderListe ner and also servlet (dispatcher) WebApplicationContext and Host can access all the OSGi services and beans in Root WebApplicationContext.

    ServerOsgiBundleXmlWebApplicationContext for root WebApplicationContext is configured using -

    Code:
    <context-param>
      <param-name>contextClass</param-name>
      <param-value>
          com.springsource.server.web.dm.ServerOsgiBundleXmlWebApplicationContext
      </param-value>
    </context-param>
    
    <listener>
      <listener-class>
         org.springframework.web.context.ContextLoaderListener
     </listener-class>
    </listener>
    Whereas, a slice can only create WebApplicationContext for defined DispatcherServlet. And to create an OSGi enabled WebApplicationContext for slice we need to give the following -

    Code:
    <servlet>
      <servlet-name>dispatcherServlet</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <init-param>
        <param-name>contextClass</param-name>
        <param-value>
              com.springsource.server.web.dm.ServerOsgiBundleXmlWebApplicationContext
        </param-value>
      </init-param>
    </servlet>
    Regards,
    Pranav

  4. #4
    Join Date
    Dec 2005
    Location
    Philadelphia, PA, USA
    Posts
    228

    Default

    There is some ambiguity in the relationship between contexts in this case.

    You really do not want to see beans from the host in your slice context - there is no way to account for classloading in that case.
    Plus spring mvc will bind root web application context in the known location in the http context and slice will try to do the same.
    I guess you can try to change the location that root web app context is bound for the slice - but I don't think it is worth an effort unless you deploy multiple
    servlets in the slice.

    So it is better to have servlet only context in the slice and import services with osgi:reference in case you need services published by the host.

    Welcome to the bleeding edge
    Thanks
    Dmitry

Posting Permissions

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