• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Urgent help!!!!!!!! java.io.Stream Corrupted Exception: Type code out of range, is 2

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, all:
I met a problem in my simple program WebLogicJNDITest.java to create a MyClass
instance and bind it into Weblogic server 6.1 SP1 running in Win2000 box. It always throw the following exception.Can anyone help me to solvet the program? What's wrong with my code? Is that static variable causes the problem?
This program works fine using Sun's File System.
I have post my question in serveral web site, Still don't get the answer from anyone.
if any one can give some suggestion, it would be very appreciated.
Long
P.S.:
There is one inner class in the MyClass.java.
Does it will cause the problem??
The steps to run the follwoing program:
1): Start WebLogic Server
2): Run the WebLogicJNDITest.class
===========Error Message =========================
javax.naming.CommunicationException. Root exception is java.rmi.UnmarshalException:
error unmarshalling arguments; nested exception is:
java.io.StreamCorruptedException: Type code out
of range, is 2
Start server side stack trace:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.io.StreamCorruptedException:
Type code out of range, is 2
java.io.StreamCorruptedException:
Type code out of range, is 2
at java.io.ObjectInputStream.peekCode
(ObjectInputStream.java:1556)
at java.io.ObjectInputStream.refill
(ObjectInputStream.java:1684)
at java.io.ObjectInputStream.read
(ObjectInputStream.java:1660)
at java.io.DataInputStream.readInt
(DataInputStream.java:338)
at java.io.ObjectInputStream.readInt
(ObjectInputStream.java:1980)
at com.mycompany.MyClass.readObject(MyClass.java:1326)
at java.lang.reflect.Method.invoke(Native Method)
at java.io.ObjectInputStream.invokeObjectReader (ObjectInputStream.java:2214)
at java.io.ObjectInputStream.inputObject
(ObjectInputStream.java:1411)
at java.io.ObjectInputStream.readObject
(ObjectInputStream.java:386)
at java.io.ObjectInputStream.readObject
(ObjectInputStream.java:236)
at weblogic.common.internal.ChunkedObjectInputStream.readObject
(ChunkedObjectInputStream.java:107)
at weblogic.common.internal.ChunkedObjectInputStream.readObject
(ChunkedObjectInputStream.java:115)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke
(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke
(BasicServerRef.java:296)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke
(ReplicaAwareServerRef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest
(BasicServerRef.java:265)
at weblogic.rmi.internal.BasicExecuteRequest.execute
(BasicExecuteRequest.java:22)
at weblogic.kernel.ExecuteThread.execute
(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run
(ExecuteThread.java:120)
End server side stack trace
; nested exception is:
java.io.StreamCorruptedException: Type code out of range, is 2
===== MyClass.java ==============================
public class MyClass implements
Referenceable, java.io.Serializable {
............
protected static HashMap myMap = new HashMap(4);
private static final int myClassType = 1;
private static final int yourClassType = 2;
private static final int hisClassType = 3;
private String className;
private String classType;
private boolean isPrivateClass;
private javax.sql.DataSource dataSource;
public String getClassName(){
return className;
}
public String getClassType(){
return classType;
}
public void setClassName(String classNameIn){
className = classNameIn;
}
public void setClassType(String classTypeIn){
classType = classTypeIn;
}
public Reference getReference() throws
NamingException {
ByteArrayOutputStream baos = new
ByteArrayOutputStream();
Reference ref = null;
try {
ObjectOutputStream oos = new
ObjectOutputStream(baos);
oos.writeObject(this);
ref = new Reference(MyClass.class.getName(),
MyClassFactory.class.getName(),
null);
Properties props = getAsProperties();
for( Enumeration e = props.propertyNames();
e.hasMoreElements() {
String key = (String)e.nextElement();
String value = props.getProperty(key);
ref.add(new StringRefAddr(key, value));
}
} catch( IOException ex) {
throw new NamingException("Error occur to
get the MyClass reference.");
}
return ref;
}
private void readObject(java.io.ObjectInputStream is) throws java.io.IOException, ClassNotFoundException {
java.io.ObjectInputStream ois = (java.io.ObjectInputStream)is;
ois.defaultReadObject();
int kind = ois.readInt();
private void readObject(java.io.ObjectInputStream is)
throws java.io.IOException, ClassNotFoundException {
java.io.ObjectInputStream ois =
(java.io.ObjectInputStream) is;
ois.defaultReadObject();
int kind = ois.readInt();
switch( kind) {
case 1:
classType = ois.readObject();
break;
case 2:
className = (String)ois.readObject();
classType = (String)ois.readObject();
break;
}
isPrivateClass = ois.readBoolean();
}
private void writeObject(java.io.ObjectOutput os)
throws java.io.IOException {
java.io.ObjectOutputStream oos =
(java.io.ObjectOutputStream) os;
oos.defaultWriteObject();
int kind = getSerializedForm();
oos.writeInt(kind);
switch(kind) {
case 1:
oos.writeObject(classType);
break;
case 2:
oos.writeObject(className);
oos.writeObject(classType);
break;
}
oos.writeBoolean(isPrivateClass);
}
}

}
===== WebLogicJNDITest.java ======================
.....................
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://jyou:7001");
Context context = null;
MyClass myClass = new MyClass();
try{
context = new InitialContext(env);
context.rebind("myClassName", yClass );
}catch(NamingException nex){
th = nex;
}catch(Exception ex){
th = ex;
}finally{
if(th != null){
System.out.println("Error occur" + th);
}
}
..........................
======= MyClassFactory ========================
public class MyClassFactory implements ObjectFactory {
/**
* Uses StringRefAddr's to store the
* information
*/
public Object getObjectInstance( Object obj, Name name, Context ctx, Hashtable env) throws Exception {
MyClass rc = null;
if (obj instanceof Reference) {
Reference ref = (Reference)obj;
if (ref.getClassName().equals
(MyClass.class.getName())) {
Properties p = new Properties();
for(Enumeration e = ref.getAll();
e.hasMoreElements() {
StringRefAddr sra =
(StringRefAddr)e.nextElement();
p.setProperty(sra.getType(),
(String)sra.getContent());
}
rc = new MyClass();
rc.setFromProperties(p);
}
}
return rc;
}
......................
}
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic