You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Hynek Mlnarik (JIRA)" <ji...@apache.org> on 2010/07/14 09:29:53 UTC

[jira] Created: (CXF-2893) CXF should use class' classloader for initialization of its loggers

CXF should use class' classloader for initialization of its loggers
-------------------------------------------------------------------

                 Key: CXF-2893
                 URL: https://issues.apache.org/jira/browse/CXF-2893
             Project: CXF
          Issue Type: Bug
    Affects Versions: 2.2.9
            Reporter: Hynek Mlnarik
            Priority: Trivial


The class org.apache.cxf.common.logging.LogUtils should attempt to use plain Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.

Rationale: Current thread might not be able to access cxf classes. Take as an example the following OSGi bundles:
1) bundle with a http server
2) bundle with CXF-based servlet SomeCXFServlet
A servlet SomeCXFServlet from bundle (2) has access to CXF via SomeCXFServlet.class.getClassloader(), similarly for LogUtils class via its classloader. However, its initialization is performed from http server thread that does not have access to bundle (2) classes. Initialization of a logger is hence also made from the http thread. CXF tries to load its org.apache.cxf.common.logging.*Logger classes - the attempt however fails because the current thread's classloader is used instead of the LogUtils'.

Solution: Try to load the class using Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.

Diff to solve this issue follows:

*** orig\org\apache\cxf\common\logging\LogUtils.java    2010-07-08 13:13:36.000000000 +0200
--- new\org\apache\cxf\common\logging\LogUtils.java       2010-07-14 08:43:01.481043100 +0200
***************
*** 92,102 ****
                  }
              }
              if (!StringUtils.isEmpty(cname)) {
!                 loggerClass = Class.forName(cname.trim(), true,
!                                             Thread.currentThread().getContextClassLoader());
                  getLogger(LogUtils.class).fine("Using " + loggerClass.getName() + " for logging.");
              }
          } catch (Throwable ex) {
--- 92,108 ----
                  }
              }
              if (!StringUtils.isEmpty(cname)) {
!                 try {
!                     loggerClass = Class.forName(cname.trim(), true,
!                                                 Thread.currentThread().getContextClassLoader());
!                 } catch (Throwable ex) {
!                     loggerClass = Class.forName(cname.trim());
!                 }
                  getLogger(LogUtils.class).fine("Using " + loggerClass.getName() + " for logging.");
              }
          } catch (Throwable ex) {


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CXF-2893) CXF should use class' classloader for initialization of its loggers

Posted by "Hynek Mlnarik (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-2893?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hynek Mlnarik updated CXF-2893:
-------------------------------

    Description: 
The class org.apache.cxf.common.logging.LogUtils should attempt to use plain Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.

Rationale: Current thread might not be able to access cxf classes. Take as an example the following OSGi bundles:
1) bundle with a http server.
2) bundle with CXF-based servlet SomeCXFServlet. The bundle contains CXF as private OSGi library.
A servlet SomeCXFServlet from bundle (2) has access to CXF via SomeCXFServlet.class.getClassloader(), similarly LogUtils class via its classloader. However, the servlet initialization is performed from http server thread that does not have access to bundle (2) private classes. Initialization of a logger is hence also made from the http thread. CXF tries to load its org.apache.cxf.common.logging.*Logger classes - the attempt however fails because the current thread's classloader is used instead of the LogUtils'.

Solution: Try to load the class using Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.

Will attach diff in a separate comment

  was:
The class org.apache.cxf.common.logging.LogUtils should attempt to use plain Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.

Rationale: Current thread might not be able to access cxf classes. Take as an example the following OSGi bundles:
1) bundle with a http server
2) bundle with CXF-based servlet SomeCXFServlet
A servlet SomeCXFServlet from bundle (2) has access to CXF via SomeCXFServlet.class.getClassloader(), similarly for LogUtils class via its classloader. However, its initialization is performed from http server thread that does not have access to bundle (2) classes. Initialization of a logger is hence also made from the http thread. CXF tries to load its org.apache.cxf.common.logging.*Logger classes - the attempt however fails because the current thread's classloader is used instead of the LogUtils'.

Solution: Try to load the class using Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.

Will attach diff in a separate comment


