Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Snaps Host using Spring(Using Spring MVC in Snaps Host)
Snaps Host using Spring [message #941489] Fri, 12 October 2012 15:21 Go to next message
Graeme Dougal is currently offline Graeme DougalFriend
Messages: 8
Registered: September 2012
Junior Member
Hi

I'm currently looking at OSGI with the view to implementing an OSGI based application framework.

Got most things working but struggling to configure snaps. Specifically I want to have the snaps host as a Spring MVC web bundle so it can handle login, home page etc.. I then want specific spring mvc snaps to provide component level functionality within the application.

I've got the host and snap deployed and the logs all look good in terms of the smap being joined to the host and I can see the link to my snap in the host when displaying the welcome page from the host that uses the <snaps: tag to provide a link to the snap.

However, this link always returns a 404, looking at the logs it seems as though the MVC side of the snap is not being wired up correctly and the dispatcher servlet is not picking up the url.

Cant seem to find any examples anywhere of using Spring MVC in the snap host - any ideas anyone ?

Cheers
Graeme
Re: Snaps Host using Spring [message #947692 is a reply to message #941489] Wed, 17 October 2012 10:21 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Hi,

This should work just fine but I would need to see the web.xml from the host, the manifest from the snap and the link that is hitting a 404 in order to diagnose it properly. Please check that the Snaps filter is defined before the dispatcher servlet as ordering matters in a web.xml. Also check that the link is in the format of '/hostContextPath/filterPath/snapContextPath' in order to get picked up by the filter and matched to the snap.

Thanks Chris.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Snaps Host using Spring [message #963036 is a reply to message #947692] Mon, 29 October 2012 14:24 Go to previous messageGo to next message
Graeme Dougal is currently offline Graeme DougalFriend
Messages: 8
Registered: September 2012
Junior Member
Chris

Thanks for the reply, apologies for the delayed response, have been away from this for a while.

As requested here are the followning you've asked to see

(1) Host web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--links omitted for post -->
  <display-name>Dealing Framework - Web</display-name>

	<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>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

<!-- 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>dealing-framework</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>dealing-framework</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

</web-app>


(2) Snap Manifest
Manifest-Version: 1.0
Built-By: n428655
Build-Jdk: 1.6.0_35
Created-By: Maven Integration for Eclipse
Export-Package: com.iag.globaldealing.controller;version="1.0.0";uses:
 ="com.iag.globaldealing.web.controller,com.iag.globaldealing.web.form
 ,org.springframework.beans.factory.annotation,org.springframework.ste
 reotype,org.springframework.ui,org.springframework.web.bind.annotation"
Tool: Bundlor 1.0.0.RELEASE
Bundle-Name: Dealing Framework Web Snap
Import-Bundle: com.springsource.org.apache.taglibs.standard;version="[
 1.1.2,2.0)",org.eclipse.virgo.snaps.api;version="[3.5.0.RELEASE,3.5.0
 .RELEASE]"
Bundle-Version: 1.0.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: dealing-web-snap
Import-Package: com.iag.globaldealing.framework.model.dto,com.iag.glob
 aldealing.framework.service.api,com.iag.globaldealing.web.controller,
 com.iag.globaldealing.web.form,javax.servlet.jsp.jstl.core;version="[
 1.2.0,2.0.0)",org.eclipse.virgo.snaps.core;version="[3.5.0.RELEASE,3.
 5.0.RELEASE]",org.eclipse.virgo.web.dm;version="[3.0.0, 4.0.0)",org.s
 pringframework.beans.factory.annotation,org.springframework.context.c
 onfig;version="[3.1.1.RELEASE, 3.1.1.RELEASE]",org.springframework.st
 ereotype,org.springframework.ui,org.springframework.web.bind.annotati
 on,org.springframework.web.context;version="[3.1.1.RELEASE, 3.1.1.REL
 EASE]",org.springframework.web.servlet;version="[3.1.1.RELEASE, 3.1.1
 .RELEASE]",org.springframework.web.servlet.mvc.annotation,org.springf
 ramework.web.servlet.tags;version="[3.1.1.RELEASE, 3.1.1.RELEASE]",or
 g.springframework.web.servlet.tags.form;version="[3.1.1.RELEASE, 3.1.
 1.RELEASE]",org.springframework.web.servlet.view
Snap-Host: dealing-web;version="[1.0.0, 1.0.0]"
Snap-ContextPath: /dealing-snap


(3) The link from the host to the snap
localhost:8080/dealing-framework/dealing-snap/secure/dealing/ListDealElements.do

Cheers
Graeme
Re: Snaps Host using Spring [message #968575 is a reply to message #963036] Fri, 02 November 2012 15:11 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Hi,

That all looks good to me. Just had a read of the Servlet spec and it seems that '/' will be classed as a default mapping and the '*.do' extension mapping will always win out. If you change the snaps filter to '/*' it will always win out and then the dispatcher servlet in the host will never get a look in. '/*' would be considered a prefix mapping by the servlet spec and win over the extension mapping so this is also not useful. I don't believe it is possible to try the filter and if that fails to then try the dispatcher servlet without coding something bespoke up. If possible it might be easier to change the filter to something like '/snaps/*' to give a clearly different path to the one the hosts dispatcher servlet is using.

In short, I think this is an issue with the Servlet spec and Spring MVC and Snaps are working as designed.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Snaps Host using Spring [message #971980 is a reply to message #968575] Mon, 05 November 2012 09:08 Go to previous messageGo to next message
Graeme Dougal is currently offline Graeme DougalFriend
Messages: 8
Registered: September 2012
Junior Member
Chris

Thanks for the update. Still struggling to get this to work...

Can you confirm that it is possible to have a spring mvc host and spring mvc snaps ?

Also, if it is possible, would be really useful to have a working exmaple to follow as I beleive this will be a fairly standard use case of what people will want to do with snaps.

Cheers
Graeme
Re: Snaps Host using Spring [message #986847 is a reply to message #971980] Thu, 22 November 2012 00:13 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Hi,

That could be the problem, remember that each Host and all its Snaps share the same Servlet context. Having filters with the same name could cause problems. It should work just fine having Spring MVC in both the host and its snaps just remember that it all ends up in the context. I can't remember what the 'Animals' example that ships with Snaps uses but that is the only example we have at the moment.

I've looked at this a couple of times now and I'm running out of ideas. I've asked another committer to have a look, he might be able to shed some light.

Chris.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Snaps Host using Spring [message #986848 is a reply to message #986847] Thu, 22 November 2012 00:49 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Hi,

Could you provide the Snaps web.xml as well please.

Thanks, Chris.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Snaps Host using Spring [message #986945 is a reply to message #986848] Thu, 22 November 2012 13:26 Go to previous messageGo to next message
Graeme Dougal is currently offline Graeme DougalFriend
Messages: 8
Registered: September 2012
Junior Member
In the animal snaps example, the host is a standard web application and one of the snaps is a spring mvc web app.

web.xml from snap

<?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>Dealing Framework - Web Snap</display-name>

<welcome-file-list>
<welcome-file>welcome-file>index.html</welcome-file>
</welcome-file-list>

<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>dealing-snap</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>dealing-snap</servlet-name>
<url-pattern>/snaps/*.do</url-pattern>
</servlet-mapping>

</web-app>

[Updated on: Thu, 22 November 2012 13:27]

Report message to a moderator

Re: Snaps Host using Spring [message #987002 is a reply to message #986945] Thu, 22 November 2012 18:42 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
Graeme,

This is actually a fault of ours. We should have explained it in the docs better.

Because snap and host are sharing the same servlet context, by deploying another "ROOT" web app context in the snap you are overriding the root context from the host.

Try this in the snap:

<servlet>
        <servlet-name>snap</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/spring/servlet/*.xml
            </param-value>
        </init-param>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>


This way you are localizing snap context to the "front servlet" of the snap and do not impact the host config.

Let us know if that works for you. If you are using spring-security - there is another little trick that needs to be done. But first let us get you working with the plain dispatch.

Regards,

Dmitry
Re: Snaps Host using Spring [message #987087 is a reply to message #987002] Fri, 23 November 2012 11:44 Go to previous messageGo to next message
Graeme Dougal is currently offline Graeme DougalFriend
Messages: 8
Registered: September 2012
Junior Member
Dimitry

Hi, thanks for the response... Ive tried your suggestion above and still no luck Sad

I've cut down the project to an absolute minimum - is there any chance I can send you what I've got to have a look at in case Im missing something simple ?

I can hit the controller in the snap host - localhost:8080/snaps-host/Welcome.do
I can generate a link to the snap in the page returned from the controller - localhost:8080/snaps-host/snaps-test/SnapTest.do
That returns 404
I can hit an html page on the snap-test - localhost:8080/snaps-host/snaps-test/index.html

Feels very close..


Cheers
Graeme
Re: Snaps Host using Spring [message #987114 is a reply to message #987087] Fri, 23 November 2012 15:05 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
I think you are missing snap-host-servlet.xml loading in the snap. i.e.

<param-value>
                /WEB-INF/applicationContext.xml
            </param-value>


should be
<param-value>
                /WEB-INF/applicationContext.xml,
                /WEB-INF/snap-host-servlet.xml
</param-value>

[Updated on: Fri, 23 November 2012 15:06]

Report message to a moderator

Re: Snaps Host using Spring [message #990315 is a reply to message #987114] Tue, 11 December 2012 19:36 Go to previous messageGo to next message
shiv khillar is currently offline shiv khillarFriend
Messages: 2
Registered: December 2012
Junior Member
Hi,
I have created a sample app with one host bundle and snap bundle.
Uploading the same for your reference.

Thanks
Shiv
Re: Snaps Host using Spring [message #990420 is a reply to message #990315] Wed, 12 December 2012 12:41 Go to previous messageGo to next message
Graeme Dougal is currently offline Graeme DougalFriend
Messages: 8
Registered: September 2012
Junior Member
Shiv

Thanks for the update - and the sample project. Smile

I'm still unable to get this to work - I cant get your sample to build and deploy so created my own project based on your project setup.. unfortunately this still doesnt quite work. I can hit a controller in the host but when I try to hit a controller in the snap I just get a 404

I'm attaching the example project and would appreciate it if you could have a quick look and see if I've missed something ?

Cheers
Graeme
Re: Snaps Host using Spring [message #991428 is a reply to message #990420] Wed, 19 December 2012 04:11 Go to previous message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
Graeme, I looked over the config files quickly for the snap-test.
I will take a closer look tomorrow.

Try this 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">

<!--  MUST NOT HAVE THIS CONTEXT LISTENER IN SNAP ONLY IN HOST
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
-->

	<servlet>
		<display-name>Snap Test Servlet</display-name>
		<servlet-name>snaps-test</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<!-- 
		<init-param> 
			<param-name>contextConfigLocation</param-name> 
			<param-value>/WEB-INF/snaps-test-servlet.xml </param-value>
		</init-param> 
		-->
		<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>snaps-test</servlet-name>
		<url-pattern>/snap/*</url-pattern>
	</servlet-mapping>

	<!-- <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> -->

</web-app>

Previous Topic:How to disable the Admin Web Console
Next Topic:Eclipse Virgo shutsdown for no reason after some hours on EC2
Goto Forum:
  


Current Time: Fri Mar 29 04:40:18 GMT 2024

Powered by FUDForum. Page generated in 0.02891 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top