Beautiful ClassLoader Deserialization

Dear All,
I want to register a ClassLoader of mine so as to use it for a remote object deserialization. Normally, I get this object by RMI, as a Stub, and this Stub class is not locally in my classpath.
So I decide to download the class by itself from the client as a bytestream. I have the bytes, I invoke defineClass () with my classloader and there it is, I have the class as a Class object. But when it comes to Naming.lookup (), there you have it, the Java(TM) Virtual Machine, goes through the Bootstrap ClassLoader, then through some URLClassLoader and doesn't give a damn about my classloader, to ask it if it knows anything about this Stub object it's trying to deserialize.
Now I really wonder if it's possible to have dynamic class registration inside a Java Virtual Machine, so as not only to create Class objects (as in Class.forName (name, .., ClassLoader)), but as in get the object as bytes, get the object's class as bytes and there you go, using the methods and stuff.
Could anyone request more information?
Yours,
Ben

Dear All,
Time's up! The issue was solved. I am only waiting for Java to ease this intricate process. Until then, whoever owns information wins.
Yours,
Ben

Similar Messages

  • Problem with XMLDecoder and a custom ClassLoader

    NOTE: Posted over in Serialization forum as more appropriate there, sorry for the crosspost but didn't notice that forum at first. Please direct any replies there.
    I am implementing an application based around Java Plugin Framework (jpf.sourceforge.net). In short one consequence of this framework is that each plugin uses its own classloader with scope of that plugins classes.
    One plugin I am using requires the ability to deserialize objects from a javabean xml file. I am using XMLDecoder to do this, and I used the constructor to pass the current plugin ClassLoader to it.
    This however only partially seems to work, this is a shortened extract from an example xml
    <java version="1.5.0" class="java.beans.XMLDecoder">
    <object class="usermanager.javabeans.BeanUser">
      <string>drftpd</string>
      <void property="downloadedBytes">
       <long>737132544</long>
      </void>
      <void property="hostMaskCollection">
       <void method="add">
        <object class="usermanager.HostMask">
         <string>*@*</string>
        </object>
       </void>
      </void>
       <void property="keyedMap">
       <void method="put">
        <object class="dynamicdata.Key">
         <class>commands.UserManagement</class>
         <string>slots</string>
         <class>java.lang.Integer</class>
        </object>
        <int>0</int>
       </void>
    etc...Now without passing XMLDecoder a ClassLoader as would be expected I get a ClassNotFoundException for the first <object>.
    However if I pass XMLDecoder the correct ClassLoader it reads the xml fine until it reaches <class>commands.UserManagement</class> at which point again I get a ClassNotFoundException.
    Here is the stacktrace from that exception:
    java.lang.ClassNotFoundException: commands.UserManagement
         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:242)
         at com.sun.beans.ObjectHandler.classForName(ObjectHandler.java:67)
         at com.sun.beans.ObjectHandler.classForName(ObjectHandler.java:54)
         at java.beans.Statement.invoke(Statement.java:140)
         at java.beans.Expression.getValue(Expression.java:98)
         at com.sun.beans.MutableExpression.getValue(ObjectHandler.java:400)
         at com.sun.beans.ObjectHandler.getValue(ObjectHandler.java:106)
         at com.sun.beans.ObjectHandler.endElement(ObjectHandler.java:327)
         at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:625)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1241)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1685)
         at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
         at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
         at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
         at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
         at javax.xml.parsers.SAXParser.parse(SAXParser.java:344)
         at javax.xml.parsers.SAXParser.parse(SAXParser.java:120)
         at java.beans.XMLDecoder.readObject(XMLDecoder.java:205)
         at usermanager.javabeans.BeanUserManager.loadUser(BeanUserManager.java:128)
    Now after looking through some of the source it appears to me at least that XMLDecoder when processing an <object> uses an ObjectHandler with the ClassLoader as a parameter, however a class contained within a <class> element gets handled by Statement.invoke() which uses an ObjectHandler without a ClassLoader specified thus using the standard ClassLoader.
    I've managed to work around it for now by setting the contextClassLoader to the correct one before calling readObject() in XMLDecoder and then reverting it back immediately after, but this feels like somewhat of a hack to me.
    I would've expected it to have been properly handled when passing the ClassLoader to XMLDecoder rather than like it is.
    Anyone know if this is intended behaviour or a bug? and if the former is there any recommended way to deal with this other than the one I'm currently using.
    NOTE: Posted over in Serialization forum as more appropriate there, sorry for the crosspost but didn't notice that forum at first. Please direct any replies there.
    Message was edited by:
    djb61
    NOTE: Reposting to Serialization

    You can provide a cell renderer to the JTree to paint the checkBox.
    The following code checks or unchecks the box with each click also:
    _tree.setCellRenderer(new DefaultTreeCellRenderer()
      private JCheckBox checkBox = null;
      public Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus)
        // Each node will be drawn as a check box
        if (checkBox == null)
          checkBox  = new JCheckBox();
          checkBox .setBackground(tree.getBackground());
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
        checkBox.setText(node.getUserObject().toString());
        checkBox.setSelected(selected);
        return checkBox;
    });

  • Error trying to deserialize EJB HomeHandle and EJB Handle classes

    I get the following exception when I try to deserialize both a javax.ejb.HomeHandle and a javax.ejb.Handle.  I serialize and immediately deserialize within the same application using the same classloader so there are not alot of external variables that may cause the problem.  Any ideas on why I can't deserialize an ejb handle?
    The reason I am doing this is to try and get around the need to reference another application just to call a remote method in that application.  I want to serialize the remote home interface handle or the remote component interface handle and deserialize it using my local application classloader.  Does anybody know if this would work?
    #1#java.lang.ClassNotFoundException: Loader /L_service:ejb could not load class turtle.registry.SBRegistryRemoteHome
         at com.sap.vmc.core.impl.sapjvm.sharing.NativeSharedClassLoaderImpl.loadClass(NativeSharedClassLoaderImpl.java:609)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:265)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:333)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:242)
         at java.io.ObjectInputStream.resolveProxyClass(ObjectInputStream.java:656)
         at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1499)
         at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1462)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1698)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
         at com.sap.engine.services.ejb3.runtime.impl.LocalHandleDelegate.readStub(LocalHandleDelegate.java:177)
         at com.sap.engine.services.ejb3.runtime.impl.ServerHandleDelegate.readStub(ServerHandleDelegate.java:64)
         at com.sap.engine.services.ejb3.runtime.impl.LocalHandleDelegate.readEJBHome(LocalHandleDelegate.java:101)
         at com.sap.engine.services.ejb3.runtime.impl.StatelessHomeHandleImpl.readObject(StatelessHomeHandleImpl.java:73)
         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 java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:946)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1818)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1718)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
         at turtle.common.util.SerializationHelper.convertObject(SerializationHelper.java:43)
         at turtle.common.server.connect.RemoteFactory.getRemoteSAPWAS(RemoteFactory.java:206)
         at turtle.common.server.connect.RemoteFactory.getRemote(RemoteFactory.java:46)
         at turtle.common.server.connect.RemoteProxyFactory.getRemote(RemoteProxyFactory.java:99)
         at turtle.common.server.connect.RemoteProxyFactory.create(RemoteProxyFactory.java:91)
         at turtle.common.server.connect.RemoteProxyFactory.createProxy(RemoteProxyFactory.java:52)
         at turtle.server.runtime.registry.RegistryFacade.connectToRegistry(RegistryFacade.java:932)
         at turtle.server.runtime.registry.RegistryFacade.getGenericRegistryBI(RegistryFacade.java:987)
         at turtle.server.runtime.registry.RegistryFacade.unbindObjectsInProject(RegistryFacade.java:857)
         at turtle.registry.ProjectRegistrar$1$1.run(ProjectRegistrar.java:130)
         at java.security.AccessController.doPrivileged(Native Method)
         at javax.security.auth.Subject.doAs(Subject.java:337)
         at turtle.common.security.auth.AuthenticatorBase.doAs(AuthenticatorBase.java:387)
         at turtle.registry.ProjectRegistrar$1.run(ProjectRegistrar.java:172)
         at java.util.TimerThread.mainLoop(Timer.java:512)
         at java.util.TimerThread.run(Timer.java:462)

    Has anyone been able to get this to work?  Or can anyone confirm that this is a bug?
    As a simpler test, I modified the UserManagementBean of the Car Rental example application.  I added some code in the register method that serializes and deserializes the Handle object obtained from the SessionContext.getEJBObject().getHandle() method.  The serialization completes without issue.  However, I get the same error when trying to deserialize the Handle object:
    java.lang.ClassNotFoundException: Loader /L_service:ejb could not load class com.sap.engine.examples.epf.ejb.controller.customer.UserManagementHome
         at com.sap.vmc.core.impl.sapjvm.sharing.NativeSharedClassLoaderImpl.loadClass(NativeSharedClassLoaderImpl.java:609)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:265)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:333)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:242)
         at java.io.ObjectInputStream.resolveProxyClass(ObjectInputStream.java:656)
         at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1499)
         at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1462)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1698)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
         at com.sap.engine.services.ejb3.runtime.impl.LocalHandleDelegate.readStub(LocalHandleDelegate.java:177)
         at com.sap.engine.services.ejb3.runtime.impl.ServerHandleDelegate.readStub(ServerHandleDelegate.java:64)
         at com.sap.engine.services.ejb3.runtime.impl.LocalHandleDelegate.readEJBHome(LocalHandleDelegate.java:101)
         at com.sap.engine.services.ejb3.runtime.impl.StatelessHomeHandleImpl.readObject(StatelessHomeHandleImpl.java:73)
         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 java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:946)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1818)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1718)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
         at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1917)
         at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1841)
         at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1718)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
         at com.sap.engine.examples.epf.ejb.controller.customer.SerializationUtils.deSerialize(SerializationUtils.java:33)
         at com.sap.engine.examples.epf.ejb.controller.customer.SerializationUtils.deepClone(SerializationUtils.java:59)
         at com.sap.engine.examples.epf.ejb.controller.customer.UserManagementBean.register(UserManagementBean.java:75)

  • Get a ClassLoader determined at runtime into the classpath

    The class MyClass is dertermined at runtime and loaded from an URLClassLoader, which can not be in the original classpath.
    An objectInputStream is deserializing classes from that type, but it throws an exception and can not resolve that class, because it isn't in the classpath.
    Because the URLClassLoader is a JarFile, it is easy to iterate to them, but trying to do loadClass for each of them didn't enable the objectInputStream to recognize them.
    Some ideas where to create bytestreams from my class and extend a classloader to load those, but is there no easier way to get a classloader into the classpath or a single class into the list of classes of the classpath?

    I think that the main problem is that the ObjectInputStream cannot find the proper ClassLoader when deserializing.
    I have never tried it, but I think what needs to be done is to set the ContextClassLoader property of the thread that is doing the deserialization.
    Something like this:
    ClassLoader cl = new URLClassLoader(....);
    Thread t = Thread.currentThread();
    t.setContextClassLoader(cl);
    ObjectInputStream ois = new ObjectInputStream(....);
    Object o = ois.readObject();
    .

  • Deserialization of a custom class

    Hello, everybody!
    My situation. I'm developing a program with help of well-known JGraph library (www.jgraph.com). This program will use serialization/deserialization for saving/opening results of work. The JGraph library contains JGraph class that implements Serializable interface. This class contains all fields that I need for save/open. But some fields are my own classes. And it weren't a problem but it is. Serialization of JGraph object goes good. But Deserialization throws the ClassNotFoundException: myPackage.MyClass. I couldn't solve this problem for two days, but the solution was weird for me: I've just removed jgraph.jar from lib/ext directory and and used the -classpath for pointing the jgraph.jar
    Can anybody explain me why it works with -classpath and why it doesn't work with ext directory?
    Thank you!

    Classloaders are organised in a hierarchy, and any given classloader can only see classes it defines and classes defined by it's parents (recursively).
    The runtime library (rt.jar) is loaded by one classloader. This is the parent of a separate classloader which loads the jars from lib/ext. Finally, this classloader is the parent of another classloader which processes the -cp jvm parameter.
    From that you can see that classes loaded from lib/ext will not be able to see any of your classes by default. (They can, but they have to be given or somehow discover an appropriate classloader which is able to see your classes.)

  • Deserialization issues in CEP environment

    Hi,
    I'm running Coherence in a CEP environment, though I'm not making use of the CEP API inside the Spring context. The cache is initialized in this most basic way:
    CacheFactory.getCache(SomeAbstract.class);
    It resides in bundleA, where SomeAbstractBase.class also is. There are several implementations of this base class across multiple bundles, and I would like to make use of Coherence to store these instances.
    I was expecting deserialization issues so I figured this would work, but it doesn't. What am I doing wrong here? What is the best approach to do this?
        Map<Long, ClassLoader> classLoaderMap = new HashMap<Long, ClassLoader>();
        public SomeAbstractBase put(SomeAbstractBase so) {
            ClassLoader old = cache.getCacheService().getContextClassLoader();
            try {
                cache.getCacheService().setContextClassLoader(so.getClass().getClassLoader());
                classLoaders.put(so.getId(), so.getClass().getClassLoader());
                return (SomeAbstractBase) cache.put(so.getId(), so);
            } finally {
                cache.getCacheService().setContextClassLoader(old);
       public SomeAbstractBase get(Long id) {
            ClassLoader old = cache.getCacheService().getContextClassLoader();
            try {
                cache.getCacheService().setContextClassLoader(classLoaderMap.get(id));
                return (SomeAbstractBase) cache.get(id);
            } finally {
                cache.getCacheService().setContextClassLoader(old);
       }

    Jarell wrote:
    Hi Andy,
    andypiper wrote:
    Setting the CCL of the CacheService is a one-shot deal, it cannot actually be changed once set (you have to shutdown the service and restart to do something different).Completely forgot about this as you mentioned in another thread.
    You can also set the bundle CL as the CCL for invocations, but this may not always be necessary.How do I do this? I want it to be flexible enough to accomodate any future implementation that will be deployed in the osgi environment.Implement BeanClassLoaderAware, then when you make the call do something like:
    ClassLoader saveCcl = Thread.currentThread().getContextClassLoader();
    try {
    Thread.currentThread().setContextClassLoader(beanClassLoader);
    // do call here
    } finally {
    Thread.currentThread().setContextClassLoader(saveCcl);
    Note that if you are invoking OSGi services then Spring-DM will do this for you if you set the appropriate attribute on the reference definition.
    We use hessian in our product which has much the same requirements as you and we actually found that it was difficult to avoid doing DynamicImport-Package: * in the bundle doing the serialization.

  • XML-Deserialize with JAXB

    Hello!
    I'm new to JAXB so maybe my question is a newbie question.
    Why can I deserialize the following XML:
    <ns3:vida xmlns:ns3="http://cpsnet.de/dms/schnittstellen/volvo/vida_dms" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    </ns3:vida> but I can't deserialize this one:
    <vida xmlns="http://cpsnet.de/dms/schnittstellen/volvo/vida_dms" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    </vida>As far as I understand XML right now, they are both the same. Aren't they?
    The Unmarshaller returns the Object for the first XML - but returns null on the second one...

    Well... once again this was a ClassLoader problem... solved!

  • ClassNotFound Message when trying to deserialize data from an applet

    Hi,
    I have an applet that reads data from a web-server. The data was created by serializing a custom class (Test.java). The serialization format is not the standard one, but XML. This is reached by using the JSX-library (http://www.jsx2.com).
    My HTML-file (Test.html) looks like that:
    <html>
    <applet width="400"
    height="200"
         code="Test.class"
         codebase="./"
         archive="JSX2.0.9.4.jar">
    </applet>
    </html>
    Both, the Test.class and JSX2.0.9.4.jar are stored in the same directory. The Applet reads the serialization data of "Test" instances and tries to deserialize them. But when started, the following error message appears:
    Java VM version: 1.4.1_02
    Java VM vendor: Sun Microsystems Inc.
    java.lang.ClassNotFoundException: Test
    at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at JSX.ObjectReader$Cache.getClass(ObjectReader.java:1503)
    at JSX.ObjectReader$Cache.getClassCache(ObjectReader.java:1511)
    at JSX.ObjectReader.object(ObjectReader.java:796)
    at JSX.ObjectReader.readObject(ObjectReader.java:381)
    at JSX.ObjectReader.readObjectOverride(ObjectReader.java:342)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:318)
    at Test.read(Test.java:49)
    at Test.start(Test.java:72)
    at org.kde.kjas.server.KJASAppletStub$1.run(KJASAppletStub.java:102)
    at java.lang.Thread.run(Thread.java:536)
    When reading serialized data of classes included in the JRE, i.e. an ArrayList, everything works fine.
    I think it is a kind of CLASSPATH problem, because "Test.class" can not be found although it is in the same directory as the Test.html file. So how can I fix this problem?
    Thanks in advance
    Markus

    Make sure your 'CLASSPATH' contains '.'. However, it
    should because you are compiling your applets fine.
    Also try specifying a path to your class when
    loading. If it's in a package, you have to specify
    that, or include the class directory in your
    CLASSPATH.Hey Devyn, it can't be a classpath problem. It's an applet; if run in the browser, there is no way to specify a classpath short of entering a jar in the archive parameter.
    How are you deserializing the applet?

  • Object deserialization and specific classloaders

    Hi,
    I must load jars during the runtime in a specific classloaders, it's works, but how could i use this class loader to deserialize object i receive from wire ? is it possible to include my specific classloader in the search tree of the main classloader ?
    thanks in advance.
    Francois

    871637 wrote:
    how could i use this class loader to deserialize object i receive from wire ?You don't. You use a classloader to load a class.
    is it possible to include my specific classloader in the search tree of the main classloader ?No. If you want your classloader to load a class, you have to make sure that class is not on the classpath, else it will be loaded by the system classloader.

  • Alternatives to needing class file during deserialization?

    Hi,
    I'm trying to find a way of deserializing an object without requiring its class file (eg, class A) to be present. In that case the JVM instance that's deserializing an instance of class A wouldn't need to worry about needing to access the class A from its classpath (file "A.class") or from any other source (such as a custom classloader loading class A's bytecodes over the network) in order to deserialize an instance of class A, except when the source is the serialization stream itself -- all data needed for serialization would be contained only within the serialization stream.
    I believe this should be doable by first serializing an instance of class java.lang.Class that represents class A (since java.lang.Class instances are serializable), and then serializing the instance of class A, as explained below. This technique isn't working, and I'm wondering if anyone knows why, and if there are other known techniques for accomplishing the same objective.
    I start out with these classes as a test that serialization is working:
    The class whose instance I'm serializing/deserializing:
    class A implements java.io.Serializable {
         public int x = 5;
    }Serialization code:
    import java.io.*;
    class Serialize {
         public static void main(String[] args) throws Exception {
              FileOutputStream fos = new FileOutputStream("a.ser");
              ObjectOutput out = new ObjectOutputStream(fos);
              A aRef = new A();
              out.writeObject(aRef);
              out.flush();
              out.close();
    }Deserialization code:
    import java.io.*;
    class Deserialize {
         public static void main(String[] args) throws Exception {
              FileInputStream fis = new FileInputStream("a.ser");
              ObjectInput in = new ObjectInputStream(fis);
              A aRef = (A)in.readObject();
              in.close();
              System.out.println(aRef.x); //expect 5
    }Here's what I do:
    (1) javac A.java Serialize.java Deserialize.java
    (2) java Serialize
    (3) java Deserialize
    This works fine, and prints "5" as expected.
    Now that I know that this base case works, I next try to serialize an instance of class java.lang.Class into the stream. This instance will represent class A, and can be obtained by specifying the literal "A.class" in the source code as shown below. Then I serialize an instance of class A as before. I'll then repeat step (1) and (2), erase the "A.class" file, and then do step 3. Here's the new code:
    The class whose instance I'm serializing/deserializing (same as before):
    class A implements java.io.Serializable {
         public int x = 5;
    }Serialization code:
    import java.io.*;
    class Serialize {
         public static void main(String[] args) throws Exception {
              FileOutputStream fos = new FileOutputStream("a.ser");
              ObjectOutput out = new ObjectOutputStream(fos);
              Class clazz = A.class;
              out.writeObject(clazz);
              A aRef = new A();
              out.writeObject(aRef);
              out.flush();
              out.close();
    }Deserialization code:
    import java.io.*;
    class Deserialize {
         public static void main(String[] args) throws Exception {
              FileInputStream fis = new FileInputStream("a.ser");
              ObjectInput in = new ObjectInputStream(fis);
              Class clazz = (Class)in.readObject(); //shouldn't this cause class A to be loaded?
              A aRef = (A)in.readObject();
              in.close();
              System.out.println(aRef.x); //expect "5"
              System.out.println(clazz); //expect "class A"
    }And now the revised steps:
    (1) javac A.java Serialize.java Deserialize.java
    (2) java Serialize
    *(3) Delete the "A.class" file because it shouldn't be needed since we're now serializing an instance of class Class that should fully represent class A.*
    (4) java Deserialize
    Bam... exception thrown at step 4:
    Exception in thread "main" java.lang.ClassNotFoundException: A
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at java.io.ObjectInputStream.resolveClass(Unknown Source)
            at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
            at java.io.ObjectInputStream.readClassDesc(Unknown Source)
            at java.io.ObjectInputStream.readClass(Unknown Source)
            at java.io.ObjectInputStream.readObject0(Unknown Source)
            at java.io.ObjectInputStream.readObject(Unknown Source)
            at Deserialize.main(Deserialize.java:6)Why is a ClassNotFoundException thrown? Class A is already loaded automatically after the instance of class Class is deserialized, isn't it? It's possible that an instance of class Class doesn't store method bytecodes -- I'm not sure about that. But even so, I purposefully did not include any methods in class A -- I just made the data member public (bad form, but this is just a test).
    Any ideas why this isn't working, or a way(s) to accomplish the goal?
    Thanks,
    Will

    serializing java.lang.Class instance does not really write the content of the class file in to the stream. It only write a class descriptor. At the read end it will try to locate the class file locally and validate the class file with the information in the descriptor.
    You need to have mechanism to send the data of the class file itself in to the stream before sending the instance.
    take a look at the annotateClass and resolveClass methods in ObjectOutputStream and ObjectInputStream

  • "Could not deserialize session data" error during sign out

    Hello,
    I have an application deployed on WLS 8.1, one instance, no clustering. The application EAR contains 1 web module and 2 ejb modules. When I try to sign out(I use Single Sign-On for Multiple Applications - a sign out application deployed separately) I receive the attached error.
    Notes: my session is serializable - I did a test that serialize and deserialize the session and I have no errors.
    Q: Why does WLS try to deserialize the session data during sign out? I don't use any session persistance/replication.
    The error ClassNotFoundException from my point of view is normal: UsersTableModel(from web modile) is not visible from the Application Classloader.
    Here is the error:
    <> <BEA-100028> <Could not deserialize session data.
    java.lang.ClassNotFoundException: xxx.controller.actions.UsersTableModel: This error could indicate that a component was deployed on a cluster member but not other members of that cluster. Make sure that any component deployed on a server that is part of a cluster is also deployed on all other members of that cluster
         at weblogic.j2ee.ApplicationManager.loadClass(Ljava.lang.String;Ljava.lang.String;Ljava.lang.String;Ljava.lang.ClassLoader;Z)Ljava.lang.Class;(ApplicationManager.java:344)
         at weblogic.j2ee.ApplicationManager.loadClass(Ljava.lang.String;Ljava.lang.String;Ljava.lang.String;Ljava.lang.ClassLoader;)Ljava.lang.Class;(ApplicationManager.java:258)
         at weblogic.j2ee.ApplicationManager.loadClass(Ljava.lang.String;Ljava.lang.String;Ljava.lang.String;)Ljava.lang.Class;(ApplicationManager.java:253)
         at weblogic.j2ee.ApplicationManager.loadClass(Ljava.lang.String;Ljava.lang.String;)Ljava.lang.Class;(ApplicationManager.java:216)
         at weblogic.common.internal.WLObjectInputStream.resolveClass(Ljava.io.ObjectStreamClass;)Ljava.lang.Class;(WLObjectInputStream.java:48)
         at java.io.ObjectInputStream.readNonProxyDesc(Z)Ljava.io.ObjectStreamClass;(Unknown Source)
         at java.io.ObjectInputStream.readClassDesc(Z)Ljava.io.ObjectStreamClass;(Unknown Source)
         at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Unknown Source)
         at java.io.ObjectInputStream.readObject0(Z)Ljava.lang.Object;(Unknown Source)
         at java.io.ObjectInputStream.readObject()Ljava.lang.Object;(Unknown Source)
         at weblogic.servlet.internal.AttributeWrapper.convertBytesToObject([B)Ljava.lang.Object;(AttributeWrapper.java:173)
         at weblogic.servlet.internal.AttributeWrapper.getObject(Z)Ljava.lang.Object;(AttributeWrapper.java:114)
         at weblogic.servlet.internal.AttributeWrapper.getObject()Ljava.lang.Object;(AttributeWrapper.java:69)
         at weblogic.servlet.internal.session.SessionData.removeAttribute(Ljava.lang.String;Z)Ljava.lang.Object;(SessionData.java:614)
         at weblogic.servlet.internal.session.SessionData.removeAttribute(Ljava.lang.String;)V(SessionData.java:596)
         at weblogic.servlet.internal.session.SessionData.remove()V(SessionData.java:808)
         at weblogic.servlet.internal.session.MemorySessionContext.invalidateSession(Lweblogic.servlet.internal.session.SessionData;)Z(MemorySessionContext.java:69)
         at weblogic.servlet.internal.session.SessionData.invalidate()V(SessionData.java:750)
         at weblogic.servlet.security.ServletAuthentication.invalidateAll(Ljavax.servlet.http.HttpServletRequest;)Z(ServletAuthentication.java:184)
         at xxx.framework.authentication.WebAuthenticationHelper.invalidateSessions(Ljavax.servlet.http.HttpServletRequest;)V(WebAuthenticationHelper.java:574)
         at xxx.framework.authentication.WebAuthenticationHelper.closeSession(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)V(WebAuthenticationHelper.java:523)
         at xxx.framework.authentication.WebAuthenticationHelper.logout(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)V(WebAuthenticationHelper.java:250)
         at xxx.yyy.ViewDispatcher.process(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)V(ViewDispatcher.java:75)
         at xxx.yyy.ViewDispatcher.doGet(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)V(ViewDispatcher.java:42)
         at javax.servlet.http.HttpServlet.service(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)V(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;)V(HttpServlet.java:853)
         at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run()Ljava.lang.Object;(ServletStubImpl.java:996)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;Lweblogic.servlet.internal.FilterChainImpl;)V(ServletStubImpl.java:419)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;)V(ServletStubImpl.java:315)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run()Ljava.lang.Object;(WebAppServletContext.java:6452)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Lweblogic.security.subject.AbstractSubject;Ljava.security.PrivilegedAction;)Ljava.lang.Object;(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(Lweblogic.security.acl.internal.AuthenticatedSubject;Lweblogic.security.acl.internal.AuthenticatedSubject;Ljava.security.PrivilegedAction;)Ljava.lang.Object;(SecurityManager.java:118)
    Edited by: user11291053 on 22-Jun-2009 02:52
    Edited by: user11291053 on 22-Jun-2009 03:01
    Edited by: user11291053 on 23-Jun-2009 01:42

    When OptimisticSerialization is turned on, WebLogic server does not serialize-deserialize context and request attributes upon getAttribute(name) when a request gets dispatched across servlet contexts. This means you will need to make sure that the attributes common to Web applications are scoped to a common parent classloader (they are application-scoped) or placed in the system classpath if the two Web applications do not belong to the same application.
    When OptimisticSerialization is turned off (which is the default) WebLogic Server does serialize-deserialize context and request attributes upon getAttribute(name) to avoid the possibility of ClassCastExceptions. The value of OptimisticSerialization can also be overridden for specific Web applications by setting the optimistic-serialization value in weblogic.xml.
    [http://edocs.bea.com/wls/docs100/ConsoleHelp/pagehelp/Corecoredomaindomainconfigwebapptitle.html]
    [http://e-docs.bea.com/wls/docs90/webapp/weblogic_xml.html#1067857]
    I hope this helps :)

  • Simple Transformation to deserialize an XML file into ABAP data structures?

    I'm attempting to write my first simple transformation to deserialize
    an XML file into ABAP data structures and I have a few questions.
    My simple transformation contains code like the following
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates"
                  xmlns:pp="http://www.sap.com/abapxml/types/defined" >
    <tt:type name="REPORT" line-type="?">
      <tt:node name="COMPANY_ID" type="C" length="10" />
      <tt:node name="JOB_ID" type="C" length="20" />
      <tt:node name="TYPE_CSV" type="C" length="1" />
      <tt:node name="TYPE_XLS" type="C" length="1" />
      <tt:node name="TYPE_PDF" type="C" length="1" />
      <tt:node name="IS_NEW" type="C" length="1" />
    </tt:type>
    <tt:root name="ROOT2" type="pp:REPORT" />
        <QueryResponse>
        <tt:loop ref="ROOT2" name="line">
          <QueryResponseRow>
            <CompanyID>
              <tt:value ref="$line.COMPANY_ID" />
            </CompanyID>
            <JobID>
              <tt:value ref="$line.JOB_ID" />
            </JobID>
            <ExportTypes>
              <tt:loop>
                <ExportType>
                   I don't know what to do here (see item 3, below)
                </ExportType>
              </tt:loop>
            </ExportTypes>
            <IsNew>
              <tt:value ref="$line.IS_NEW"
              map="val(' ') = xml('false'), val('X') = xml('true')" />
            </IsNew>
          </QueryResponseRow>
          </tt:loop>
        </QueryResponse>
        </tt:loop>
    1. In a DTD, an element can be designated as occurring zero or one
    time, zero or more times, or one or more times. How do I write the
    simple transformation to accommodate these possibilities?
    2. In trying to accommodate the "zero or more times" case, I am trying
    to use the <tt:loop> instruction. It occurs several layers deep in the
    XML hierarchy, but at the top level of the ABAP table. The internal
    table has a structure defined in the ABAP program, not in the data
    dictionary. In the simple transformation, I used <tt:type> and
    <tt:node> to define the structure of the internal table and then
    tried to use <tt:loop ref="ROOT2" name="line"> around the subtree that
    can occur zero or more times. But every variation I try seems to get
    different errors. Can anyone supply a working example of this?
    3. Among the fields in the internal table, I've defined three
    one-character fields named TYPE_CSV, TYPE_XLS, and TYPE_PDF. In the
    XML file, I expect zero to three elements of the form
    <ExportType exporttype='csv' />
    <ExportType exporttype='xls' />
    <ExportType exporttype='pdf' />
    I want to set field TYPE_CSV = 'X' if I find an ExportType element
    with its exporttype attribute set to 'csv'. I want to set field
    TYPE_XLS = 'X' if I find an ExportType element with its exporttype
    attribute set to 'xls'. I want to set field TYPE_PDF = 'X' if I find
    an ExportType element with its exporttype attribute set to 'pdf'. How
    can I do that?
    4. For an element that has a value like
    <ErrorCode>123</ErrorCode>
    in the simple transformation, the sequence
    <ErrorCode>  <tt:value ref="ROOT1.CODE" />  </ErrorCode>
    seems to work just fine.
    I have other situations where the XML reads
    <IsNew value='true' />
    I wanted to write
    <IsNew>
            <tt:value ref="$line.IS_NEW"
            map="val(' ') = xml('false'), val('X') = xml('true')" />
           </IsNew>
    but I'm afraid that the <tt:value> fails to deal with the fact that in
    the XML file the value is being passed as the value of an attribute
    (named "value"), rather than the value of the element itself. How do
    you handle this?

    Try this code below:
    data  l_xml_table2  type table of xml_line with header line.
    W_filename - This is a Path.
      if w_filename(02) = '
        open dataset w_filename for output in binary mode.
        if sy-subrc = 0.
          l_xml_table2[] = l_xml_table[].
          loop at l_xml_table2.
            transfer l_xml_table2 to w_filename.
          endloop.
        endif.
        close dataset w_filename.
      else.
        call method cl_gui_frontend_services=>gui_download
          exporting
            bin_filesize = l_xml_size
            filename     = w_filename
            filetype     = 'BIN'
          changing
            data_tab     = l_xml_table
          exceptions
            others       = 24.
        if sy-subrc <> 0.
          message id sy-msgid type sy-msgty number sy-msgno
                     with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        endif.

  • [svn:bz-trunk] 11030: Tweak the deserialization of ASObjects to treat an empty string for the type of an object as null .

    Revision: 11030
    Author:   [email protected]
    Date:     2009-10-20 11:35:02 -0700 (Tue, 20 Oct 2009)
    Log Message:
    Tweak the deserialization of ASObjects to treat an empty string for the type of an object as null. It appears that there is some logic in the LC remoting code that relies on a non-null class name to always exist. This change reverts to the old behavior of not allowing empty string as a value for the ASObject.namedType.
    This should fix bug 2448442 and its duplicates caused by the recent serialization changes.
    I don't think this is the perfect fix. Pending further investigation, a better fix would be either:
    a. If it's OK to assume that empty string should always mean null for the type of the ASObject, the code that enforces it should be in the setter/getter inside ASObject and not in the deserializer.
    b. ASObject doesn't guarantee that a named type exists or is valid. In that sense an empty string is as bad as some random characters that cannot be a valid class name in java, so depending on how disruptive it may be, the fix should be in any logic that uses ASObject.getType().
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/io/amf/AbstractAmfInput.java

    Hi Pavan,
    "In your payload there is no namespace prefix for the elements under PayloadHeader element."
    Yes, you are right - but this message is standard AQ Adapter Header message - it's not defined by me. I just used message which was automatically added to my project when I have defined AQ Adapter.
    "In your process is the default namespace is same as namespace value of tns ??"
    Do you mean targetNamespace? If yes it's different as it points to process "targetNamespace="http://xmlns.oracle.com/PF_SOA_jws/PF_APPS/APPS_PROCESS" (names of application and process have changed as I try different ways to do that)
    ns1 is: xmlns:ns1="http://xmlns.oracle.com/pcbpel/adapter/aq/PF_SOA/PF_APPS/PO_AQ"
    "another thing is tns and ns1 should have same values.."
    When I create a variable of header type, namespace ns1 is automatically created for it. I set it as property of receive activity. When process is instantiated on the serwer I get the error in which you can see that namespace is tns.
    Maybe I'm doing something wrong but I don't see how I could fix this in my process.
    You can see that the message I get on the server has nothing in common with the application/project/process names. Is it possible to define such variable?
    Regards
    Pawel
    PS:
    In Transformation xsl file, both variables (source and target) has tns namespace for Header and PayloadHeader, and no namespace for subfields.
    Edited by: pawel.fidelus on 2010-01-05 02:37

  • How to enable web-app "parent-last" classloading in WLS 10.3?

    Hello,
    We are having some issues when using Groovy to execute ant tasks in a webapp. They are due to the classloading order in WLS.
    The problem is this :
    - Our webapp is using Groovy 1.5.6.
    - Groovy 1.5.6 uses ant 1.7. When groovy calls ant tasks such as <untar>, <unjar>, etc, it is passing the <mapper> element, which is supported in ant 1.7.
    - When this webapp is deployed in WLS 10.3, Groovy tries to call these ant tasks, but WLS has ant 1.6 which does not support the nested <mapper> element groovy is trying to pass.
    - The groovy script blows up with an ant error because of the unsupported element.
    - We are packaging ant 1.7 jars in the WEB-INF/lib dir of our WAR file, but WLS is loading the classes from it's own classpath first, so we do not get the 1.7 impl loaded.
    The solution is to enable "parent-last" classloading for this webapp, but I can not find any documentation on how to do this.
    In Websphere you can set a checkbox for it in the console.
    In Orion, you add to the orion-web.xml file this tag <web-app-class-loader search-local-classes-first="true"/>
    ** In WebLogic, how do you do this?
    I have been searching the documentation and asking around, and I can not find an answer yet. Thanks in advance for your help!

    Try either a filtering classloader as described here:
    http://edocs.bea.com/wls/docs103/programming/classloading.html#wp1097187
    Or prefer-web-inf-classes in weblogic.xml:
    http://edocs.bea.com/wls/docs103/programming/classloading.html#wp1082452

  • Classloader Again

    Sorry to bring up the classloader questions again and again. I am a bit confused by the language used in the documentation when it says things like each application has its own universe etc. And also, the following statement in the docs,
    "The exception is the Web Classloader, which follows the delegation model in the Servlet specification. The Web Classloader looks in the local classloader before delegating to its parent. You can make the Web Classloader delegate to its parent first by setting delegate="true" in the class-loader element of the sun-web.xml file. For details, see the Developer's Guide to Web Applications."
    I wanted to see if some one could answer the following. (These are very easy for me to test. But, at this point I have a very "rich" system classpath that includes a lot of classes/jars etc. Makes it harder to see a clear picture. And I want to see if what I am observing the correct behavior))
    I have a com.xyz.myClass packaged in utils.jar. I also have a test servlet and jsp page. The test servlet makes a call to com.xyz.myClass
    A) If I individually deploy my test servlet/jsp as a .WAR, where should I place utils.jar?
    (If I had utils.jar in the system classpath, is the WAR supposed to see it?)
    B) What if the a

    I have a com.xyz.myClass packaged in utils.jar. I also have > a test servlet and jsp page. The test servlet makes a call to > com.xyz.myClass
    A) If I individually deploy my test servlet/jsp as a .WAR,
    where should I place utils.jar?You can place it in any one of a number of locations:
    - within the WAR under WEB-INF/lib/. This location would be the most conventional, self-contained approach.
    - under $INSTANCE_ROOT/lib/. This location would mean that the same "version" the library would be shared by all apps (assuming that the other apps did not include their own copy).
    - under classpath-suffix setting for the instance. Similar to using $INSTANCE_ROOT/lib/, but you have to specify the JAR file name explicitly.
    (If I had utils.jar in the system classpath, is the WAR
    supposed to see it?)Yes.
    B) What if the above .WAR was part of a larger .EAR and I > deploy the .EAR instead of the .WAR? (Should utils.jar
    be in system class path or the web-inf/lib of the .WAR ?)Either.
    C) What if the .EAR above also had a few EJBs that
    accessed com.xyx.myClass ?- Self-contained approach would be to package the JAR file in the EAR and use the manifest classpath approach to denote its location for both the EJB JAR module and the WAR module.
    - Alternatively, you could either place the library either under $INSTANCE_ROOT/lib/ or specify the library in the classpath-suffix setting in the instance configuration.
    A good example of when it makes sense for the web classloader to look in the local classloader before delegating upward to the system classloader is the case in which your web application depends on a particular JAXP compatible XML parser that is different from that which is being used by the application server infrastructure. In this case, you would want the XML parser embedded in your web app or EAR to take precedence over the other XML parser packaged in the system classpath for use by the app server.
    Chris

Maybe you are looking for