> CXF should use class' classloader for initialization of its loggers
> -------------------------------------------------------------------
>
>                 Key: CXF-2893
>                 URL: https://issues.apache.org/jira/browse/CXF-2893
>             Project: CXF
>          Issue Type: Bug
>    Affects Versions: 2.2.9
>            Reporter: Hynek Mlnarik
>            Priority: Trivial
>         Attachments: patch.diff
>
>
> The class org.apache.cxf.common.logging.LogUtils should attempt to use plain Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.
> Rationale: Current thread might not be able to access cxf classes. Take as an example the following OSGi bundles:
> 1) bundle with a http server.
> 2) bundle with CXF-based servlet SomeCXFServlet. The bundle contains CXF as private OSGi library.
> A servlet SomeCXFServlet from bundle (2) has access to CXF via SomeCXFServlet.class.getClassloader(), similarly LogUtils class via its classloader. However, the servlet initialization is performed from http server thread that does not have access to bundle (2) private classes. Initialization of a logger is hence also made from the http thread. CXF tries to load its org.apache.cxf.common.logging.*Logger classes - the attempt however fails because the current thread's classloader is used instead of the LogUtils'.
> Solution: Try to load the class using Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.
> Will attach diff in a separate comment

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CXF-2893) CXF should use class' classloader for initialization of its loggers

Posted by "Hynek Mlnarik (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-2893?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hynek Mlnarik updated CXF-2893:
-------------------------------

    Description: 
The class org.apache.cxf.common.logging.LogUtils should attempt to use plain Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.

Rationale: Current thread might not be able to access cxf classes. Take as an example the following OSGi bundles:
1) bundle with a http server
2) bundle with CXF-based servlet SomeCXFServlet
A servlet SomeCXFServlet from bundle (2) has access to CXF via SomeCXFServlet.class.getClassloader(), similarly for LogUtils class via its classloader. However, its initialization is performed from http server thread that does not have access to bundle (2) classes. Initialization of a logger is hence also made from the http thread. CXF tries to load its org.apache.cxf.common.logging.*Logger classes - the attempt however fails because the current thread's classloader is used instead of the LogUtils'.

Solution: Try to load the class using Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.

Will attach diff in a separate comment

  was:
The class org.apache.cxf.common.logging.LogUtils should attempt to use plain Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.

Rationale: Current thread might not be able to access cxf classes. Take as an example the following OSGi bundles:
1) bundle with a http server
2) bundle with CXF-based servlet SomeCXFServlet
A servlet SomeCXFServlet from bundle (2) has access to CXF via SomeCXFServlet.class.getClassloader(), similarly for LogUtils class via its classloader. However, its initialization is performed from http server thread that does not have access to bundle (2) classes. Initialization of a logger is hence also made from the http thread. CXF tries to load its org.apache.cxf.common.logging.*Logger classes - the attempt however fails because the current thread's classloader is used instead of the LogUtils'.

Solution: Try to load the class using Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.

Diff to solve this issue follows:

*** orig\org\apache\cxf\common\logging\LogUtils.java    2010-07-08 13:13:36.000000000 +0200
--- new\org\apache\cxf\common\logging\LogUtils.java       2010-07-14 08:43:01.481043100 +0200
***************
*** 92,102 ****
                  }
              }
              if (!StringUtils.isEmpty(cname)) {
!                 loggerClass = Class.forName(cname.trim(), true,
!                                             Thread.currentThread().getContextClassLoader());
                  getLogger(LogUtils.class).fine("Using " + loggerClass.getName() + " for logging.");
              }
          } catch (Throwable ex) {
--- 92,108 ----
                  }
              }
              if (!StringUtils.isEmpty(cname)) {
!                 try {
!                     loggerClass = Class.forName(cname.trim(), true,
!                                                 Thread.currentThread().getContextClassLoader());
!                 } catch (Throwable ex) {
!                     loggerClass = Class.forName(cname.trim());
!                 }
                  getLogger(LogUtils.class).fine("Using " + loggerClass.getName() + " for logging.");
              }
          } catch (Throwable ex) {



> CXF should use class' classloader for initialization of its loggers
> -------------------------------------------------------------------
>
>                 Key: CXF-2893
>                 URL: https://issues.apache.org/jira/browse/CXF-2893
>             Project: CXF
>          Issue Type: Bug
>    Affects Versions: 2.2.9
>            Reporter: Hynek Mlnarik
>            Priority: Trivial
>         Attachments: patch.diff
>
>
> The class org.apache.cxf.common.logging.LogUtils should attempt to use plain Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.
> Rationale: Current thread might not be able to access cxf classes. Take as an example the following OSGi bundles:
> 1) bundle with a http server
> 2) bundle with CXF-based servlet SomeCXFServlet
> A servlet SomeCXFServlet from bundle (2) has access to CXF via SomeCXFServlet.class.getClassloader(), similarly for LogUtils class via its classloader. However, its initialization is performed from http server thread that does not have access to bundle (2) classes. Initialization of a logger is hence also made from the http thread. CXF tries to load its org.apache.cxf.common.logging.*Logger classes - the attempt however fails because the current thread's classloader is used instead of the LogUtils'.
> Solution: Try to load the class using Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.
> Will attach diff in a separate comment

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CXF-2893) CXF should use class' classloader for initialization of its loggers

