Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Can I import and export services when I'm using Virgo Snaps?
Can I import and export services when I'm using Virgo Snaps? [message #786711] Mon, 30 January 2012 13:44 Go to next message
Gabriel Afonso is currently offline Gabriel Afonso
Messages: 23
Registered: December 2011
Junior Member
Hi I have a doubt I want to import and export services between two snaps, Is it possible?. And one Snap can import a service from other bundle? (this bundle is not a snap). Is it possible too?

Because I have One Host and Two Snaps, but this snaps can make an import or export services. I don't kwon Why.


Thanks.

[Updated on: Mon, 30 January 2012 14:18]

Report message to a moderator

Re: Can I import and export services when I'm using Virgo Snaps? [message #786743 is a reply to message #786711] Mon, 30 January 2012 14:25 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry Sklyut
Messages: 268
Registered: January 2010
Senior Member
Snaps is treated as a wab by virgo. The only difference is that start of the bundle is delayed until host wab is fully activated. There is not limitation on what services are shared between bundles.

Can you provide a more detailed example of the issue?
Are you packaging all shared interfaces in a shared bundle or Snap1 is packaging and exports interface of the service its want to publish and Snap2 does the same with its service?
Re: Can I import and export services when I'm using Virgo Snaps? [message #786757 is a reply to message #786743] Mon, 30 January 2012 14:44 Go to previous messageGo to next message
Gabriel Afonso is currently offline Gabriel Afonso
Messages: 23
Registered: December 2011
Junior Member
Hi, I have A host bundle and two children(C1 and C2). C1 provide a service and C2 is traying to consume this service, but in both cases, the applicationContext.xml isn't read (I guest) because the service is not publicated.

this is the code of the Host
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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" version="2.5">

    <display-name>H View</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext-business.xml
            /WEB-INF/security-app-context.xml
            /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>
    
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

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

    <filter>
        <filter-name>host-filter</filter-name>
        <filter-class>org.eclipse.virgo.snaps.core.SnapHostFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>host-filter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

<!-- CONFIGURE A PARENT APPLICATION CONTEXT -->

    <context-param>
        <param-name>contextClass</param-name>
        <param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
    </context-param>

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

  <!-- DISPATCHER SERVLET CONFIG -->
    <servlet>
        <servlet-name>hostcore</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>hostcore</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
</web-app>


the web.xml from C1

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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" version="2.5">

  <display-name>C navigation</display-name>

<!-- CONFIGURE A PARENT APPLICATION CONTEXT -->

  <context-param>
    <param-name>contextClass</param-name>
    <param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
  </context-param>

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

  <!-- DISPATCHER SERVLET CONFIG -->
  <servlet>
    <servlet-name>navigation</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>navigation</servlet-name>
    <url-pattern>/web/*</url-pattern>
  </servlet-mapping>

</web-app>


this is the web.xml code of C2
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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" version="2.5">

    <display-name>C template</display-name>

<!-- CONFIGURE A PARENT APPLICATION CONTEXT -->

    <context-param>
        <param-name>contextClass</param-name>
        <param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
    </context-param>

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

  <!-- DISPATCHER SERVLET CONFIG -->
    <servlet>
        <servlet-name>template</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>template</servlet-name>
        <url-pattern>/web/*</url-pattern>
    </servlet-mapping>

</web-app>


I traying to export a service from C1 in applicationContext.xml file
 <osgi:service id="comunicationTemplateService" interface="com.c1.admin.templateone.inter.ComunicationTemplate" ref="comunicationTemplate"/>


And I consume this service in C2
<osgi:list id="comunicationTemplate"  interface="com.divux.onex.admin.templateone.inter.ComunicationTemplate"/>


But there is a problem because no service is exported and no service is Consumed
Re: Can I import and export services when I'm using Virgo Snaps? [message #786766 is a reply to message #786757] Mon, 30 January 2012 14:56 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry Sklyut
Messages: 268
Registered: January 2010
Senior Member
Ok - you do notice that C1 export uses "com.c1.admin.templateone.inter.ComunicationTemplate" interface and C2 trying to import using "com.divux.onex.admin.templateone.inter.ComunicationTemplate"

Interfaces do not match.

Dmitry

p.s. I hope this is a problem. You also might want to scope your child appContext to the dispatcher servlet and remove ContextLoaderListener from child snaps.
Re: Can I import and export services when I'm using Virgo Snaps? [message #973359 is a reply to message #786766] Tue, 06 November 2012 04:11 Go to previous messageGo to next message
Markus Schmailzl is currently offline Markus Schmailzl
Messages: 6
Registered: November 2012
Junior Member
Hi,

I have basically the same problem and cant get it running. I want to create a pluggable Webapplication where services can be added at runtime by a new snap and used by another one.

In my current web.xml i try to load the context-file /WEB-INF/osgi-context.xml where i instanciate a bean for the use within the snap C1 and for the export to other snaps. But I think that the context-file is not loaded by the ContextLoaderListener.


What I am confused about in the example of the posts before and in generel is whether the snaps (e.g. C1 that is exporting a service) uses their own ServerOsgiBundleXmlWebApplicationContext configured in an xml-file within the snap or whether they are obtaining one from the host?

Another question i have is whether the org.springframework.web.context.ContextLoaderListener even works in a snaps web.xml because i have read that in version 3.0.? this tag would not be processed.

I would really apprecitate it if someone could help me out

thanks markus

osgi-context.xml of snap C1
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans ...>
	
	<beans:bean id="appManager" class="de.project.webapp.plugins.base.AppManagerImpl"></beans:bean>	
	<service ref="appManager" interface="de.project.webapp.plugins.base.services.AppManager" />		
</beans:beans>


web.xml of snap C1
<?xml version="1.0" encoding="UTF-8"?>
<web-app ...

  <display-name>Base</display-name>  
  
  <context-param>
		<param-name>contextClass</param-name>
		<param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
	</context-param>
  
  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>           
            /WEB-INF/osgi-context.xml
        </param-value>
    </context-param>	
	
	
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <servlet>
    <servlet-name>base</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>   
		<init-param>
			<param-name>contextClass</param-name>
			<param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
		</init-param>  
		 <load-on-startup>1</load-on-startup> 
  </servlet>
  
  <servlet-mapping>
    <servlet-name>base</servlet-name>
    <url-pattern>/web/*</url-pattern>
  </servlet-mapping>
</web-app>


Re: Can I import and export services when I'm using Virgo Snaps? [message #974685 is a reply to message #973359] Wed, 07 November 2012 03:47 Go to previous message
Markus Schmailzl is currently offline Markus Schmailzl
Messages: 6
Registered: November 2012
Junior Member
Hello,

I have found a solution to my problem by now. I have a Snap called de.project.bai.webapp.plugins.deviceManagement. The Snap uses
the two contexts /WEB-INF/webapp-context.xml and /WEB-INF/deviceManagement-servlet.xml.
In the Servlet there is a bean instanciated which is exported as an osgi service in the webapp-context.
In other snaps it is possible to use this service by importing it via <osgi:reference.

The host itself doenst provide another context beside the standard one.

Maybe someone can tell me whether this solution is a practical one for my use case and if I could run into any problems.
The use case is a pluggable webplattform where users can provide there own snaps. A snap should be able to provide services to other snaps and use services from snaps as well as providing some dynamic webpages with jsp.

Thanks

web.xml of Snap deviceManagement
<?xml ...>
  <display-name>Base</display-name>  
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <servlet>
    <servlet-name>base</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>   
		
		<init-param>
			<param-name>contextClass</param-name>
			<param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>			
		</init-param>  
		<init-param>
			<param-name>contextConfigLocation</param-name>
       	 	<param-value>           
            /WEB-INF/webapp-context.xml
            /WEB-INF/deviceManagement-servlet.xml                       
        	</param-value>
		</init-param>			
		 <load-on-startup>1</load-on-startup> 
  </servlet>
  
  <servlet-mapping>
    <servlet-name>base</servlet-name>
    <url-pattern>/web/*</url-pattern>
  </servlet-mapping>
</web-app>


webapp-contxt.xml from deviceManagement
<beans ...>		
		<osgi:service ref="deviceManager" interface="de.project.bai.webapp.plugins.deviceManagement.services.DeviceManager"></osgi:service>
	
</beans>



deviceManagement-servlet.xml from deviceManagement

<?xml version="1.0" encoding="UTF-8"?>
<beans ...>

	<context:component-scan base-package="de.project.bai.webapp.plugins.deviceManagement" />
	
	<bean id="deviceManager" class="de.project.bai.webapp.plugins.deviceManagement.DeviceManagerImpl"/>
</beans>
Previous Topic:Remote debug of spring classes
Next Topic:how to prevent double loading of blueprint extender (one loaded in kernel and one in user)
Goto Forum:
  


Current Time: Fri Apr 18 10:14:34 EDT 2014

Powered by FUDForum. Page generated in 0.01941 seconds