[jboss-user] [JNDI/Naming/Network] - basic JNDI beginners problems - cant do look up from applica

wiggy do-not-reply at jboss.com
Tue Sep 4 14:23:37 EDT 2007


just trying to get to grips with JBOSS AS4.2 and new to the environment.  Really trying to get to EJB3 but doing it bit by bit and want to be able to call session bean services from a test application client - that i can run in eclipse.

deployed 4.2 and configured a My sql XA datasource as follows.


  | 
  | <datasources>
  |    <xa-datasource>
  |     <jndi-name>jdbc/willsDS</jndi-name>
  |     <use-java-context>false</use-java-context>
  | 	<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
  | 	<xa-datasource-property
  | 		name="URL">
  | 		jdbc:mysql://localhost:3306/test
  | 	</xa-datasource-property>
  | 	<user-name>will</user-name>
  | 	<password>will</password>
  |     <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>		
  |     <max-pool-size>5</max-pool-size>
  |     <min-pool-size>1</min-pool-size>
  |     
  | 	<blocking-timeout-millis>2000</blocking-timeout-millis>
  |     <idle-timeout-minutes>2</idle-timeout-minutes>
  | 	<track-connection-by-tx>true</track-connection-by-tx>
  | 	<no-tx-separate-pools>false</no-tx-separate-pools> 
  | 	
  | 	<exception-sorter-class-name>
  | 	org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
  | 	</exception-sorter-class-name>
  | 	<metadata>
  | 	<type-mapping>mySQL</type-mapping>
  | 	</metadata> 	
  | 	
  |   </xa-datasource>
  | </datasources>
  | 

This all goes well - and when i start the server inside eclipse i can see the datasource in the JNDIView tree

i've registered the datasource in the global tree and not the java: default part as the JNDI FAQ says you cant see the java: tree unless its in the same VM.

i've checked netstat - a and port 1099 is being listened on when i run the server up.

next created a simple client app (as an EJB project in eclipse to pickup the AS libraries if nothing else) 

my simple app client looks like this - at the mo i'm just trying to get a simple JNDI lookup to the datasource in the AS (no DI here as its an standalone client)

 
  | 
  | package org;
  | 
  | import java.sql.Connection;
  | import java.util.Hashtable;
  | 
  | import javax.naming.InitialContext;
  | import javax.sql.DataSource;
  | 
  | 
  | /**
  | * @author Will
  | *
  | */
  | public class Test 
  | {
  | 
  | 
  | 	public static void main(String[] args) throws Exception 
  | 	{
  | 
  | 
  | 	    InitialContext ctx = getInitialContext();
  | 	    DataSource ds;
  | 	    Connection conn;
  | 	    
  |                     //llookup ds via jndi in global tree - using jnp://localhost:1099 - see helper function above
  | 	    ds = (DataSource) ctx.lookup("jdbc/willDS");
  | 	    conn = ds.getConnection();
  | 	    conn.close();
  | 	    
  | 
  | 	}
  | 	
  | 	public static InitialContext getInitialContext() throws Exception
  | 	{
  | 	   Hashtable props = getInitialContextProperties();
  | 	   return new InitialContext(props);
  | 	}
  | 
  | 	private static Hashtable getInitialContextProperties()
  | 	{
  | 
  | 	   Hashtable props = new Hashtable();
  | 	   props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  | 	   props.put("javax.naming.Context.PROVIDER_URL","jnp://localhost:1099");
  | 	   props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" );
  | 	   return props;
  | 	}
  | }
  | 

when i run the app however i get varying errors depending on whether  i set the provider_url or not.

code shows me setting the provider_url and get error 

anonymous wrote : 
  | Exception in thread "main" javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
  | 	at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1317)
  | 	at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1446)
  | 	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:594)
  | 	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
  | 	at javax.naming.InitialContext.lookup(Unknown Source)
  | 	at org.Test.main(Test.java:32)
  | Caused by: java.net.SocketTimeoutException: Receive timed out
  | 	at java.net.PlainDatagramSocketImpl.receive0(Native Method)
  | 	at java.net.PlainDatagramSocketImpl.receive(Unknown Source)
  | 	at java.net.DatagramSocket.receive(Unknown Source)
  | 	at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1287)
  | 	... 5 more
  | 

on an earlier go i got errors about cant find bound class jdbc - but i cant get that at present - and now stuck on the above.

I'll never progress to anything smarter if i cant sort the basics out - what am i doing wrong, any ideas please?



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4081019#4081019

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4081019



More information about the jboss-user mailing list