.currentThread().getContextClassLoader().loadClass(value)

Hi
What the difference between Thread.currentThread().getContextClassLoader().loadClass(value) and Class.forname(value)?
I'm using property files and storing the name of class file in propert file .I want to use Class.forname(value).In that condition how I'll create the instance of the class?
Regards
Himanshu

The thing to know here is that the context class loader is loading the class. All apps default, when first started, to the JVM application classloader as being the currentThread context loader. Often code like xerces, ejb based client code, etc will set a different classloader on the context thread. The main purpose is to allow higher up loaders in the hierarchy of a chain to "see" classes lower than it. Normall, any class loaded by a classloader can use any other class loaded by it or any of its parent (with regards to package names, visibility, and other java rules). But a parent loader can't "see" any child loaders classes. By using the thread context loader, a parent loader can be passed a reference to a child classloader of its own or any other classloader and ask that classloader to load classes for it, thus delegating in an unusual manner. It does, however, allow code loaded by the boot loader (rt.jar) to use your own code loaded by the app loader such that things like EJB calls are possible by rt.jar boot loaded classes. You may have to set the loader to your custom loader if you use custom loaders, otherwise its set to the application loader and by default any class loaded by the boot loader or extension loader can access the application loader ref through the context loader, allowing any code there to "see" any classes loaded by the app loader. This is how rt.jar EJB/rmi code can use your classes and reflection, even though they are loaded by a higher parent loader.

Similar Messages

  • Platform.runLater messes up my Thread.currentThread().getContextClassLoader()

    Hi,
    I have a plugin mechanism in my application. The plugins are defines by an interface and are loaded via URLClassLoader. A plugin can also have resources, loaded via ResourceBundle.getBundle.
    Whenever a plugin's method is called, I do this, before it is called:
    ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(pluginClassLoaders.get(pluginClass.cast(proxy)));
    // Invoke plugin method
    Thread.currentThread().setContextClassLoader(oldLoader);
    The plugin methods are called in their own thread, that means, when I want to open a window I need to do it on the JavaFX Application Thread with Platform.runLater.
    The problem is, that in the run method of the Platform.runLater, my Thread.currentThread().getContextClassLoader() is not my URLClassLoader but the Application Classloader.
    Why I need this?
    I don't want the plugin developer to always keep in mind, that he has to pass the correct class loader (of his classes) into the ResourceBundle.getBundle method.
    Instead I thought I could rely on Thread.currentThread().getContextClassLoader(), which is set in the main application, to load the correct bundle.
    It would work, but not if I load the bundle inside the JavaFX Application Thread (but which makes the most sense for UI development).
    So my goal was to have a convenient method like:
    String getResource(String bundle, String key)
    return ResourceBundle.getBundle(bundle).getString(key),  Thread.currentThread().getContextClassLoader());
    To avoid passing the classloader every time.
    Any ideas on this?

    OK, found the problem.
    In data-sources.xml, there is a connection pool and a managed-data-source settings. If I set the data source in there - it works!! Seems these XML tags take preference above the datasource tag.
    This is how the data-sources.xml now looks that's been working:
    <?xml version = '1.0' standalone = 'yes'?>
    <data-sources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/data-sources-10_1.xsd" schema-major-version="10" schema-minor-version="1">
    <connection-pool name="jdev-connection-pool-MYDB">
    <connection-factory factory-class="com.mysql.jdbc.Driver" user="henkie" password="->DataBase_User_recGxQcVfghwCszzy_gfsRgwOrxutL2l" url="jdbc:mysql://localhost/mydb"/>
    </connection-pool>
    <managed-data-source name="jdev-connection-managed-MYDB" jndi-name="jdbc/MYDBDS" connection-pool-name="jdev-connection-pool-MYDB"/>
    </data-sources>

  • Thread.currentThread().getContextClassLoader().getResourceAsStream() bug?

    Hello
    I have a problem with Thread.currentThread().getContextClassLoader().getResourceAsStream() sporadically returning null when my app is running via JNLP using Win XP/build 1.6.0_20-b02 and tomcat 6-20/JnlpDownLoadServlet.
    The code is:
    final InputStream resourceStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);I have added a map that counts the number of non null streams returned by getResourceAsStream. Here is the output when running with tracing level 5:
    cache: Reading Signers from 1024 http://x.x.x.x:8080/MDA/webstart/VTSDBClient-SOK.jar | C:\Users\xxx\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\61\6b90d63d-4feb6af0-1.7-SNAPSHOT-.idx
    cache:  Read manifest for http://10.10.20.64:8080/MDA/webstart/VTSDBClient-SOK.jar: read=117 full=14269
    cache: Reading Signers from 1024 http://x.x.x.x:8080/MDA/webstart/VTSDBClient-SOK.jar | C:\Users\xxx\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\61\6b90d63d-4feb6af0-1.7-SNAPSHOT-.idx
    Weird! data/eez-de.shp has been loaded 77 time(s) previously but is now null
    Loader is com.sun.jnlp.JNLPClassLoaderSo getResourceAsStream managed to open the file 77 times before it suddenly returns null.
    From the trace it looks like it happens when the cache is doing " Reading Signers from 1024 ..." the second time for VTSDBClient-SOK.jar. Could it be related to bug 6911763 (http://bugs.sun.com/view_bug.do?bug_id=6911763)?
    What causes the cache to reread the Signers in general and is there a way to provoke it?
    Thanks
    Carsten

    Just a tad more info on this.
    Each time Thread.currentThread().getContextClassLoader().getResourceAsStream() returns null there is a:
    network: SyncFileAccess.openLock: handled OverlappingFileLockException, remainint TO : 10000in the log.
    My does does spawn multiple threads that accesses different resources located in the same jar file in the client. Could it be a problem with using Thread.currentThread().getContextClassLoader().getResourceAsStream() from multiple threads and a slow respose from the JNLPDownLoadServlet and some locking scheme used by the JNLP cache?
    cache: Reading Signers from 1024 http://x:8080/MDA/webstart/aislayer.jar | C:\Users\x\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\52\5e675934-678dbaa9-1.5-SNAPSHOT-.idx
    BinaryFile: trying to figure out how to handle [3] data/eez-dk.shp
    cache: Reading Signers from 1024 http://x:8080/MDA/webstart/aislayer.jar | C:\Users\x\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\52\5e675934-678dbaa9-1.5-SNAPSHOT-.idx
    BinaryFile: trying to figure out how to handle [3] data/eez-se.shp
    cache: Reading Signers from 1024 http://x:8080/MDA/webstart/aislayer.jar | C:\Users\x\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\52\5e675934-678dbaa9-1.5-SNAPSHOT-.idx
    BinaryFile: trying to figure out how to handle [3] data/12nm.shp
    cache: Reading Signers from 1024 http://x:8080/MDA/webstart/aislayer.jar | C:\Users\x\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\52\5e675934-678dbaa9-1.5-SNAPSHOT-.idx
    BinaryFile: trying to figure out how to handle [3] data/eez-pl.shp
    cache: Reading Signers from 1024 http://x:8080/MDA/webstart/aislayer.jar | C:\Users\x\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\52\5e675934-678dbaa9-1.5-SNAPSHOT-.idx
    BinaryFile: trying to figure out how to handle [3] data/danm_nav.shp
    BinaryFile: trying to figure out how to handle [3] data/europ_nav.shp
    BinaryFile: trying to figure out how to handle [3] data/eez-de.shp
    network: SyncFileAccess.openLock: handled OverlappingFileLockException, remainint TO : 10000

  • CurrentThread().getContextClassLoader().getResourceAsStream() doesn't work!

    After reading all this instructions about how to run an application that uses Eclipselink API in JWS offline mode:
    http://forums.sun.com/thread.jspa?threadID=5403895;
    http://forums.sun.com/thread.jspa?threadID=5404318;
    https://bugs.eclipse.org/bugs/show_bug.cgi?id=287718;
    http://dev.eclipse.org/newslists/news.eclipse.rt.eclipselink/msg00933.html.
    I am still having problems!
    Basically, the solution that solves all peoples problems was to look up the resource, in this case "META-INF/persistence.xml", using the command "Thread.currentThread().getContextClassLoader().getResourceAsStream(entryPath)".
    After modifying all the required classes, the application throws a "[EclipseLink-8034] JPQLException - Unknow entity type [Entity]", wich I suppose that is because the application wasn't able to find the "persistence.xml" file and them couldn't "resolve" the type that I am trying to find in the database.
    I am using the following Java/API versions:
    - JRE 1.6.0_02-b06
    - EclipseLink 2.1.0.v20100614-r7608
    Thanks.
    Edited by: eduardogdom on Sep 2, 2010 7:45 AM

    I've got the solution.
    Tks.

  • How to load a class in lib/file.jar

    Hi,
    I use jboss 4.0.2. and i have a jar-file from a third party in my server/default/lib that calls Thread.currentThread().getContextClassLoader().loadClass("foo"); My problem is that foo.class is never found and i dont know where i have to place this class. I would like to have a seperate folder for my classes, but i dont know how i should configure the classloader to find my classes. i dont want to package them in a jar.
    Thanks a lot!

    i tried this but the class was not found
    my simple question is:
    if a class in a jar that is placed in my jboss/server/default/lib-directory tries to load a class dynamic, where is it(classloader) looking? please tell me...
    thanks

  • Java mysql OK with Terminal but not OK with Apache local web server

    With terminal I have :
    CLASSPATH=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/:/Library/Java/Extensions/:./
    SUDO_GID=20
    SECURITYSESSIONID=210800
    _=/usr/bin/printenv
    127:/Library/WebServer/Documents/Java root# java TestMySQL
    2006-05-21 13:39:00.0 ************************************************** = OK
    127:/Library/WebServer/Documents/Java root#
    import java.sql.*;
    * mysql-connector-java-3.1.12-bin.jar
    *   % javac /Library/WebServer/Documents/Java/TestMySQL.java
    *   % java TestMySQL
    public class TestMySQL {
            public static void main(String argv[]) throws Exception {
                    // Load the driver class
                    Class.forName("org.gjt.mm.mysql.Driver");
    1                //Class theClass = null;
    2               //try {
    3                //    theClass = Thread.currentThread().getContextClassLoader().loadClass("org.gjt.mm.mysql.Driver");
    4                //}
    5                //catch (ClassNotFoundException e) {
    6                //    theClass = getClass().getClassLoader().loadClass("org.gjt.mm.mysql.Driver");
    7                //}
                    Connection conn = DriverManager.getConnection(
                            "jdbc:mysql:///test",
                    Statement stmt = conn.createStatement();
                    ResultSet rset = stmt.executeQuery("SELECT now();");
                    while (rset.next()) {
                            System.out.println(rset.getString(1));
                    // Close result set, statement and DB connection
                    rset.close();
                    stmt.close();
                    conn.close();
    }I have a simple TestMySQL.html file with applet TestMySQL.class in it.
    Nothing but "Applet TestMySQL not inited"
    When I uncomment the try/catch lines (lines 1 to 7) , java compiler generate an error... near getClass().getClassLoader().loadClass("org.gjt.mm.mysql.Driver");
    With "Class.forName("org.gjt.mm.mysql.Driver");" no problem.
    Running MacOS X 10.3.9, Apache/1.3.33 (Darwin) PHP/4.4.1 mod_ssl/2.8.24 OpenSSL/0.9.7i and JVM 1.4.2_09
    Thanks for help.
    P.S. This my first approach to java/mysql but I would like to see this short program running on my local web server ...
    Thanks.

    hi :-)
    can you post the stack trace?
    im not sure what is causing the error because of less info,
    but have you tried to copy the driver of mysql to tomcat lib folder?
    regards,

  • Error on writing a connector using WSIF to provision users.

    Hello All,
    I am writing a connector to provision users using WSIF. Everything works great through my IDE (eclipse on Windows XP), but when I drop the jar, map the adapter (using OIM 9.0.3, RH4, and weblogic 8.1 SP6) and invoke a process task I get the following error:
    The WSIFDefaultMapper class exists in the wsif.jar file and as far as I can tell, only one instance of that class file exists (did a grep on all jar files).
    Any pointers will be appreciated.
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    Caused by: org.apache.wsif.WSIFException: Unable to create new mapper; nested exception is:
    java.lang.ClassNotFoundException: org.apache.wsif.mapping.WSIFDefaultMapper
    at org.apache.wsif.mapping.WSIFMapperFactory.newMapper(WSIFMapperFactory.java:107)
    at org.apache.wsif.mapping.WSIFMapperFactory.newMapper(WSIFMapperFactory.java:52)
    at org.apache.wsif.base.WSIFServiceImpl.overrideMapper(WSIFServiceImpl.java:1106)
    at org.apache.wsif.base.WSIFServiceImpl.init(WSIFServiceImpl.java:938)
    at org.apache.wsif.base.WSIFServiceImpl.<init>(WSIFServiceImpl.java:299)
    at org.apache.wsif.base.WSIFServiceFactoryImpl.getService(WSIFServiceFactoryImpl.java:274)
    at com.netapp.webservice.DynamicInvoker.invokeMethod(DynamicInvoker.java:213)
    at com.netapp.webservice.DynamicInvoker.WSIF(DynamicInvoker.java:130)
    ... 56 more
    Caused by: java.lang.ClassNotFoundException: org.apache.wsif.mapping.WSIFDefaultMapper
    at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:199)
    at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:61)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:224)
    at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:41)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:219)
    at org.apache.wsif.mapping.WSIFMapperFactory.newMapper(WSIFMapperFactory.java:100)
    ... 63 more
    com.thortech.xl.dataobj.util.tcAdapterTaskException: Unable to create new mapper; nested exception is:
    java.lang.ClassNotFoundException: org.apache.wsif.mapping.WSIFDefaultMapper
    at com.thortech.xl.adapterGlue.ScheduleItemEvents.adpNTAPSERVICENOW.INSERT(adpNTAPSERVICENOW.java:108)
    at com.thortech.xl.adapterGlue.ScheduleItemEvents.adpNTAPSERVICENOW.implementation(adpNTAPSERVICENOW.java:50)
    at com.thortech.xl.client.events.tcBaseEvent.run(Unknown Source)
    at com.thortech.xl.dataobj.tcDataObj.runEvent(Unknown Source)
    at com.thortech.xl.dataobj.tcScheduleItem.runMilestoneEvent(Unknown Source)
    at com.thortech.xl.dataobj.tcScheduleItem.eventPostInsert(Unknown Source)
    at com.thortech.xl.dataobj.tcDataObj.insert(Unknown Source)
    Thanks,
    Sunny
    Edited by: user11989584 on Dec 1, 2009 4:36 PM

    I have narrowed this down to the following (some of this is a repetition, I am copying and pasting my post from a WSIF forum):
    I am using wsif wsif-2.0.1_IB3 to connect to a webservice to create user accounts. Everything works great in Eclipse.
    When I deployed my jars (application jars, wsif and dependencies) to weblogic 8.1 sp6 and generate a task through OIM that calls this adapter, I run into the following error:
    org.apache.wsif.WSIFException: Unable to create new mapper; nested exception is:
    java.lang.ClassNotFoundException: org.apache.wsif.mapping.WSIFDefaultMapper
    Caused by: java.lang.ClassNotFoundException: org.apache.wsif.mapping.WSIFDefaultMapper
    at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:199)
    at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:61)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:224)
    at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:41)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:219)
    at org.apache.wsif.mapping.WSIFMapperFactory.newMapper(WSIFMapperFactory.java:100)
    The WSIFMapperFactory.class exists in wsif.jar file and makes a call to newMapper but is unable to load org.apache.wsif.mapping.WSIFDefaultMapper that is in the same wsif.jar file.
    public static WSIFMapper newMapper() throws WSIFException {
    return newMapper(false);
    The line that it fails on is Class c = Class.forName(mapperClassNameBuffer.toString(), true, Thread.currentThread().getContextClassLoader());
    from the following code snippet in WSIFMapperFactory.class file
    try {
    Class c =
    Class.forName(
    mapperClassNameBuffer.toString(),
    true,
    Thread.currentThread().getContextClassLoader());
    return (WSIFMapper) c.newInstance();
    } catch (ClassNotFoundException cnf) {
    throw new WSIFException("Unable to create new mapper", cnf);
    } catch (Exception e) {
    throw new WSIFException("Unable to create new mapper", e);
    Any ideas on how to fix this?
    I modified some of the WSIF code to try using the following:
    Class c = Thread.currentThread().getContextClassLoader().loadClass(mapperClassNameBuffer.toString()); but it had the same effect.
    Again, the same code path works great standalone in Eclipse.
    Any help/pointers would be appreciated.

  • ClassLoader & java.policy

    Hi ,
    I am facing problem with the following code.
    ClassLoader loaderPrev = Thread.currentThread().getContextClassLoader();
    ClassLoader loader = URLClassLoader.newInstance(new URL[]{new URL(CodeBase)} , loaderPrev );
    ClassLoader loader = new URLClassLoader(urlList);
    Thread.currentThread().setContextClassLoader(loader) ;
    result = Thread.currentThread().getContextClassLoader().loadClass(className);
    This loads class successfully if I give "AllPermision" in my java.policy. But in real project I cann't do this. If I give only the http port in the java.policy file, it doesn't work . It gives socket permission denied exception.
    I appreciate if somebody can give some input on this.
    Thanks
    Surendra

    try to sign applets
    please check documents
    or search in the forums
    http://java.sun.com/security/signExample12/
    http://java.sun.com/j2se/1.4/docs/guide/plugin/developer_guide/rsa_signing.html
    renjith.

  • Unable to rollback using BMT in a stateless bean

    Hi,
    My stateless bean contains the following testing code
    UserTranaction ut = null;
    try{
    ut = context.getUserTransaction();
    ut.begin();
    // get database connection from OracleDataSource
    // via container
    // update a recored in db
    if (true)
    throw new Exception();
    ut.commit();
    } catch (Exception e){
    ut.rollback();
    } finally {
    // close connection
    I am using oracle 817 jdbc driver and when I execute the method,
    the changes in DB are not rolledback and there is no exception
    thrown. My questions are
    1). Is BMT really work in oc4j? Anyone try before?
    2). Is there any additional conditions/setting need to be done
    in order to make BMT work? such as dataSource setting, database
    configuration...
    3). Could anyone provide sample code with related settings?
    (especially what datasoure u are using)
    Thank you very much!!!

    Have you already tried to load the class like this:
    Thread.currentThread().getContextClassLoader.loadClass(actionName);
    Instead of using the same classloader that loaded your bean implementation, it uses the classloader given to the executer thread as the context classloader.
    (In many cases this will be the same, but I don't know how this is done in the implementation of your container).

  • Toplink Proxy Authentication with 10.1.3 problem

    Hi,
    I'm are using Toplink Proxy Authentication in a JSF application with SessionFacade pattern and have implemented a preLogin() method of oracle.itech.pil.utils.PILSessionEventManager (which implements SessionEventListener) as described in
    http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/dblgcfg008.htm. Due to Class Loader problem while loading of SessionEventManager, I'm explicitly loading the Class by doing this:
    try {
    Thread.currentThread().getContextClassLoader().loadClass("oracle.itech.pil.utils.PILSessionEventManager");
    catch(Exception exp) {
    System.out.println("Exception while loading class oracle.itech.pil.utils.PILSessionEventManager "+exp.toString());
    The SessionEventManager is loaded by doing this:
    session.getEventManager().addListener(new PILSessionEventManager());
    (Encountered while using <event-listener-class>oracle.itech.pil.events.PILSessionEventManager</event-listener-class> in sessions.xml file, so removed and added the same using session.getEventManager().addListener(new PILSessionEventManager()) )
    But now, I'm encountering ClassCastException during the login to my application
    The below pasted exception (oracle.oc4j.rmi.OracleRemoteException: java.lang.ClassCastException: oracle.itech.pil.utils.PILSessionEventManager) is coming when invoking line (Login)session.readObject(oracle.itech.pil.model.Login.class, expression);
    Code :
    XMLSessionConfigLoader xmlLoader =
    new XMLSessionConfigLoader("META-INF/sessions.xml");
    SessionManager sessionMgr = SessionManager.getManager();
    DatabaseSession session =
    (DatabaseSession)sessionMgr.getSession(xmlLoader, "serverSession",
    SessionFacadeEJBBean.class.getClassLoader());
    // Set Listener through Java code
    //session.getEventManager().addListener(new PILSessionEventManager());
    new PILSessionEventManager();
    System.out.println("I am at getLoginDetails after the listner...>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
    Login login = null;
    LoggedInBB loggedIn = null;
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression expression = null;
    // If username is not null
    System.out.println("The _uname is "+_uname);
    if (_uname != null) {
    expression = builder.get("uname").equalsIgnoreCase(_uname).and(builder.get("empno").equalsIgnoreCase(_empNo));
    if (expression != null) {
    System.out.println("expression != null >>>>>>>>>>>>>>");
    //login = (Login)session.readObject(oracle.itech.pil.model.Login.class, expression);
    login =(oracle.itech.pil.model.Login) (session.readAllObjects(oracle.itech.pil.model.Login.class, expression)).get(0);
    System.out.println("Login Object is "+login);
    Exception:
    [TopLink Info]: 2006.05.02 05:04:18.703--ServerSession(21707422)--TopLink, version: Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)
    [TopLink Info]: 2006.05.02 05:04:22.619--ServerSession(21707422)--serverSession login successful
    06/05/02 17:04:22 I am at getLoginDetails after the listner............>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    06/05/02 17:04:22 The _uname is admin
    06/05/02 17:04:22 expression != null >>>>>>>>>>>>>>
    [TopLink Warning]: 2006.05.02 05:04:22.639--ServerSession(21707422)--java.lang.ClassCastException: oracle.itech.pil.utils.PILSessionEventManager
    oracle.oc4j.rmi.OracleRemoteException: java.lang.ClassCastException: oracle.itech.pil.utils.PILSessionEventManager
         at com.evermind.server.ejb.EJBUtils.getUserException(EJBUtils.java:333)
         at com.evermind.server.ejb.interceptor.system.AbstractTxInterceptor.convertAndHandleMethodException(AbstractTxInterceptor.java:69)
         at com.evermind.server.ejb.interceptor.system.TxSupportsInterceptor.invoke(TxSupportsInterceptor.java:39)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.StatelessSessionEJBObject.OC4J_invokeMethod(StatelessSessionEJBObject.java:86)
         at SessionFacadeEJB_StatelessSessionBeanWrapper2.getLoginDetails(SessionFacadeEJB_StatelessSessionBeanWrapper2.java:172)
         at oracle.itech.pil.backing.LoginBB.LoginButton_action(LoginBB.java:182)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
         at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
         at oracle.adf.view.faces.component.UIXCommand.broadcast(UIXCommand.java:211)
         at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
         at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
         at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
         at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
         at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
         at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._invokeDoFilter(AdfFacesFilterImpl.java:367)
         at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._doFilterImpl(AdfFacesFilterImpl.java:336)
         at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl.doFilter(AdfFacesFilterImpl.java:196)
         at oracle.adf.view.faces.webapp.AdfFacesFilter.doFilter(AdfFacesFilter.java:87)
         at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
         at oracle.itech.pil.utils.PILFilter.doFilter(PILFilter.java:124)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:627)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451)
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:299)
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:187)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)
         Nested exception is:
    java.lang.ClassCastException: oracle.itech.pil.utils.PILSessionEventManager
         at oracle.toplink.sessions.SessionEventManager.preExecuteQuery(SessionEventManager.java:508)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:976)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:938)
         at oracle.toplink.publicinterface.Session.readAllObjects(Session.java:2458)
         at oracle.itech.pil.ejb.SessionFacadeEJBBean.getLoginDetails(SessionFacadeEJBBean.java:399)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.evermind.server.ejb.interceptor.joinpoint.EJBJoinPointImpl.invoke(EJBJoinPointImpl.java:35)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.interceptor.system.TxSupportsInterceptor.invoke(TxSupportsInterceptor.java:37)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:69)
         at com.evermind.server.ejb.StatelessSessionEJBObject.OC4J_invokeMethod(StatelessSessionEJBObject.java:86)
         at SessionFacadeEJB_StatelessSessionBeanWrapper2.getLoginDetails(SessionFacadeEJB_StatelessSessionBeanWrapper2.java:172)
         at oracle.itech.pil.backing.LoginBB.LoginButton_action(LoginBB.java:182)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
         at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
         at oracle.adf.view.faces.component.UIXCommand.broadcast(UIXCommand.java:211)
         at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
         at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
         at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
         at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
         at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
         at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._invokeDoFilter(AdfFacesFilterImpl.java:367)
         at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._doFilterImpl(AdfFacesFilterImpl.java:336)
         at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl.doFilter(AdfFacesFilterImpl.java:196)
         at oracle.adf.view.faces.webapp.AdfFacesFilter.doFilter(AdfFacesFilter.java:87)
         at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
         at oracle.itech.pil.utils.PILFilter.doFilter(PILFilter.java:124)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:627)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451)
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:299)
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:187)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)
    Any clue why this error, which i am facing since 10 days to complete my task
    Thanks In Advance
    Prashant

    James, what Venkat and Prashant are trying to do is something like this...
    1. If I connect to the DB using scott/tiger then in the preLogin method of the Toplink Session Listener class, the proxy user will connect using something like admin/welcome1 and in the database audit view, the name that shows up SHOULD BE that of admin and NOT of scott. This is called proxy authentication if it works fine.
    We developed the above scenario but in the audit logs, we still see scott instead of admin as the user who connected.
    2. This feature is available in the DB but our objective is to use it through TopLink
    Also see Toplink Proxy Authentication Not Working
    I hope I was able to explain the scenario clearly.
    Any help will be appreciated
    Regards,
    Amit

  • Applets and 3rd party jars

    Hi,
    I'm trying to use a 3rd party jar with an applet. I can access the functions just fine when using an applet viewer, but when I try deploying the applet from a web page I get classNotFound exceptions. How do I go about getting the applet to recognize the jar file?
    Thanks

    Eva, yes, if that class in one of the 3rd party jars wants to access your class directly, then it is necessary that your class is loaded by the same classloader that loads that 3rd party jar or even higher up the classloader hierarchy.
    Why do you consider putting your class library into applib "a bit rude"? As long as your classes are named distinctively so that they will not clash with other classes, it is not a problem.
    On the other hand, it seems that the design of that 3rd party class is not classloader friendly. Had it used something like the following to load a class that is undefined at the compile time, you might not have this problem.
       Class userClass = Thread.currentThread().getContextClassLoader().loadClass(nameOfUserDevelopedClass);
       Object plugin = userClass.newInstance();

  • Class.forName() debunked

    This issue is about: Dynamic loading and Inheritance.
    Debugging an odd ClassNotFoundException in a J2EE Application, I was involved investigating deeply Class.ForName(). This method - namely the version with only the class name as parameter - is used inside xsdbeans.jar, an optiopnal library, shipped with IBM WebSphere 5.x. Moving the jar from the EAR classloader to the server runtime classloader caused weird behavior on my app.
    I try to simplify the core question:
    Suppose class E extends B. Base class B declares an instance method, dynLoad(String name) that uses internally Class.forName(String name).
    Say 'e' an instance of E. Invoking e.dynLoad("Foo"), Class.forName("Foo") should use the ClassLoader of current class. But which is the 'current class': E or B? Is it the class of current object (E) or the declaring superclass (B)?
    My instinctive answer was: E. But my J2EE app was behaving as the current class was B. Indeed E and B may be defined by different classloaders, and this makes a big difference.
    A rapid lookup at Sun's docs confirmed my first hypothesis:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#forName(java.lang.String)
    > Returns the Class object associated with the class or interface with the given string name.
    Invoking this method is equivalent to:
    Class.forName(className, true, currentLoader)
    where currentLoader denotes the defining class loader of the current class.
    ok, this is a little misleading, but going on:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#forName(java.lang.String,%20boolean,%20java.lang.ClassLoader)
    > For example, in an instance method the expression:
    >
    Class.forName("Foo")
    is equivalent to:
    Class.forName("Foo", true, this.getClass().getClassLoader())
    Not equivocal. The current class is the class of current object, no matter (apparently) if the instance method is declared in a superclass.
    Right? Wrong. Here a minimal counter-example:
    //-- B.java
    import java.net.*;
    public class B {
        public void dynLoad(String name) throws Exception {
            System.out.println(getClass().getSuperclass()
                + " defining classloader is: "
                + getClass().getSuperclass().getClassLoader());
            System.out.println(getClass()
                + " defining classloader is: "
                + getClass().getClassLoader());
            System.out.println("\n1) Class.forName(\""+name+"\");");
            // Loading with 'currentLoader'
            Class.forName(name)
                .newInstance();
            System.out.println("\n2) Class.forName(\""+name
                +"\", true, this.getClass().getClassLoader());");
            // This should be equivalent (by Sun J2SE API spec)
            Class.forName(name, true, this.getClass().getClassLoader())
                .newInstance();
        public static void main(String[] args) {
            ClassLoader syscl = ClassLoader.getSystemClassLoader();
            if (!URLClassLoader.class.isInstance(syscl)) {
                System.err.println("Cannot continue the trick.");
                System.exit(1);
            URL[] urls = ((URLClassLoader)syscl).getURLs();
            // Yet Another ClassLoader
            URLClassLoader yacl = new URLClassLoader(urls) {
                // Force Parent-last delegation policy to assure
                // demanded classes are defined by _this_ classloader
                public Class loadClass(String name)
                    throws ClassNotFoundException {
                    Class c = findLoadedClass(name);
                    if (c == null) {
                        try {
                            // Simulate no visibility to base class to assure
                            // it is _not_ defined by this classloader too
                            if (name.equalsIgnoreCase("B")) {
                                throw new ClassNotFoundException();
                            c = findClass(name);
                        } catch (ClassNotFoundException e) {
                            c = getParent().loadClass(name);
                    return c;
            try {
                // Loading class E with a different classloader
                Class c = yacl.loadClass("E");
                c.getMethod("dynLoad", new Class[]{String.class})
                    .invoke(c.newInstance(), new Object[]{"Foo"});
            } catch (Exception ex) {
                ex.printStackTrace();
                System.exit(1);
    //-- E.java
    public class E extends B {
    //-- Foo.java
    public class Foo {
      public Foo() {
        System.out.println(getClass()
          + " defining classloader is: "
          + getClass().getClassLoader());
    }Running above B.main() produce the following output on Sun JDK 1.3, 1.4.2, 1.5:
    > class B defining classloader is: sun.misc.Launcher$AppClassLoader@3d200480
    class E defining classloader is: B$1@3d2c0480
    1) Class.forName("Foo");
    class Foo defining classloader is: sun.misc.Launcher$AppClassLoader@3d200480
    2) Class.forName("Foo", true, this.getClass().getClassLoader());
    class Foo defining classloader is: B$1@3d2c0480
    The evidence is that classloader used is not the same. in the case 1) it uses the classloader of superclass B. Hence the two form of Class.forName() invocation are not equivalent, as stated in Sun documentation.
    Disclosure
    The evidence is confirmed and explained looking at Sun's implementation of java.lang.Class.java and java.lang.ClassLoader.java: finally the Class.forName(String name) relies on sun.reflect.Reflection.getCallerClass(int) to find the famous 'current class' mentioned in the javadocs. This undocumented method returns the i-th caller class of current stack frames; each stack frame represents a method invocation coupled with its declaring class.
    I wonder why in Sun docs this poorly explained issue was remaining immutable from 1.3 to date. Furthermore: which was the intended behavior? Another reason to the long said "Class.forName() is evil..." or am I missing something?
    regards, Lorenzo

    Of course, it comes down to the question: What is the current class?
    Not something well defined. You are looking for this.getClass(), it's taking the class at compile time. If it went your way, woundn't that create an inconsistency in forName in static vs instance contexts?
    Actually I think the static approach is more natural, because it means that forName behaves the way that resolving external references work. Your way would also go against the spirit of Java security policies which requires references down the classloader chain something to be treated with suspision.
    The mechanism intended, I think, for these situations is the contextClassLoader property of Thread. When executing plugin type code the contextClassLoader should be set to the ClassLoader that loaded the plugin, and any references to resources or dynamic class loads from the plugin should be made using the contextClassLoader. This enables your shared library code to access classes and resources on behalf of the plugin code with access to classes and resources inside the plugin.
    Thus, if you write library code or other container stuff likely to be called from a plugin you should probably always use:
    Class cls = Thread.currentThread().getContextClassLoader().loadClass("foo");

  • Problem with dynamic class loading

    Hi,
    We have a class file in an external jar(outside ear) and access it in an ear using classloader.loadClass method. But if the class file is changed in jar, it gets hotdeployed in jboss but code which calls this class still refers to the old code.
    Class getClassByName(String className) throws ClassNotFoundException {
    Class theClass = null;
    try {
    theClass = Thread.currentThread().getContextClassLoader().loadClass(className);
    } catch (ClassNotFoundException e) {
    theClass = getClass().getClassLoader().loadClass(className);
    return theClass;
    When I looked into api I came to know that loadClass actually loads the class if it is not already exists. Can any one help me in writing thecustom class loader which loads the class everytime instead of checking previous instance before loading......
    Thanks,
    Kruthika

    You probably have to get rid of the class loader that loads the original version and start with a new class loader.

  • Problem using ant to create a jar...

    Hi,
    I am trying to create a JAR, and amongst other things include in that a directory called docs. I would like both the directory and its contents included, not just the contents.
    I can get this to work, but when using a property it doesn't!
    Within my jar task
                   <fileset dir=".">
                        <include name="doc/**"/>
                   </fileset>will work just fine. However,
                   <fileset dir=".">
                        <include name="${doc}/**"/>
                   </fileset>will not do anything, with doc defined as:
    <property name="doc" location="doc" />Does anyone have any ideas? Many thanks.

    Yes, that's pretty standard code (except you don't need the .newInstance() just loading the class does it).
    I haven't experimented much with Class-Path in jars, but I still think a ClassLoader problem is the most likely cause. Try something like this:
    try {
         Class driverClass = Thread.currentThread().getContextClassLoader().loadClass("com.mysql.jdbc.Driver");
         Driver driver = (Driver)driverClass.newInstance();
         java.util.Properties conProps = new java.util.Properties();
          conProps.setProperty("user", "root");
          conProps.setProperty("password", "");
         dbConnection = driver.connect("jdbc:mysql://127.0.0.1/bdd/", conProps);
    catch(ClassNotFoundException) {
    ....(Of course I might be way off track, and we might have missed something simpler).

  • Classload.load and Class.forName question

    I know there are several threads about this, but I have a doubt.
    I'm getting a ClassNotFoundException running the JUnitSampler of JMeter.
    This test is run by maven (using a specific plugin for it). This plugin creates a new Thread to call JMeter with all the parameters that needs.
    The class that the JUnitSampler is trying to run is in the classpath (is not jar).
    I know this because I run maven with -X parameter and it shows this:
    [DEBUG] Test Classpath :
    [DEBUG]   /path/to/project/target/classes
    [DEBUG]   /path/to/project/target/test-classesLooking at JUnitSampler code I can see this
    theclazz = Thread.currentThread().getContextClassLoader().loadClass(className.trim());Is there any reason that the class couldn't be found?

    No idea - it is your code.It's JMeter code, not mine.You said it couldn't find your test classes.
    >
    My original question was about if there were any
    difference in using
    Class.forName
    or
    Thread.currentThread().getContextClassLoader().loadClass
    No idea. You can print the class loader though.
    That was because the JUnitSampler is using the second
    option to instantiate the test classes, and
    I was receiving a ClassNotFoundException. That
    problem is now solved, because it can find the class,
    but is unable to cast it to TestCase.
    I want to know if there is a way to put my test
    classes in the ClassLoader that JMeter is using.You have an instance of some class.
    To create that class it was loaded by a class loader.
    You can get that class loader via the methods of java.lang.Class.
    You can use that class loader to load your class.
    That might or might not solve your problem.
    Because there are any number of ways it can fail to solve you problem. Below is one, one of many, that might do it.
    It won't solve it if you have already loaded your class via the system loaders which will happen if you use absolutely any reference to it.

Maybe you are looking for

  • How to hack into another computer on my  wireless network?

    Hi, just downloaded a program called "who is on my wifi" and it shows me that there are 2,3 people are on my network. sometimes my network gets slower. I want to connect to their computer and check what is going on on their desk top. to actually see

  • Problem with receiver jdbc CC

    Hi, Iam doing RFC to JDBC scenario.. The receiver JDBC adapte which i configured is giving me an error saying that "Unable to execute statement for table or stored procedure. 'HR_Employee' (Structure 'Statement') due to com.microsoft.sqlserver.jdbc.S

  • Intermittent WiFi Connections

    I have a new Apple Thunderbolt Display and new MacBook Air 2011 which after a 30-60 minutes loses the WiFi connectivity.  I am using the Bluetooth Magic Trackpad with the Bluetooth iMac Keyboard. Since I recently purchased the MacBook Air, I have bee

  • Change Document Icons

    For some reason all of my web related files (html, php, css) have all had there icons changed when viewing from dialog boxes. In the finder they look fine but in other applications and dialog boxes they have all changed to Adobe GoLive style icons. G

  • Beach ball now out of hand!

    Downloaded 250 raw images onto my separate hard drive and I now have the dreaded beach ball spinning for hours on end and I have to force quit Aperture - is there a way to 'reset' Aperture 2?