-
1. Re: Problems getting Datasource via JNDI from client
matt.clark Feb 20, 2002 11:08 AM (in response to matt.clark)I may have found the answer to my question from way back in this forum.
Is it because I can't access a DataSource outside of the jBoss VM? -
2. Re: Problems getting Datasource via JNDI from client
davidjencks Feb 20, 2002 5:28 PM (in response to matt.clark)You got it!
-
3. Re: Problems getting Datasource via JNDI from client
luckystar_007 Mar 8, 2002 1:54 AM (in response to matt.clark)davidjencks, but you also mean even when i use JBoss-2.4.3_Tomcat-3.2.3, the jboss and tomcat are in 2 jvms,and programs in tomcat (jsp or servlet) can't access a Datasource via JNDI?
-
4. Re: Problems getting Datasource via JNDI from client
davidjencks Mar 8, 2002 8:17 AM (in response to matt.clark)Packages labeled jboss-xxx-tomcat-yyy run jboss and tomcat in the SAME vm so calls between the 2 do not involve serialization. Another effect is that you can get to the in vm java: jndi context and get to things like datasources from servlets.
Be sure you are starting jboss with a script mentioning tomcat- I believe theses packages also include a way of running jboss by itself. -
5. still not resolved.
luckystar_007 Mar 11, 2002 10:16 PM (in response to matt.clark)More detail:
I am in emergency for a project, my boss told me to make a solution, to use tomcat+jboss to
provide
2-phase commit ability,but we are not allowed to use EJB,
My solution is:
step 1. configure Datasource in JBoss
step 2. to make a web application in JBoss's embbeded Tomcat,and program a servlet program
step 3. in the servlet program, get UserTransaction via JNDI, get DataSource via JNDI.
(I am using JBoss-2.4.3_Tomcat-3.2.3)
The result is: I got the UserTransaction, but I failed to get DataSource Name.
the screen snapshot is :
[Default] Before lookup OracleDS1
[Default] Exception occured
[Default] javax.naming.NameNotFoundException: OracleDS1 not bound
[Default] at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServe
r(StreamRemoteCall.java:245)
[Default]
[Default] at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCa
ll.java:220)
[Default]
[Default] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
[Default]
[Default] at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
[Default]
[Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:34
9)
[Default]
[Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:33
3)
[Default]
[Default] at javax.naming.InitialContext.lookup(InitialContext.java:350)
[Default]
[Default] at Test.myTest.ExecuteTransaction(myTest.java:31)
[Default]
[Default] at Test.UIServlet.doGet(UIServlet.java:25)
[Default]
[Default] at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
[Default]
[Default] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[Default]
[Default] at org.apache.tomcat.core.ServletWrapper.doService(ServletWrappe
r.java:405)
[Default]
[Default] at org.apache.tomcat.core.Handler.service(Handler.java:287)
[Default]
[Default] at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.
java:372)
[Default]
[Default] at org.apache.tomcat.core.ContextManager.internalService(Context
Manager.java:812)
[Default]
[Default] at org.apache.tomcat.core.ContextManager.service(ContextManager.
java:758)
[Default]
[Default] at org.apache.tomcat.service.http.HttpConnectionHandler.processC
onnection(HttpConnectionHandler.java:213)
[Default]
[Default] at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoi
nt.java:416)
[Default]
[Default] at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadP
ool.java:501)
[Default]
[Default] at java.lang.Thread.run(Thread.java:484)
[Default]
The code section is;
.....
public boolean ExecuteTransaction(){
boolean utBeginFlg=false;
UserTransaction ut=null;
try{
Properties _props = new Properties();
_props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
_props.setProperty(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
_props.setProperty(Context.PROVIDER_URL, "localhost:1099");
InitialContext ctx = new InitialContext(_props);
ut=(UserTransaction)ctx.lookup("UserTransaction");
ut.begin();
System.out.println("Before lookup OracleDS1");
DataSource ds1 =(DataSource)ctx.lookup("java:/OracleDS1");
System.out.println("After lookup OracleDS1");
Connection conn_1=ds1.getConnection();
System.out.println("Before lookup OracleDS2");
DataSource ds2 =(DataSource)ctx.lookup("java:/OracleDS2");
System.out.println("After lookup OracleDS2");
Connection conn_2=ds2.getConnection();
Statement stat_1=conn_1.createStatement();
Statement stat_2=conn_2.createStatement();
String strSQL_1="update GAOTABLE set age = 18";
String strSQL_2="update JIANTABLE set age = 19";
stat_1.execute(strSQL_1);
stat_2.execute(strSQL_2);
conn_1.close();
conn_2.close();
ut.commit();
if ( (conn_1!=null) && (conn_2!=null)){
System.out.println("yes, connection ok");
}else{
System.out.println("no, connection failed");
}
return true;
}catch(Exception e){
System.out.println("Exception occured");
e.printStackTrace();
return false;
}
}
.....
I'm confused why I can't lookup OracleDS1,
I use http:/8082, and can found that: (I really saw the OracleDS1 in java:Namespace)
How Strange it is!
...
Application:
file:/E:/SoftBank/webserver/JBoss-2.4.3_Tomcat-3.2.3/jboss/tmp/deploy/Default/tomcat-test.ear
java:comp namespace of the NonOptimized bean:
+ env (class: org.jnp.interfaces.NamingContext)
java:comp namespace of the Optimized bean:
+ env (class: org.jnp.interfaces.NamingContext)
java: Namespace
+ jaas (class: javax.naming.Context)
+ TransactionPropagationContextImporter (class:
org.jboss.tm.TransactionPropagationContextImporter)
+ JmsXA (class: org.jboss.jms.ra.JmsConnectionFactoryImpl)
+ MinervaSharedLocalCMFactory (class:
org.jboss.pool.connector.jboss.MinervaSharedLocalCMFactory)
+ DefaultDS (class: org.jboss.pool.jdbc.xa.XAPoolDataSource)
+ StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
+ MinervaXACMFactory (class: org.jboss.pool.connector.jboss.MinervaXACMFactory)
+ TransactionManager (class: org.jboss.tm.TxManager)
+ TransactionPropagationContextExporter (class:
org.jboss.tm.TransactionPropagationContextFactory)
+ ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
+ DefaultJMSProvider (class: org.jboss.jms.jndi.JBossMQProvider)
+ XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
+ Mail (class: javax.mail.Session)
+ MinervaDS (class: org.jboss.pool.connector.jdbc.JDBCDataSource)
+ OracleDS2 (class: org.jboss.pool.jdbc.xa.XAPoolDataSource)
+ OracleDS1 (class: org.jboss.pool.jdbc.xa.XAPoolDataSource)
+ SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
+ comp (class: javax.naming.Context)
+ MinervaNoTransCMFactory (class: org.jboss.pool.connector.jboss.MinervaNoTransCMFactory)
Global JNDI Namespace
+ TopicConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
+ jmx (class: org.jboss.jmx.server.JMXAdaptorImpl)
+ NonOptimized (class: $Proxy2)
+ ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
+ UserTransactionSessionFactory (class:
org.jboss.tm.usertx.server.UserTransactionSessionFactoryImpl)
+ Optimized (class: $Proxy2)
+ XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
+ invokers (class: org.jnp.interfaces.NamingContext)
| + Optimized (class: org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker)
| + NonOptimized (class: org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker)
+ UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
+ UILXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
+ RMIXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
+ jmx:gaojian:rmi (class: org.jboss.jmx.server.RMIConnectorImpl)
+ queue (class: org.jnp.interfaces.NamingContext)
| + D (class: org.jboss.mq.SpyQueue)
| + C (class: org.jboss.mq.SpyQueue)
| + B (class: org.jboss.mq.SpyQueue)
| + A (class: org.jboss.mq.SpyQueue)
| + controlQueue (class: org.jboss.mq.SpyQueue)
| + testQueue (class: org.jboss.mq.SpyQueue)
| + ex (class: org.jboss.mq.SpyQueue)
| + F (class: org.jboss.mq.SpyQueue)
| + E (class: org.jboss.mq.SpyQueue)
+ topic (class: org.jnp.interfaces.NamingContext)
| + example (class: org.jboss.mq.SpyTopic)
| + testTopic (class: org.jboss.mq.SpyTopic)
| + bob (class: org.jboss.mq.SpyTopic)
+ UILConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
+ servercollector (class: org.jboss.management.ServerDataCollector)
+ RMIConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
+ QueueConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef) -
6. Re: still not resolved.
davidjencks Mar 11, 2002 11:14 PM (in response to matt.clark)1. putting properties with things like localhost in your new InitialProperties calls makes the lookup go over rmi to ... yourself. This is no longer the same vm, as far as jndi can tell. Just use new InitialContext().
2. I cannot emphasize strongly enough that you should get cmt working with an ejb example using 2pc and make sure you have the Oracle drivers set up correctly, working, it really is doing prepare,...commit. Only when this is working completely and you understand why and how should you start trying to control this from Tomcat. I have never tried to use UserTransaction from a servlet, however I think some people have reported problems with it with some versions of jboss. Why is your boss against using ejbs? -
7. Re: still not resolved.
vickyk May 23, 2002 7:38 AM (in response to matt.clark)Hi,
Did you got the program working now?If you have found the solution please send me,I am trying to access the DataSource from the java client(neither by ejbs nor by jsp).It is very urgent,hope to get the help..
regards vickyk -
8. Re: still not resolved.
davidjencks May 23, 2002 9:02 AM (in response to matt.clark)How about if you read posts 2,3 and 7 in this thread? You can't access a datasource from another vm.
-
9. Re: Problems getting Datasource via JNDI from client
tobing May 23, 2002 10:58 AM (in response to matt.clark)If a client in another vm can not access a datasource (through JNDI lookup) in JBoss, then what use is a datasource in JBoss? Can somebody enlighten me on this issue.
-
10. Re: Problems getting Datasource via JNDI from client
vickyk May 24, 2002 1:11 AM (in response to matt.clark)Hi Tobing,
> If a client in another vm can not access a datasource
> (through JNDI lookup) in JBoss, then what use is a
> datasource in JBoss? Can somebody enlighten me on
> this issue.
This is something new I have come to know regarding the
app server implementation.Any way let me give my opinion
regarding your query:
The app server will try to follow the J2EE specification where in we have the ejb,web,java,connector
modules.So these modules should be able to get the services provided by the app server......like DataSource,JNDI etc.Hence to get the services of the app
server you require to use these modules only(if specifications are followed strictly)...
And that is what the jboss is doing.
So in short I had understood that from different JVM to
get the app server services you have to use the ejb module in between......
Hope this helps you and expect an comments from the jboss
gurus....
regards vicky