Posted by "Daniel Kulp (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-2893?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Kulp resolved CXF-2893.
------------------------------

         Assignee: Daniel Kulp
    Fix Version/s: 2.2.10
       Resolution: Fixed

> CXF should use class' classloader for initialization of its loggers
> -------------------------------------------------------------------
>
>                 Key: CXF-2893
>                 URL: https://issues.apache.org/jira/browse/CXF-2893
>             Project: CXF
>          Issue Type: Bug
>    Affects Versions: 2.2.9
>            Reporter: Hynek Mlnarik
>            Assignee: Daniel Kulp
>            Priority: Trivial
>             Fix For: 2.2.10
>
>         Attachments: patch.diff
>
>
> The class org.apache.cxf.common.logging.LogUtils should attempt to use plain Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.
> Rationale: Current thread might not be able to access cxf classes. Take as an example the following OSGi bundles:
> 1) bundle with a http server.
> 2) bundle with CXF-based servlet SomeCXFServlet. The bundle contains CXF as private OSGi library.
> A servlet SomeCXFServlet from bundle (2) has access to CXF via SomeCXFServlet.class.getClassloader(), similarly LogUtils class via its classloader. However, the servlet initialization is performed from http server thread that does not have access to bundle (2) private classes. Initialization of a logger is hence also made from the http thread. CXF tries to load its org.apache.cxf.common.logging.*Logger classes - the attempt however fails because the current thread's classloader is used instead of the LogUtils'.
> Solution: Try to load the class using Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.
> Will attach diff in a separate comment

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CXF-2893) CXF should use class' classloader for initialization of its loggers

Posted by "Hynek Mlnarik (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-2893?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hynek Mlnarik updated CXF-2893:
-------------------------------

    Attachment: patch.diff

Diff to fix the described issue.

> CXF should use class' classloader for initialization of its loggers
> -------------------------------------------------------------------
>
>                 Key: CXF-2893
>                 URL: https://issues.apache.org/jira/browse/CXF-2893
>             Project: CXF
>          Issue Type: Bug
>    Affects Versions: 2.2.9
>            Reporter: Hynek Mlnarik
>            Priority: Trivial
>         Attachments: patch.diff
>
>
> The class org.apache.cxf.common.logging.LogUtils should attempt to use plain Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.
> Rationale: Current thread might not be able to access cxf classes. Take as an example the following OSGi bundles:
> 1) bundle with a http server
> 2) bundle with CXF-based servlet SomeCXFServlet
> A servlet SomeCXFServlet from bundle (2) has access to CXF via SomeCXFServlet.class.getClassloader(), similarly for LogUtils class via its classloader. However, its initialization is performed from http server thread that does not have access to bundle (2) classes. Initialization of a logger is hence also made from the http thread. CXF tries to load its org.apache.cxf.common.logging.*Logger classes - the attempt however fails because the current thread's classloader is used instead of the LogUtils'.
> Solution: Try to load the class using Class.forName(cname) if Class.forName(cname, true, Thread.currentThread().getContextClassLoader()) fails.
> Will attach diff in a separate comment

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.