1

I've tried to register the following ResourceMapping as an OSGi service:

package ru.focusmedia.odp.server.poim.http;

import org.ops4j.pax.web.extender.whiteboard.ResourceMapping;

import ru.focusmedia.odp.server.poim.api.PoimConfig;

import aQute.bnd.annotation.component.Component;

@Component(immediate = true)
public class PoimResourceMapping implements ResourceMapping {
    private String httpContextId;
    private String alias = "...";
    private String someAbsolutePath = "...";

    @Override
    public String getHttpContextId() {
        return httpContextId;
    }

    @Override
    public String getAlias() {
        return "/resources";
    }

    @Override
    public String getPath() {
        return someAbsolutePath;
    }

}

but don't see the result in browser under http://127.0.0.1:8282/resources/aFileUnderMyPath. I can see that Pax Web is accessing my mapping in the log. Is this possible or do I need to write a servlet instead?

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487

1 Answers1

2

The short answer is no.

The path is resolved relative to the bundle and therefore your absolute path will turn in some url syntax error.

Why not loading your file in a bundle and serving it from there? We dynamically load bundles with resources that we need to serve following some versioning conventions.

maasg
  • 37,100
  • 11
  • 88
  • 115
  • That's a possibility, but not too convenient. For an administrator, there is quite a bit of difference between "put a file into this directory" and "put a file into this directory, then rebuild the bundle and deploy it". Similarly, I'd need to restart the bundle whenever a user uploads a document... – Alexey Romanov May 30 '12 at 18:29
  • Yes, depends on your usecase of course. In our case, the files to serve are produced by the build, so it's a natural integration. In your case, where you want to serve files dropped-in by users, you'd need to look into a servlet made for that purpose. – maasg May 31 '12 at 08:52