|
Re: [net4j] ClassNotFoundException when transferring instances of custom serializable class [message #499394 is a reply to message #499378] |
Sat, 21 November 2009 19:01 |
|
This is a multi-part message in MIME format.
--------------020809020909010003060505
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Hi Frank,
This is probably a ClassLoader issue. Here is a snippet from a Net4j
example (ProtocolUtil):
| *public static *IMessage readMessage(ExtendedDataInputStream in, *final *ClassLoader classLoader) *throws *IOException
{
*try*
{
ObjectInputStream ois = *new *ObjectInputStream(in)
{
@Override
*protected *Class<?> resolveClass(ObjectStreamClass desc) *throws *IOException, ClassNotFoundException
{
String className = desc.getName();
*return *classLoader.loadClass(className);
}
};
*return *(IMessage)ois.readObject();
}
*catch *(IOException ex)
{
*throw *ex;
}
*catch *(Exception ex)
{
*throw *WrappedException.wrap(ex);
}
}|
I suspect that it comes from times before the
ExtendedDataInputStream.readObject() method was introduced. Have you
tried to use the overloaded readObject() methods?
Cheers
/Eike
----
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Frank Grimm schrieb:
> Dear newsgroup,
>
> when transferring instances of a custom class XYZ that implements
> Serializable between a net4j Request and an Indication
> ClassNotFoundExceptions occur:
>
> java.lang.ClassNotFoundException: services.XYZ
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClassInter nal(BundleLoader.java:494)
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(Bund leLoader.java:410)
> at
> org.eclipse.osgi.internal.loader.BundleLoader.findClass(Bund leLoader.java:398)
> at
> org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loa dClass(DefaultClassLoader.java:105)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316 )
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:247)
> at java.io.ObjectInputStream.resolveClass(ObjectInputStream.jav a:604)
> at
> org.eclipse.net4j.util.io.ExtendedIOUtil$3.resolveClass(Exte ndedIOUtil.java:170)
> at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream .java:1575)
> at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.ja va:1496)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1732)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1329)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java: 351)
> at
> org.eclipse.net4j.util.io.ExtendedIOUtil.readObject(Extended IOUtil.java:177)
> at
> org.eclipse.net4j.util.io.ExtendedIOUtil.readObject(Extended IOUtil.java:126)
> at
> org.eclipse.net4j.util.io.ExtendedDataInputStream.readObject (ExtendedDataInputStream.java:41)
>
> Class XYZ is defined in a 'common' bundle shared between the client and
> the server bundles (the problem occurs in the server bundle). I've tried
> both adding the common bundle via 'require-bundle' and 'import-package'
> none of them worked.
>
> The strangest thing is that when I manually persist XYZ instances (using
> ObjectOutputStream.writeObject) and read them again (using
> ObjectInputStream.readObject), everything works fine. But using
> ExtendedDataInputStream.readObject fails... I'm running the bundles as
> Eclipse applications. Is there something (possible class path-related
> stuff) that has to be considered when writing/reading instances of
> custom classes the ExtendedData(Input|Output)Stream?
>
> Thanks,
> Frank
>
--------------020809020909010003060505
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Frank,<br>
<br>
This is probably a ClassLoader issue. Here is a snippet from a Net4j
example (ProtocolUtil):<br>
<br>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = --><!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td align="left" nowrap="nowrap"
valign="top"> <code><font color="#ffffff"> </font><font
color="#7f0055"><b>public static </b></font ><font color="#000000">IMessage readMessage</font><font
color="#000000">(</font><font color="#000000">ExtendedDataInputStream in, </font><font
color="#7f0055"><b>final </b></font><font color="#000000">ClassLoader classLoader</font><font
color="#000000">) </font><font color="#7f0055"><b>throws </b></font><font
color="#000000">IOException</font><br>
<font color="#ffffff"> </font><font color="#000000">{</font><br>
<font color="#ffffff"> </font ><font color="#7f0055"><b>try</b></font><br>
<font color="#ffffff"> </font ><font color="#000000">{</font><br>
<font color="#ffffff"> </font><font color="#000000">ObjectInputStream ois = </font><font
color="#7f0055"><b>new </b></font><font color="#000000">ObjectInputStream</font><font
color="#000000">(</font><font color="#000000">in</font><font
color="#000000">)</font><br>
<font color="#ffffff"> </font><font color="#000000">{</font><br>
<font color="#ffffff"> </font><font color="#646464">@Override</font><br>
<font color="#ffffff"> </font><font color="#7f0055"><b>protected </b></font><font
color="#000000">Class<?> resolveClass </font><font color="#000000">(</font><font
color="#000000">ObjectStreamClass desc</font><font color="#000000">) </font><font
color="#7f0055"><b>throws </b></font><font color="#000000">IOException, ClassNotFoundException </font><br>
<font color="#ffffff"> </font><font color="#000000">{</font><br>
<font color="#ffffff"> </font><font color="#000000">String className = desc.getName </font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font><font color="#7f0055"><b>return </b></font><font
color="#000000">classLoader.loadClass</font><font color="#000000">(</font><font
color="#000000">className</font><font color="#000000">)</font><font
color="#000000">;</font><br>
<font color="#ffffff"> </font><font color="#000000">}</font><br>
<font color="#ffffff"> </font><font color="#000000">}</font><font
color="#000000">;</font><br>
<font color="#ffffff"></font><br>
<font color="#ffffff"> </font><font color="#7f0055"><b>return </b></font><font
color="#000000">(</font><font color="#000000">IMessage</font><font
color="#000000">)</font><font color="#000000">ois.readObject</font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff"> </font ><font color="#000000">}</font><br>
<font color="#ffffff"> </font ><font color="#7f0055"><b>catch </b></font><font
color="#000000">(</font><font color="#000000">IOException ex</font><font
color="#000000">)</font><br>
<font color="#ffffff"> </font ><font color="#000000">{</font><br>
<font color="#ffffff"> </font><font color="#7f0055"><b>throw </b></font><font
color="#000000">ex;</font><br>
<font color="#ffffff"> </font ><font color="#000000">}</font><br>
<font color="#ffffff"> </font ><font color="#7f0055"><b>catch </b></font><font
color="#000000">(</font><font color="#000000">Exception ex</font><font
color="#000000">)</font><br>
<font color="#ffffff"> </font ><font color="#000000">{</font><br>
<font color="#ffffff"> </font><font color="#7f0055"><b>throw </b></font><font
color="#000000">WrappedException.wrap</font><font color="#000000">(</font><font
color="#000000">ex</font><font color="#000000">)</font><font
color="#000000">;</font><br>
<font color="#ffffff"> </font ><font color="#000000">}</font><br>
<font color="#ffffff"> </font><font color="#000000">}</font></code>
</td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== --><br>
I suspect that it comes from times before the
ExtendedDataInputStream.readObject() method was introduced. Have you
tried to use the overloaded readObject() methods?<br>
<br>
Cheers<br>
/Eike<br>
<br>
----<br>
<a class="moz-txt-link-freetext" href="http://thegordian.blogspot.com">http://thegordian.blogspot.com</a><br>
<a class="moz-txt-link-freetext" href="http://twitter.com/eikestepper">http://twitter.com/eikestepper</a><br>
<br>
<br>
<br>
Frank Grimm schrieb:
<blockquote cite="mid:he90eo$pfb$1@build.eclipse.org" type="cite">
<pre wrap="">Dear newsgroup,
when transferring instances of a custom class XYZ that implements
Serializable between a net4j Request and an Indication
ClassNotFoundExceptions occur:
java.lang.ClassNotFoundException: services.XYZ
at
org.eclipse.osgi.internal.loader.BundleLoader.findClassInter nal(BundleLoader.java:494)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(Bund leLoader.java:410)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(Bund leLoader.java:398)
at
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loa dClass(DefaultClassLoader.java:105)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316 )
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.jav a:604)
at
org.eclipse.net4j.util.io.ExtendedIOUtil$3.resolveClass(Exte ndedIOUtil.java:170)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream .java:1575)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.ja va:1496)
at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java: 351)
at
org.eclipse.net4j.util.io.ExtendedIOUtil.readObject(Extended IOUtil.java:177)
at
org.eclipse.net4j.util.io.ExtendedIOUtil.readObject(Extended IOUtil.java:126)
at
org.eclipse.net4j.util.io.ExtendedDataInputStream.readObject (ExtendedDataInputStream.java:41)
Class XYZ is defined in a 'common' bundle shared between the client and
the server bundles (the problem occurs in the server bundle). I've tried
both adding the common bundle via 'require-bundle' and 'import-package'
none of them worked.
The strangest thing is that when I manually persist XYZ instances (using
ObjectOutputStream.writeObject) and read them again (using
ObjectInputStream.readObject), everything works fine. But using
ExtendedDataInputStream.readObject fails... I'm running the bundles as
Eclipse applications. Is there something (possible class path-related
stuff) that has to be considered when writing/reading instances of
custom classes the ExtendedData(Input|Output)Stream?
Thanks,
Frank
</pre>
</blockquote>
</body>
</html>
--------------020809020909010003060505--
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
Re: [net4j] ClassNotFoundException when transferring instances of custom serializable class [message #499420 is a reply to message #499397] |
Sun, 22 November 2009 09:26 |
|
This is a multi-part message in MIME format.
--------------000505050806010903050003
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Hi Frank,
I'm glad that it works now. Often people ask me if anybody else uses
Net4j and I must always say that I don't know exactly. To encourage
others to use and help evolve Net4j would you mind to give me a little
description of your usage and why you chose it and allow me to publish
it somewhere on the homepage?
Cheers
/Eike
----
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Frank Grimm schrieb:
> Hi Eike
>
> On 11/21/2009 08:01 PM, Eike Stepper wrote:
>
>> I suspect that it comes from times before the
>> ExtendedDataInputStream.readObject() method was introduced. Have you
>> tried to use the overloaded readObject() methods?
>>
>
> Using readObject(XYZ.class.getClassLoader()) did the trick :-)
>
> Thanks a lot!
> Frank
>
>
>> Frank Grimm schrieb:
>>
>>> Dear newsgroup,
>>>
>>> when transferring instances of a custom class XYZ that implements
>>> Serializable between a net4j Request and an Indication
>>> ClassNotFoundExceptions occur:
>>>
>>> java.lang.ClassNotFoundException: services.XYZ
>>> at
>>> org.eclipse.osgi.internal.loader.BundleLoader.findClassInter nal(BundleLoader.java:494)
>>> at
>>> org.eclipse.osgi.internal.loader.BundleLoader.findClass(Bund leLoader.java:410)
>>> at
>>> org.eclipse.osgi.internal.loader.BundleLoader.findClass(Bund leLoader.java:398)
>>> at
>>> org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loa dClass(DefaultClassLoader.java:105)
>>> at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
>>> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316 )
>>> at java.lang.Class.forName0(Native Method)
>>> at java.lang.Class.forName(Class.java:247)
>>> at java.io.ObjectInputStream.resolveClass(ObjectInputStream.jav a:604)
>>> at
>>> org.eclipse.net4j.util.io.ExtendedIOUtil$3.resolveClass(Exte ndedIOUtil.java:170)
>>> at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream .java:1575)
>>> at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.ja va:1496)
>>> at
>>> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1732)
>>> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1329)
>>> at java.io.ObjectInputStream.readObject(ObjectInputStream.java: 351)
>>> at
>>> org.eclipse.net4j.util.io.ExtendedIOUtil.readObject(Extended IOUtil.java:177)
>>> at
>>> org.eclipse.net4j.util.io.ExtendedIOUtil.readObject(Extended IOUtil.java:126)
>>> at
>>> org.eclipse.net4j.util.io.ExtendedDataInputStream.readObject (ExtendedDataInputStream.java:41)
>>>
>>> Class XYZ is defined in a 'common' bundle shared between the client and
>>> the server bundles (the problem occurs in the server bundle). I've tried
>>> both adding the common bundle via 'require-bundle' and 'import-package'
>>> none of them worked.
>>>
>>> The strangest thing is that when I manually persist XYZ instances (using
>>> ObjectOutputStream.writeObject) and read them again (using
>>> ObjectInputStream.readObject), everything works fine. But using
>>> ExtendedDataInputStream.readObject fails... I'm running the bundles as
>>> Eclipse applications. Is there something (possible class path-related
>>> stuff) that has to be considered when writing/reading instances of
>>> custom classes the ExtendedData(Input|Output)Stream?
>>>
>>> Thanks,
>>> Frank
>>>
>>>
--------------000505050806010903050003
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Frank,<br>
<br>
I'm glad that it works now. Often people ask me if anybody else uses
Net4j and I must always say that I don't know exactly. To encourage
others to use and help evolve Net4j would you mind to give me a little
description of your usage and why you chose it and allow me to publish
it somewhere on the homepage?<br>
<br>
Cheers<br>
/Eike<br>
<br>
----<br>
<a class="moz-txt-link-freetext" href="http://thegordian.blogspot.com">http://thegordian.blogspot.com</a><br>
<a class="moz-txt-link-freetext" href="http://twitter.com/eikestepper">http://twitter.com/eikestepper</a><br>
<br>
<br>
<br>
Frank Grimm schrieb:
<blockquote cite="mid:he9h46$87c$1@build.eclipse.org" type="cite">
<pre wrap="">Hi Eike
On 11/21/2009 08:01 PM, Eike Stepper wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I suspect that it comes from times before the
ExtendedDataInputStream.readObject() method was introduced. Have you
tried to use the overloaded readObject() methods?
</pre>
</blockquote>
<pre wrap=""><!---->
Using readObject(XYZ.class.getClassLoader()) did the trick :-)
Thanks a lot!
Frank
</pre>
<blockquote type="cite">
<pre wrap="">Frank Grimm schrieb:
</pre>
<blockquote type="cite">
<pre wrap="">Dear newsgroup,
when transferring instances of a custom class XYZ that implements
Serializable between a net4j Request and an Indication
ClassNotFoundExceptions occur:
java.lang.ClassNotFoundException: services.XYZ
at
org.eclipse.osgi.internal.loader.BundleLoader.findClassInter nal(BundleLoader.java:494)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(Bund leLoader.java:410)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(Bund leLoader.java:398)
at
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loa dClass(DefaultClassLoader.java:105)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316 )
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.jav a:604)
at
org.eclipse.net4j.util.io.ExtendedIOUtil$3.resolveClass(Exte ndedIOUtil.java:170)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream .java:1575)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.ja va:1496)
at
java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStre am.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java :1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java: 351)
at
org.eclipse.net4j.util.io.ExtendedIOUtil.readObject(Extended IOUtil.java:177)
at
org.eclipse.net4j.util.io.ExtendedIOUtil.readObject(Extended IOUtil.java:126)
at
org.eclipse.net4j.util.io.ExtendedDataInputStream.readObject (ExtendedDataInputStream.java:41)
Class XYZ is defined in a 'common' bundle shared between the client and
the server bundles (the problem occurs in the server bundle). I've tried
both adding the common bundle via 'require-bundle' and 'import-package'
none of them worked.
The strangest thing is that when I manually persist XYZ instances (using
ObjectOutputStream.writeObject) and read them again (using
ObjectInputStream.readObject), everything works fine. But using
ExtendedDataInputStream.readObject fails... I'm running the bundles as
Eclipse applications. Is there something (possible class path-related
stuff) that has to be considered when writing/reading instances of
custom classes the ExtendedData(Input|Output)Stream?
Thanks,
Frank
</pre>
</blockquote>
</blockquote>
</blockquote>
</body>
</html>
--------------000505050806010903050003--
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Powered by
FUDForum. Page generated in 0.03372 seconds