Loading resources through JBWeb context API

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Loading resources through JBWeb context API

Thomas Diesler
Hi Remy,

I have a 3rd party servlet that uses this API

       InputStream is = getServletContext().getResourceAsStream(propFile);

How is it possible to hook into this call using the dynamic context API?

Here is what I do to register the servlet

             // Add the RegistryServlet
             servlet = new RegistryServlet();
             wrapper = context.createWrapper();
             wrapper.setName("JUDDIRegistryServlet");
             wrapper.setServlet(servlet);
             wrapper.setServletClass(servlet.getClass().getName());
             wrapper.setLoadOnStartup(1);
             context.addChild(wrapper);

cheers
-thomas

--
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thomas Diesler
JBoss OSGi Lead
JBoss, a division of Red Hat
xxxxxxxxxxxxxxxxxxxxxxxxxxxx

_______________________________________________
jboss-as7-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/jboss-as7-dev
Reply | Threaded
Open this post in threaded view
|

Re: Loading resources through JBWeb context API

Rémy Maucherat
On Tue, 2011-11-01 at 18:32 +0000, Thomas Diesler wrote:
> Hi Remy,
>
> I have a 3rd party servlet that uses this API
>
>        InputStream is = getServletContext().getResourceAsStream(propFile);
>
> How is it possible to hook into this call using the dynamic context API?

You cannot replace the servlet context implementation.

> Here is what I do to register the servlet
>
>              // Add the RegistryServlet
>              servlet = new RegistryServlet();
>              wrapper = context.createWrapper();
>              wrapper.setName("JUDDIRegistryServlet");
>              wrapper.setServlet(servlet);
>              wrapper.setServletClass(servlet.getClass().getName());
>              wrapper.setLoadOnStartup(1);
>              context.addChild(wrapper);

--
Remy Maucherat <[hidden email]>
Red Hat Inc

_______________________________________________
jboss-as7-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/jboss-as7-dev
Reply | Threaded
Open this post in threaded view
|

Re: Loading resources through JBWeb context API

jtgreene
Administrator
On 11/2/11 2:39 AM, Remy Maucherat wrote:

> On Tue, 2011-11-01 at 18:32 +0000, Thomas Diesler wrote:
>> Hi Remy,
>>
>> I have a 3rd party servlet that uses this API
>>
>>         InputStream is = getServletContext().getResourceAsStream(propFile);
>>
>> How is it possible to hook into this call using the dynamic context API?
>
> You cannot replace the servlet context implementation.

Thomas are you asking how to get the context to see the right resources?

You can do:
final Loader loader = new
         WebCtxLoader(ThirdPartyClass.getClassLoader());

...
context.setLoader(loader);

--
Jason T. Greene
JBoss AS Lead / EAP Platform Architect
JBoss, a division of Red Hat
_______________________________________________
jboss-as7-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/jboss-as7-dev
Reply | Threaded
Open this post in threaded view
|

Re: Loading resources through JBWeb context API

jtgreene
Administrator
On 11/2/11 1:00 PM, Jason T. Greene wrote:

> On 11/2/11 2:39 AM, Remy Maucherat wrote:
>> On Tue, 2011-11-01 at 18:32 +0000, Thomas Diesler wrote:
>>> Hi Remy,
>>>
>>> I have a 3rd party servlet that uses this API
>>>
>>>          InputStream is = getServletContext().getResourceAsStream(propFile);
>>>
>>> How is it possible to hook into this call using the dynamic context API?
>>
>> You cannot replace the servlet context implementation.
>
> Thomas are you asking how to get the context to see the right resources?
>
> You can do:
> final Loader loader = new
>           WebCtxLoader(ThirdPartyClass.getClassLoader());
>
> ...
> context.setLoader(loader);
>

Oh duh I see what you mean. You want to be able to load resources
*without* changing that call.

In that case you can just plug in your own DirContext impl.

--
Jason T. Greene
JBoss AS Lead / EAP Platform Architect
JBoss, a division of Red Hat
_______________________________________________
jboss-as7-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/jboss-as7-dev
Reply | Threaded
Open this post in threaded view
|

Re: Loading resources through JBWeb context API

Rémy Maucherat
On Wed, 2011-11-02 at 13:12 -0500, Jason T. Greene wrote:
> Oh duh I see what you mean. You want to be able to load resources
> *without* changing that call.
>
> In that case you can just plug in your own DirContext impl.

Ah ok, so if it's only about the resources from the servlet context and
not the whole servlet context impl, then it must still be about the
supposed need to have real static files for the juddi webapp.

Indeed, static resources are served from DirContext which can come from
files or VFS. It is also possible to take advantage of the overlays from
Servlet 3 (which are exposed).

But rather than do one of these, would it be possible to be reasonable
and drop that webapp ? ;)

