Re: [Resin-interest] Getting application name with no ServletContext

2008-07-30 Thread Vic Simkus
Scott Ferguson wrote:

> Oh. I see.  Take a look at com.caucho.security.SecurityContext.  You  
> can try:
>
> HttpServletRequest request
> = (HttpServletRequest)  
> com.caucho.security.SecurityContext.getProvider();
>
> You could also try:
>
> WebBeansContainer webBeans = WebBeansContainer.getCurrent();
> ServletContext webApp = webBeans.getByType(ServletContext.class);
>
> As Serge mentioned, you can also create a filter that stores the  
> context in a ThreadLocal.  If you do that, make absolutely certain you  
> clear the ThreadLocal at the end of the filter otherwise very bad  
> things will happen.  (Basically GC and web-app reloading will break  
> horribly.)
>
> -- Scott
>   

 
Thanks guys!  It works!

-- 
Vic Simkus

Department of Neurology, UIC
912 South Wood St.
Room 855N
Chicago IL 60612




___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Getting application name with no ServletContext

2008-07-29 Thread Scott Ferguson

On Jul 29, 2008, at 10:34 AM, Vic Simkus wrote:

> Scott Ferguson wrote:
>>> Hello
>>>
>>> Is there any way to get the current application name/path without a
>>> ServletContext?  I'm looking for this is to add it to the logging
>>> statements in a customized Acegi class that does not have direct
>>> access
>>> to any of the web application specifics.  I realize that this  
>>> might be
>>> Resin-specific, but I'm ok with that :)
>>>
>>
>> HttpServletRequest has a getContextPath() that you can use.
>>
> 
>
> Hi, Scott
>
> I don't have access to anything "web related" within the class/method.
> Does Resin provide any way of extracting that sort of information  
> (shot
> in a dark here) based on the current thread?

Oh. I see.  Take a look at com.caucho.security.SecurityContext.  You  
can try:

HttpServletRequest request
= (HttpServletRequest)  
com.caucho.security.SecurityContext.getProvider();

You could also try:

WebBeansContainer webBeans = WebBeansContainer.getCurrent();
ServletContext webApp = webBeans.getByType(ServletContext.class);

As Serge mentioned, you can also create a filter that stores the  
context in a ThreadLocal.  If you do that, make absolutely certain you  
clear the ThreadLocal at the end of the filter otherwise very bad  
things will happen.  (Basically GC and web-app reloading will break  
horribly.)

-- Scott


>
>
> Thanks
>
> -- 
> Vic Simkus
>
> Department of Neurology, UIC
> 912 South Wood St.
> Room 855N
> Chicago IL 60612
>
>
>
>
> ___
> resin-interest mailing list
> resin-interest@caucho.com
> http://maillist.caucho.com/mailman/listinfo/resin-interest



___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Getting application name with no ServletContext

2008-07-29 Thread Serge Knystautas
Vic Simkus wrote:
>> HttpServletRequest has a getContextPath() that you can use.
>>   
> 
> 
> Hi, Scott
> 
> I don't have access to anything "web related" within the class/method.  
> Does Resin provide any way of extracting that sort of information (shot 
> in a dark here) based on the current thread?
> 
> Thanks

This is a hack, but what we do is create a ThreadLocal with the current 
request object.  Something like this:

public abstract class ThreadRequest {

 private static ThreadLocal requestHolder = new ThreadLocal();
 /**
  * Sets the current thread's request.
  */
 public static void setRequest(HttpServletRequest request) {
 requestHolder.set(request);
 }

 /**
  * Gets the current thread's request.
  */
 public static HttpServletRequest getRequest() {
 return (HttpServletRequest) requestHolder.get();
 }
}

Then you need a filter that sets this and clears it from the thread.

ThreadRequest.setRequest(request);
try {
 // Now hand it off to everything else.
 chain.doFilter(proxiedRequest, response);
} finally {
 ThreadRequest.setRequest(null);
}


This gives you static access to the current request on this thread.

-- 
Serge Knystautas
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. [EMAIL PROTECTED]


___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Getting application name with no ServletContext

2008-07-29 Thread Vic Simkus
Scott Ferguson wrote:
>> Hello
>>
>> Is there any way to get the current application name/path without a
>> ServletContext?  I'm looking for this is to add it to the logging
>> statements in a customized Acegi class that does not have direct  
>> access
>> to any of the web application specifics.  I realize that this might be
>> Resin-specific, but I'm ok with that :)
>> 
>
> HttpServletRequest has a getContextPath() that you can use.
>   


Hi, Scott

I don't have access to anything "web related" within the class/method.  
Does Resin provide any way of extracting that sort of information (shot 
in a dark here) based on the current thread?

Thanks

-- 
Vic Simkus

Department of Neurology, UIC
912 South Wood St.
Room 855N
Chicago IL 60612




___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Getting application name with no ServletContext

2008-07-29 Thread Scott Ferguson

On Jul 29, 2008, at 9:56 AM, Vic Simkus wrote:

> Hello
>
> Is there any way to get the current application name/path without a
> ServletContext?  I'm looking for this is to add it to the logging
> statements in a customized Acegi class that does not have direct  
> access
> to any of the web application specifics.  I realize that this might be
> Resin-specific, but I'm ok with that :)

HttpServletRequest has a getContextPath() that you can use.

-- Scott

>
>
> Thanks
>
> -- 
> Vic Simkus
>
> Department of Neurology, UIC
> 912 South Wood St.
> Room 855N
> Chicago IL 60612
>
>
>
>
> ___
> resin-interest mailing list
> resin-interest@caucho.com
> http://maillist.caucho.com/mailman/listinfo/resin-interest



___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest