You can create your own HttpContext type then rewrite its getMimeType() and
getResource() method.
In getResource() method, you can return a URL instance to point to your
uploaded file. e.g. file:../web-content/test.bin.
Then uses OSGi HttpService API to register a resource to an servlet alias
passing your newly created HttpContext instance as the last parameter.
For example:
public class MyHttpContext implements HttpContext {
public String getMimeType(String name) {
return null; // you should correctly implement this method.
}
public URL getResource(String name) {
return new URL("file:" + this.myWebRoot + name);
}
}
then
httpService.registerResources("/uploaded_files", "/", new MyHttpContext());
On Wed, Aug 5, 2009 at 9:57 AM, Nima Kaviani <[email protected]> wrote:
> Hi all,
>
> I have a servlet registered with the Jetty Http Service, offered by Pax
> Web,
> that enables uploading content (like various types of files) to my backend
> OSGi-based application. I am able to upload the files without any problem,
> however, I am not sure how I can register the uploaded content with the Web
> server on the fly, so that I can immediately access the uploaded content
> through their URLs.
>
> It seems to me like the folder keeping the resources needs to be part of a
> bundle which registers the resoures with the Web server once it discovers
> the Web server in the OSGi service registry. However, in my case, since the
> content to be registered with the Web server is not available, I am not
> sure
> how this whole process of exposing new content to the Web server can be
> done.
>
> One solution I could think of was to wrap this folder as a WAR file and
> have
> it registered with the Web server. But this requires the whole process to
> be
> repeated upon adding or deleting new content to/from my resource folder.
> This renders the whole approach infeasible.
>
> Does any body have any solution or has anybody already encountered a
> similar
> problem?
>
> I believe my question is not a Pax Web specific question, so I believe this
> should be the proper mailing list to ask the question.
>
> I would very much appreciate your help and response.
>
> bests,
> -Nima
> --
> http://nima.magic.ubc.ca
>
--
唐睿
电话:+86 010 58732330 转 810
传真:+86 010 58732330 转 800
手机(北京):+86 13717808625
手机(深圳):+86 13510560457
汉星天(中国)公司
地址(北京):北京市海淀区知春路甲 48 号盈都大厦 A 座 9B (100098)
Hansky
Better Software, Better Business
WWW.HANSKY.COM.CN