--
Remy Maucherat <[hidden email]>
Red Hat Inc

_______________________________________________
jboss-as7-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/jboss-as7-dev
Reply | Threaded
Open this post in threaded view
|

Re: Loading resources through JBWeb context API

Kurt T Stam
This is juddiv2 reading its config property file. I'd rather not have to change code in juddiv2 for this.

-Kurt

On Nov 2, 2011, at 15:44, Remy Maucherat <[hidden email]> wrote:

> On Wed, 2011-11-02 at 13:12 -0500, Jason T. Greene wrote:
>> Oh duh I see what you mean. You want to be able to load resources
>> *without* changing that call.
>>
>> In that case you can just plug in your own DirContext impl.
>
> Ah ok, so if it's only about the resources from the servlet context and
> not the whole servlet context impl, then it must still be about the
> supposed need to have real static files for the juddi webapp.
>
> Indeed, static resources are served from DirContext which can come from
> files or VFS. It is also possible to take advantage of the overlays from
> Servlet 3 (which are exposed).
>
> But rather than do one of these, would it be possible to be reasonable
> and drop that webapp ? ;)
>
> --
> Remy Maucherat <[hidden email]>
> Red Hat Inc
>
> _______________________________________________
> jboss-as7-dev mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/jboss-as7-dev

_______________________________________________
jboss-as7-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/jboss-as7-dev
Reply | Threaded
Open this post in threaded view
|

Re: Loading resources through JBWeb context API

Thomas Diesler
In reply to this post by Rémy Maucherat
Hi Remy,

I think it is reasonable to ask for a clean API to setup a web context that includes servlet and resoure registration. May I remind you about AS7-351 which also has resource registration as a requirement.

I'll look into replacing the DirContext as a work around.

cheers
-thomas


On 11/02/2011 08:44 PM, Remy Maucherat wrote:
On Wed, 2011-11-02 at 13:12 -0500, Jason T. Greene wrote:
Oh duh I see what you mean. You want to be able to load resources 
*without* changing that call.

In that case you can just plug in your own DirContext impl.
Ah ok, so if it's only about the resources from the servlet context and
not the whole servlet context impl, then it must still be about the
supposed need to have real static files for the juddi webapp.

Indeed, static resources are served from DirContext which can come from
files or VFS. It is also possible to take advantage of the overlays from
Servlet 3 (which are exposed).

But rather than do one of these, would it be possible to be reasonable
and drop that webapp ? ;)


-- 
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thomas Diesler
JBoss OSGi Lead
JBoss, a division of Red Hat
xxxxxxxxxxxxxxxxxxxxxxxxxxxx 

_______________________________________________
jboss-as7-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/jboss-as7-dev
Reply | Threaded
Open this post in threaded view
|

Re: Loading resources through JBWeb context API

Rémy Maucherat
On Thu, 2011-11-03 at 15:09 +0100, Thomas Diesler wrote:
> Hi Remy,
>
> I think it is reasonable to ask for a clean API to setup a web context
> that includes servlet and resoure registration. May I remind you about
> AS7-351 which also has resource registration as a requirement.

One thing that I find confusing is if the whole HttpService is supposed
to be one big webapp.

> I'll look into replacing the DirContext as a work around.

There's an existing VFSDirContext implementation. The overlays (which
are defined in WarMetaData) are straight VirtualFile objects and are
using it, so it should work fine for you.

What should be added then is a "parent" DirContext to handle the aliases
if everything is supposed to go in a single webapp.

--
Remy Maucherat <[hidden email]>
Red Hat Inc

_______________________________________________
jboss-as7-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/jboss-as7-dev
Reply | Threaded
Open this post in threaded view
|

Re: Loading resources through JBWeb context API

Rémy Maucherat
On Thu, 2011-11-03 at 17:05 +0100, Remy Maucherat wrote:

> On Thu, 2011-11-03 at 15:09 +0100, Thomas Diesler wrote:
> > Hi Remy,
> >
> > I think it is reasonable to ask for a clean API to setup a web context
> > that includes servlet and resoure registration. May I remind you about
> > AS7-351 which also has resource registration as a requirement.
>
> One thing that I find confusing is if the whole HttpService is supposed
> to be one big webapp.
>
> > I'll look into replacing the DirContext as a work around.
>
> There's an existing VFSDirContext implementation. The overlays (which
> are defined in WarMetaData) are straight VirtualFile objects and are
> using it, so it should work fine for you.
>
> What should be added then is a "parent" DirContext to handle the aliases
> if everything is supposed to go in a single webapp.

So is the right design using a DirContext that do the alias list for the
register resources ?

--
Remy Maucherat <[hidden email]>
Red Hat Inc

_______________________________________________
jboss-as7-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/jboss-as7-dev