Hello,
I spent the better part of a day playing with this to finally get it to
work. I thought it would be helpful to add an example when we are not
using the default whiteboard.
1. Use of the welcome file (Pax Web specific but Karaf uses Pax Web)
2. The fact that if you create your own context, you need to pass the
bundle to the constructor of ServletContextHelper in order for it to
resolve resources correctly (this drove me completely nuts)
3. Common place to put static resources i.e src/main/resources/static
being shown here (common in other frameworks)
4. You can put the HttpWhiteboardResource directly on the
ServletContextHelper along with the ContextSelect for what is being
defined instead of a separate class (though not sure if this is more
confusing)
import static
org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.http.context.ServletContextHelper;
import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardContext;
import
org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardContextSelect;
import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardResource;
@Component(
service = ServletContextHelper.class,
property = {"osgi.http.whiteboard.welcome.file=index.html"})
@HttpWhiteboardContext(name = "dashboard", path = "/dashboard")
@HttpWhiteboardContextSelect("(" + HTTP_WHITEBOARD_CONTEXT_NAME + "=dashboard)")
@HttpWhiteboardResource(pattern = "/*", prefix = "/static")
public class DashboardServletContextHelper extends ServletContextHelper {
@Activate
public DashboardServletContextHelper(final BundleContext bundleContext) {
super(bundleContext.getBundle());
}
}
BREAK BREAK
How can I get on the #karaf ASF slack? Says I do not have an account
with my email.
--
Chaz