Announcement Announcement Module
Collapse
No announcement yet.
implementing a view resolver to find jsp in a jar Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • implementing a view resolver to find jsp in a jar

    We are trying to build up a modular system where jars contain application contexts and jsps along with the classes. Different URIs are located in different jars.

    For example lets say we have a request for /monkey/home.html and another for /elephant/home.html. I need monkey to go to WEB-INF/lib/monkey-1.1.jar!/WEB-INF/jsp/monkey/home.jsp and elephant to go to WEB-INF/lib/elephant-1.1.jar!/WEB-INF/jsp/monkey/home.jsp. Then there are other's that are in the main webapps web-inf/jsp such as a request for simply home.html should be found in web-inf/jsp/home.jsp.

    Any ideas on how to implement a org.springframework.web.servlet.ViewResolver to be able to find the jsp in the jar? I started something, but its not working:

    Code:
     <bean id="viewResolver" class="com.retrieve.commons.viewResolver.JarViewResolver">
            <property name="cache" value="false" />
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
            <property name="locations">
                <map>
                    <entry key="monkey" value="animals-monkey-5.2.jar"/>
                    <entry key="elephant" value="animals-elephant-5.2.jar"/>
                </map>
            </property>
        </bean>



    Code:
    public class JarViewResolver
            extends org.springframework.web.servlet.view.InternalResourceViewResolver
    {
        private String requested;
        private Map<String, String> locations = new HashMap<String, String>();
    
        public void setLocations(Map<String, String> locations)
        {
            this.locations = locations;
        }
    
        protected String getPrefix()
        {
            Set<Map.Entry<String, String>> entries = locations.entrySet();
    
            for (Map.Entry entry : entries)
            {
                if (requested.contains(entry.getKey().toString()))
                {
                    return "/WEB-INF/lib/" + entry.getValue().toString() + "!/WEB-INF/jsp/";
                }
            }
    
            return super.getPrefix();
        }
    
        protected AbstractUrlBasedView buildView(String s)
                throws Exception
        {
            requested = s; // /elephant/Home
            return super.buildView(s);    
        }
    }
    Errors as:
    Code:
    HTTP Status 404 -The requested resource (/context/WEB-INF/lib/animal-monkey-5.2.jar!/WEB-INF/jsp/monkey/Home.jsp) is not available.
    Lets assume the file is indeed in that location, in that jar, and in that web-inf jsp directory. How can I pull a resource from the jar?

    Thanks.

  • #2
    Help

    Any thoughts at all? Its been a few months. I need to revisit this issue again.

    Comment


    • #3
      Oups... I've almost posted the same request a few hours ago... but you've much better defined the issue.

      Maybe you have resolved this question by the time... any help would be appreciate.

      Thanks

      Steph

      Comment


      • #4
        Hello, Steph.

        I have not solved this problem. The work that I have done towards this has been exploratory.

        You already found my other post on the topic http://forum.springframework.org/showthread.php?t=65740

        I think part of the solution to this particular problem is that the jsp in the jar may need to be precompiled to .class files and put into the jar. I think there is a maven plugin that can do this.

        But the answer to your question here and in the other post is, No, I have not yet found a solution to creating modular web applications that allow you to add and remove web resource functionality by adding and removing jars.

        I'll be sure to contact you if I find anything useful, please do the same for me ( :

        Cheers.

        Comment

        Working...
        X