1

As a developer completely new to Spring and OSGi, and returning to Tomcat after a long time, I don't even know if I can ask this question properly. But I hope someone will be able to understand where I am stuck and how I should proceed.

The setup includes a Tomcat 7 bundles in the Equinox OSGi container. A bundle provides the "MainDispatcherServlet", which extends org.springframework.web.servlet.DispatcherServlet. Other service bundles register org.springframework.web.servlet.mvc.Controller instances in the OSGi whiteboard which the MainDispatcherServlet listens for. MainDispatcherServlet provides an API to map url-patterns to the registered Controllers, which it in turn uses a SimpleUrlHandlerMapping to identify the handler for individual requests. The service bundles often implement a javax GenericServlet, and wrap it in ServletWrappingController for the registration.

This much works smoothly. Now I need the following

Static Resources

Dispatch to static resources like images and jsps (don't know if they are considered static) in these bundles.

Searching on SO it seems this can be done with some <mvc:resources> magic in the client bundle, even though I don't quite figure out the exact xml. But if I understand right the request would not go through the MainDispatcherServlet, which is a requirement.

So the approach I am taking right now is to use a org.apache.catalina.servlets.DefaultServlet and wrap it in a Controller as described above. Is this a good way to accomplish this? The problem here is that DefaultServlet needs a ServletContext and I don't have one to give it.

Is there easy way a to create a ServletContext that I can inject into the Controller?

Forward to Static Resources

Further, I need another Servlet in the same client bundle to be able to forward to the jsps in the bundle using RequestDispatcher, an additional reason I need a full fledged ServletContext.

In summary, is workable (even if not elegant)? And if so how do I create a ServletConteext? If this is not workable what is the alternative?

All this is quite daunting. Though I am not (cannot :)) ask for implemented prototype, I will appreciate more then a terse instruction like "inject X in Y and wrap it with a Z and you are all set".

Miserable Variable
  • 28,432
  • 15
  • 72
  • 133

1 Answers1

0

The Amdatu open source project has a bundle that allows you to easily serve static resources from a bundle. It uses an extender pattern, which means that you just need to add some information to your bundle's manifest:

X-Web-Resource-Version: 1.0
X-Web-Resource: path/to/resources

Go to this page [1] and scroll down for more information about it. Of course you need to deploy Amdatu's "resource handler" bundle and its dependencies, which can be found in this repository [2].

[1] http://amdatu.org/components/web.html

[2] http://repository.amdatu.org/snapshot/org.amdatu.web.resourcehandler/org.amdatu.web.resourcehandler-1.0.2.jar

Marcel Offermans
  • 3,313
  • 1
  • 15
  • 23