views:

567

answers:

2

I'm currently researching OSGi with Spring, and working through a couple of examples from Pro Spring Dynamic Modules for OSGi.

My example web-app has a single controller like:

@Controller
public class HelloWorldController {
    private HelloWorldService helloWorldService;

    @RequestMapping(method = RequestMethod.GET)
    @ModelAttribute("helloworld")
    public HelloWorld home() {
        return this.helloWorldService.find();
    }

    // injected in - spring looks up the service from OSGi
    public void setHelloWorldService(HelloWorldService helloWorldService) {
        this.helloWorldService = helloWorldService;
    }
}

The view resolver is configured as:

<bean id="viewResolver"
  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="viewClass" 
    value="org.springframework.web.servlet.view.JstlView"/>
  <property name="prefix" value="/jsp/" />
  <property name="suffix" value=".jsp" />
</bean>

Calling on the url 'http://localhost:8080/helloworld-web/spring/home' should cause the view jsp/home.jsp to be rendered, with helloworld containing a single bean:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"&gt;
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
<html>
<head>
<title>Spring DM HelloWorld</title>
</head>
<body>
<p>Results from accessing Spring-DM service bundle:</p>
<p>Message <c:out value="${helloworld.message}" /></p>
<p>Current Time: <c:out value="${helloworld.currentTime}" /></p>
<p>Model Version: <c:out value="${helloworld.modelVersion}" /></p>
</body>
</html>

However, I am seeing the following stacktrace:

org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116)
    org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:317)
    org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:148)
    org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:424)
    org.apache.jasper.compiler.Parser.parseDirective(Parser.java:493)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1557)
    org.apache.jasper.compiler.Parser.parse(Parser.java:127)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:212)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:156)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:296)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:299)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:236)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1183)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:902)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

Because this is a WAR deployed as an OSGi bundle, its WEB-INF/lib directory is completely empty.

My understanding was that the OSGi version of jasper would look for taglib descriptors and JARs outside of the individual web-app?

Has anyone else seen this?

+2  A: 

Must have been some subtle bundle version issue. I downloaded the example code for the book, which used slightly different versions of jasper etc, and it now works.

The Spring-DM reference states:

Spring-DM extends the JSP convention, of placing the taglibs either packed as a jar under WEB-INF/lib or unpacked under WEB-INF/classes, by detecting any taglib defined in the bundle classpath (imported packages or required bundles).

Which I had done...

toolkit
A: 

What does contains your MANIFEST.MF (in Import-package and/or Required bundle ?)

Bundle-ManifestVersion: 2
Bundle-Classpath: .,
 WEB-INF/classes
Bundle-Version: 0.0.1.SNAPSHOT
Bundle-Name: iki-admin
Import-Package: javax.servlet,
 javax.servlet.http,
 javax.servlet.resources,
 [..]
 net.sf.navigator.taglib.el,
 [..]
 org.ikiproject.lib.exception,
 [..]
 org.springframework.web.servlet.tags,
 uk.ltd.getahead.dwr
Bundle-SymbolicName: org.ikiproject.admin
Web-ContextPath: iki-admin
Application-TraceLevels: *=info,org.ikiproject.*=verbose
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: com.springsource.javax.servlet.jsp.jstl,
 com.springsource.org.apache.taglibs.standard,
 org.springframework.security.taglibs

You also might have some problem with jasper & apache-tomcat version with OSGi afterwards.

Vincent Demeester