I am setting up a standalone JNDI and loading a Datasource to the JNDI. DataSource I use is: org.apache.commons.dbcp.BasicDataSource

The JNDI is set up as follows

 

  String detectorHost = InetAddress.getLocalHost().getHostName();
  System.out.println("detectorHost: " + detectorHost);
  System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  final NamingBeanImpl namingInfo = new NamingBeanImpl();
  namingInfo.start();
  final Main JNDIServer = new Main();
  JNDIServer.setNamingInfo( namingInfo );
  JNDIServer.setPort( 5400 );
  JNDIServer.setBindAddress(InetAddress.getLocalHost().getHostName());
  JNDIServer.start();
  final Hashtable _properties = new Hashtable();
  _properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  _properties.put(Context.PROVIDER_URL, "jnp://" + InetAddress.getLocalHost().getHostName() + ":5400");
  final Context _context = new InitialContext(_properties);
  _context.createSubcontext("jdbc");
  String JNDI_PATH = "jdbc" + "/" + "mydbname";
  _context.bind(JNDI_PATH, getDataSource());


I get the following exception


javax.naming.CommunicationException [Root exception is java.io.NotSerializableException: org.apache.commons.dbcp.BasicDataSource]
  at org.jnp.interfaces.NamingContext.bind(NamingContext.java:677)
  at org.jnp.interfaces.NamingContext.bind(NamingContext.java:611)
  at javax.naming.InitialContext.bind(Unknown Source)
  at com.lombardrisk.reform.integration.ReformIntegration.createJNDIServer(ReformIntegration.java:93)
  at com.lombardrisk.reform.integration.ReformIntegration.main(ReformIntegration.java:44)
Caused by: java.io.NotSerializableException: org.apache.commons.dbcp.BasicDataSource
  at java.io.ObjectOutputStream.writeObject0(Unknown Source)
  at java.io.ObjectOutputStream.writeObject(Unknown Source)
  at java.rmi.MarshalledObject.<init>(Unknown Source)
  at org.jnp.interfaces.MarshalledValuePair.<init>(MarshalledValuePair.java:65)
  at org.jnp.interfaces.NamingContext.createMarshalledValuePair(NamingContext.java:1425)
  at org.jnp.interfaces.NamingContext.bind(NamingContext.java:640)


I don't quite follow why I am getting a NotSerializableException exception, this is a local JNDI in the same JVM and not a remote JNDI. Not sure why this occurs.

Can some one advise what is wrong here.

regards D

FacebookTwitterLinkedin
Pin It
Joomla Tutorials for Beginners