Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Load jsp from another bundle OSGi (Try to load jsp file from another bundle)
icon5.gif  Load jsp from another bundle OSGi [message #772342] Thu, 29 December 2011 14:52 Go to next message
Gabriel Afonso is currently offline Gabriel Afonso
Messages: 23
Registered: December 2011
Junior Member
Hi,
I have 2 WAB (Web Application Bundles), I need WAB-1 to scan the controllers of the WAB-2. Then when I deploy WAB-1 and go to the browser and I type "localhost:8080/wab-1/index" it shows me the Index page (because WAB-1 has a controller to show the index page (jsp)). When I deploy both (WAB-1 and WAB-2) the WAB-1 should scan to the controllers of the WAB-2 and be able to show his JSPs(pages). But when I type this url "localhost:8080/wab-1/SOME-PAGE-OF-WAB-2" in browser it return 404 error with this message:

HTTP Status 404 - /wab-1/WEB-INF/jsp/SOME-PAGE-OF-WAB-2.jsp
type Status report
message /wab-1/WEB-INF/jsp/SOME-PAGE-OF-WAB-2.jsp
description The requested resource (/wab-1/WEB-INF/jsp/SOME-PAGE-OF-WAB-2.jsp) is not available.

WAB-1 doesn't find a jsp file named "SOME-PAGE-OF-WAB-2" in his /wab-1/WEB-INF/jsp/ folder because there isn't this file. But it should look for this file in /wab-2/WEB-INF/jsp/ because there is this file.

I'm using Virgo with Spring DM 3.0.5. in OSGi Environment.

This is the code of WAB-1.
Manifest
Manifest-Version: 1.0
Created-By: user
Bundle-ManifestVersion: 2
Bundle-Name: WAB-1
Bundle-SymbolicName: WAB-1
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Web-ContextPath: wab-1
Webapp-Context: wab-1
Bundle-ClassPath: .,WEB-INF/classes,WEB-INF/lib/jstl-impl-1.2.jar
Import-Package: org.eclipse.virgo.web.dm,org.apache.taglibs.standard.tag.rt.core,com.wab2.controller
Import-Library: org.springframework.spring;version="[3.0.5.RELEASE,3.0.5.RELEASE]"


wab1-servlet.xml

<context:component-scan annotation-config="true" base-package="com.wab1.controller"></context:component-scan>
 <context:component-scan annotation-config="true" base-package="com.wab2.controller"></context:component-scan>       
 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/jsp/"/>
      <property name="suffix" value=".jsp"/>
 </bean>
   
 <mvc:annotation-driven/>
 <mvc:resources mapping="/resources/**" location="/resources/"/>


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

    <servlet-mapping>
        <servlet-name>wab1</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>


This is the code of WAB-2.
Manifest
Manifest-Version: 1.0
Created-By: user
Bundle-ManifestVersion: 2
Bundle-Name: WAB-2
Bundle-SymbolicName: WAB-2
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Web-ContextPath: wab-2
Webapp-Context: wab-2
Bundle-ClassPath: .,WEB-INF/classes,WEB-INF/lib/jstl-impl-1.2.jar
Import-Package: org.eclipse.virgo.web.dm,org.apache.taglibs.standard.tag.rt.core
Import-Library: org.springframework.spring;version="[3.0.5.RELEASE,3.0.5.RELEASE]"
Export-Package: com.wab2.controller



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

    <servlet-mapping>
        <servlet-name>wab2</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>


Can Somebody help me??
How I can tell to WAB-1 to look for this jsp file in WAB-2 and not in WAB-1 folder?
.... sorry for my bad english Rolling Eyes

[Updated on: Thu, 29 December 2011 14:58]

Report message to a moderator

Re: Load jsp from another bundle OSGi [message #772351 is a reply to message #772342] Thu, 29 December 2011 15:14 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry Sklyut
Messages: 272
Registered: January 2010
Senior Member
You can't do it with two wab/war. The jsps in wab-2 are private to that deployment unit.

You could deploy "wab-2" as a bundle vs. a wab and place jsps in the some package that is exported by that bundle and reconfigure wab-1 to look for jsps in that location for example with combination of InternvalViewResolver and XmlViewResolver/ResourceBundleViewResolver and classpath: prefix for jsp urls. Make sure to order resolvers so that InternalViewResolver is always last in the chain.

Take a look at snaps as a way to partition one wab into multiple modules.

Regards,
Dmitry
Re: Load jsp from another bundle OSGi [message #772364 is a reply to message #772351] Thu, 29 December 2011 15:54 Go to previous messageGo to next message
Gabriel Afonso is currently offline Gabriel Afonso
Messages: 23
Registered: December 2011
Junior Member
First at all, Thanks for your reply Dmitry. Yes that is a good idea, but I have 2 wabs (or more) because they work with Spring MVC and they have controllers and Views (they work like plugins). These wabs are working with Spring MVC and each one has its owns controllers, so, when I call a wab2 controller from a wab1, the result should be showing its JSP but wab2 is looking for this jsp in wab-1/WEB-INF/jsp/ instead its owns directory (wab-2/WEB-INF/jsp/).

this is the controller of wab-2

@Controller
public class Navigation {
    
    @RequestMapping(value="nav",method=RequestMethod.GET)
    public String showNavigation() {
        return "navigation";
    }
}


Its really simple, it only returns a view (navigation.jsp) that is located in wab-2/WEB-INF/jsp/, but it look for this view in /wab-1/WEB-INF/jsp/

I call a wab-2 controller from wab-1 whit this URL:

localhost:8080/wab-1/nav

wab-1 knows there's a controller called "nav" in wab-2 (because it scan all controller first using component-scan) and wab-1 delegate the work to wab-2 controller. The problem is when wab-2 controller returns the view
Re: Load jsp from another bundle OSGi [message #772369 is a reply to message #772364] Thu, 29 December 2011 16:09 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry Sklyut
Messages: 272
Registered: January 2010
Senior Member
Yes. It is really simple Smile. But you must keep in mind that with OSGi you only see what is exported by another bundle/wab and imported by your bundle. Because wab-2 does not export anything from /WEB-INF/jsp (and in really it should never do - think about resolution hell if every bundle will export WEB-INF? Ever heard of split package?) those files are not visible to wab-1.

It is really difficult to mix standard jee programming model and osgi programming model. In your situation please do take a look at snaps. This is specifically the reason that snaps were created for. Composite web apps in osgi. Each wab that you deploy will have its own controllers, views, etc. It will also get its one subpath within a larger composite web-app context.

You really do want the isolation between web-apps. It just not really possible to make one wab import controllers from another wab and use it that way. You are basically deploying two web applications. Virgo will start both of them as web application. You will have two servlet contexts created, but you want to use controllers from one in another and expect those controllers within context of wab-1 to see stuff in wab-2.

If you want to re-use code across multiple wabs - package that reusable code as a bundle not as a wab and share it that way. Both wabs import packages from shared bundle and use them.

Hope this is clears the picture a bit for you.

Regards,
Dmitry
Re: Load jsp from another bundle OSGi [message #772377 is a reply to message #772369] Thu, 29 December 2011 16:32 Go to previous messageGo to next message
Gabriel Afonso is currently offline Gabriel Afonso
Messages: 23
Registered: December 2011
Junior Member
Thanks for your suggestions Dmitry. I will do that and then I'll tell you how was it.

Regards,
Gabriel
Re: Load jsp from another bundle OSGi [message #774800 is a reply to message #772377] Wed, 04 January 2012 16:35 Go to previous message
Gabriel Afonso is currently offline Gabriel Afonso
Messages: 23
Registered: December 2011
Junior Member
Thanks Dmitry, it works fine!
Previous Topic:Virgo 2.1.1 and Blazeds 4.0
Next Topic:Using Virgo Snaps and Spring Interceptors
Goto Forum:
  


Current Time: Sat Oct 25 12:46:57 GMT 2014

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

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