JNDI bind Referenceable object fails
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Michal_Tym
Posted On:   Thursday, November 27, 2003 06:25 AM

I have a simple JNDI test program whose source is listed below. Bind fails with the following error. Operation failed: javax.naming.CommunicationException. Root exception is java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.io.StreamCorruptedException at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108 ) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java :284) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java :244) at weblogic.jndi.internal.ServerNamingNode_811_WLStub.bind(Unknown Source) at weblogic.jndi.internal   More>>

I have a simple JNDI test program whose source is listed below. Bind fails
with the following error.

Operation failed: javax.naming.CommunicationException. Root exception is
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception
is:
java.io.StreamCorruptedException
at
weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108
)
at
weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java
:284)
at
weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java
:244)
at weblogic.jndi.internal.ServerNamingNode_811_WLStub.bind(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.bind(WLContextImpl.java:359)
at javax.naming.InitialContext.bind(InitialContext.java:355)
at com.client.mytest.main(JNDIBindTestClient.java:50)
Caused by: java.io.StreamCorruptedException
....
Exception in thread "main"

I have listed the source code for the test program as well as the class
Fruit (the object I am trying to bind)

JDK 1.4.1_03
BEA WL 8.1

What is going on here? Any help would be greatly appreciated.

------------------------------------mytest.java-----------------------------
-------------
package examples.jndi;

import javax.naming.*;
import java.util.Hashtable;

/**
* Demonstrates how to bind a Referenceable object to a context.
* (Use Unbind to remove binding.)
*
* usage: java RefObj
*/

class mytest {
public static void main(String[] args) {

Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://localhost:7001");

try {
// Create the initial context
Context ctx = new InitialContext(env);

// Create object to be bound
Fruit fruit = new Fruit("orange");

// Perform bind
ctx.bind("cn=favorite", fruit);

// Read object back
Fruit f2 = (Fruit) ctx.lookup("cn=favorite");
System.out.println(f2);

// Close the context when we're done
ctx.close();
} catch (NamingException e) {
System.out.println("Operation failed: " + e);
}
}
}

---- ------------------Fruit.java----------------------------------
import javax.naming.*;

public class Fruit implements Referenceable, java.io.Serializable{
String fruit;

public Fruit(String f)
{
fruit = f;
}

public Reference getReference() throws NamingException
{
return new Reference(
Fruit.class.getName(),
new StringRefAddr("fruit", fruit),
FruitFactory.class.getName(),
null); // factory location
}
public String toString()
{
return fruit;
}
}

--------------------------------------FruitFactory.java---------------------
------------

import javax.naming.*;
import javax.naming.spi.ObjectFactory;
import java.util.Hashtable;

/**
* This is an object factory that when given a reference for a Fruit
* object, will create an instance of the corresponding Fruit.
*/
public class FruitFactory implements ObjectFactory {
public FruitFactory() {
}

public Object getObjectInstance(Object obj, Name name, Context ctx,
Hashtable env) throws Exception {
if (obj instanceof Reference) {
Reference ref = (Reference)obj;
if (ref.getClassName().equals(Fruit.class.getName())) {
RefAddr addr = ref.get("fruit");
if (addr != null) {
return new Fruit((String)addr.getContent());
}
}
}
return null;
}
}

The the non refrence object bind's fine.

   <<Less

Re: JNDI bind Referenceable object fails

Posted By:   Sheetal_P  
Posted On:   Wednesday, December 3, 2003 04:30 AM

Make sure that you are contacting the Server at the right port(usually 389). Even I'm trying a similar binding but I'm getting "NoSuchAttributeException", I'm using Windows Active Directory.
About | Sitemap | Contact