I am following Head First EJB. I know it has EJB 2.0 which is old as now EJB 3.1 is in. But I consider Head first book a good book for learning for amateurs like us.
I am using J2ee 1.3.1 RI and jdk 1.4. I ran the "deploy" tool to deploy by EJB and now I have a ejb client JAVA program given below:
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;
import java.util.*;
public class AdviceClient {
public static void main(String[] args){
new AdviceClient().go();
}
public void go(){
try{
Properties props=new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
//props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
//env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
//props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty(Context.PROVIDER_URL,"rmi://localhost:1050");
//props.setProperty("java.naming.provider.url","rmi://localhost:1099");
Context ic = new InitialContext(props);
Object o = ic.lookup("Advisor");
AdviceHome home = (AdviceHome)PortableRemoteObject.narrow(o,AdviceHome.class);
Advice advisor = home.create();
System.out.println(advisor.getAdvice());
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
Following the book, I compiled the program. The "Properties" part is something not mentioned in the example. I got it from some other examples on the web. Now, that when I am executing the client, am getting the following error:
F:\EJBProject\advice>java -classpath AdviceAppClient.jar;. AdviceClient
javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketTimeoutException: Read timed out]
at com.sun.jndi.rmi.registry.RegistryContext.lookup(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.lookup(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at AdviceClient.go(AdviceClient.java:26)
at AdviceClient.main(AdviceClient.java:11)
Caused by: java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
java.net.SocketTimeoutException: Read timed out
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
... 5 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at java.io.DataInputStream.readByte(Unknown Source)
Please help. I am stuck up badly here. I wanted to sit for the OCBCD exam!
Regards,
Shouvanik
Finally Solved.
If you hit a roadblock while running the first EJB example simply follow these steps
to run the first example of HeadFirst EJB.
Softwares
1. j2sdk1.4.1 - jdk
2. j2sdkee1.3.1 - j2ee RI
3. CMD (command prompt)
Compile all the classes using c:\j2sdkee1.3.1\lib\j2ee.jar library.
Now, create a App and deploy EJB inside RI. download the application client as shown in the book.
Now, comes the tricky part.
Compile client class using the following jars
javac -classpath AdviceAppClient.jar;c:\j2sdkee1.3.1\lib\j2ee.jar AdviceClient.java
Next, run the client as follows
java -cp AdviceAppClient.jar;c:\j2sdkee1.3.1\lib\j2ee.jar;c:\j2sdk1.4.1\jre\lib\rt.jar;. AdviceClient
Related
When trying to launch a Java Action within Oozie (CDH6.3.1) I get a GSS initiate failed. The code in question is pretty straight forward:
String impalaUrl = "jdbc:impala://pxyserver.global.ad:21050/default;SSL=1;AuthMech=1;KrbRealm=GLOBAL.AD;KrbHostFQDN=pxyserver.global.ad;KrbServiceName=Impala;sslTrustStore=/opt/cloudera/security/jks/truststore.jks;trustStorePassword=password";
Properties impalaProperties = new Properties();
impalaProperties.put("user", "svcaccount");
impalaProperties.put("password", "svcpassword");
impalaProperties.put("Driver", "com.cloudera.impala.jdbc41.Driver");
try {
setConnection(DriverManager.getConnection(impalaUrl , impalaProperties));
} catch (SQLException e) {
e.printStackTrace();
}
Running this gives the following stack trace:
java.sql.SQLException: [Cloudera][ImpalaJDBCDriver](500164) Error initialized or created transport for authentication: [Cloudera][ImpalaJDBCDriver](500169) Unable to connect to server: GSS initiate failed.
at com.cloudera.impala.hivecommon.api.HiveServer2ClientFactory.createTransport(Unknown Source)
at com.cloudera.impala.hivecommon.api.ServiceDiscoveryFactory.createClient(Unknown Source)
at com.cloudera.impala.hivecommon.core.HiveJDBCCommonConnection.establishConnection(Unknown Source)
at com.cloudera.impala.impala.core.ImpalaJDBCDSIConnection.establishConnection(Unknown Source)
at com.cloudera.impala.jdbc.core.LoginTimeoutConnection.connect(Unknown Source)
at com.cloudera.impala.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
at com.cloudera.impala.jdbc.common.AbstractDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
I can fix this by kiniting with a keytab. However in our production environment Oozie runs this on one of many worker nodes and they do not have valid kerberos tickets. What are my options here? If possible I'd rather not kinit every day on each of our 40 worker nodes, is there a parameter I am missing here?
Thanks
I'm using two H2 databases in my Java projects. Recently, I changed my computer and since then I have no problem with connecting to one of those databases using my Java code but problems with the other one. It's exactly the same code (up to PATH_TO_DATABASE) I use to start the connection:
import java.sql.DriverManager;
import java.sql.SQLException;
public class DatabaseConfig {
private static java.sql.Connection connection;
public static void init() {
if (connection == null) {
try {
connection = DriverManager.getConnection("jdbc:h2:tcp://192.168.178.50:9092/C:/Users/PATH_TO_DATABASE", "USER", "PW");
} catch (SQLException e) {
System.err.println("SQLException");
e.printStackTrace();
System.exit(0);
}
}
}
[...]
}
This is the stack trace I get:
SQLException
org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.SocketTimeoutException: connect timed out: 192.168.178.21:9092" [90067-196]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:168)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:457)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:334)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:116)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:100)
at org.h2.Driver.connect(Driver.java:69)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at data.DatabaseConfig.init(DatabaseConfig.java:20)
...
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.h2.util.NetUtils.createSocket(NetUtils.java:103)
at org.h2.util.NetUtils.createSocket(NetUtils.java:83)
at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:115)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:453)
... 8 more
Using the web interface I can connect to both databases easily.
I'm a little bit lost here since I can't figure out what's going wrong with one of the databases. The strange thing is that everything works fine with the other database.
EDIT: I just realized that the IP address in the error message is different from the one in the code (192.168.178.21:9092 vs. 192.168.178.50:9092). Maybe this is th ereason of the error. The one in the code is the correct IP address. Why do I get a different one in the error message? Is that the reason of my problem?
If it's a remote connection, do an ipconfig to find out if the 192.168.x.x. address is changed.
If it's a local connection, you can simplify your URL as
jdbc:h2:~/PATH_TO_DATABASE
I just solved the problem (it was kind of my stupidity): The project couldn't build on the new computer because the H2 jar was not properly included in the build path. That's why eclipse called all the time the old .class file and hence tried to connect to the old computer (192.168.178.21:9092) instead to the new one (192.168.178.50:9092). I didn't realize that eclipse didn't compile and was executing old stuff.
I am new to the concept of OLAP DB.
Please excuse me if I missed out something in the Connection String.
I am trying to connect to connect to Microsoft Analysis Server(which is in different Domain) from my System.
While Connecting I am getting below Error.
Can you please let me know, what am I doing wrong?
I have executed the Steps Mentioned in :
https://msdn.microsoft.com/en-us/library/gg492140.aspx
and referred to the below link for connection to the Cube:
http://www.matthewgodding.com/articles/2010/2/27/getting-data-from-sql-analysis-services-using-java-and-olap4.html
After connecting to the CUbe, I need to execute MDX Query.
Please find the snippet of the code I am using:
public static void main(String[] args) {
try {
Class.forName("org.olap4j.driver.xmla.XmlaOlap4jDriver");
final Connection connection = DriverManager
.getConnection("jdbc:xmla:Server=http://Remote_Server_IPAddress/OLAP/msmdpump.dll;"
+ "Catalog=MyCatalog;"
+ "User='Domian\\Username';" \\ This is the Username to login to the Server
+ "Password='Password';" \\ This is the Password to login to the Server
+ "Cube=Cube;"); \\This is the Cube Name
I get the below Exception when I execute the program:
Exception:
java.lang.RuntimeException: org.olap4j.OlapException: This connection encountered an exception while executing a query.
at org.olap4j.driver.xmla.DeferredNamedListImpl.getList(DeferredNamedListImpl.java:96)
at org.olap4j.driver.xmla.DeferredNamedListImpl.size(DeferredNamedListImpl.java:116)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.getOlapDatabase(XmlaOlap4jConnection.java:451)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.getDatabase(XmlaOlap4jConnection.java:444)
at org.sid.practise.CheckConnection.main(CheckConnection.java:79)
Caused by: org.olap4j.OlapException: This connection encountered an exception while executing a query.
at org.olap4j.driver.xmla.XmlaHelper.createException(XmlaHelper.java:43)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.executeMetadataRequest(XmlaOlap4jConnection.java:878)
at org.olap4j.driver.xmla.XmlaOlap4jDatabaseMetaData.getMetadata(XmlaOlap4jDatabaseMetaData.java:137)
at org.olap4j.driver.xmla.XmlaOlap4jDatabaseMetaData.getMetadata(XmlaOlap4jDatabaseMetaData.java:67)
at org.olap4j.driver.xmla.XmlaOlap4jDatabaseMetaData.getDatabaseProperties(XmlaOlap4jDatabaseMetaData.java:1044)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.makeConnectionPropertyList(XmlaOlap4jConnection.java:324)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.generateRequest(XmlaOlap4jConnection.java:1037)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.populateList(XmlaOlap4jConnection.java:849)
at org.olap4j.driver.xmla.DeferredNamedListImpl.populateList(DeferredNamedListImpl.java:136)
at org.olap4j.driver.xmla.DeferredNamedListImpl.getList(DeferredNamedListImpl.java:90)
... 4 more
Caused by: org.olap4j.driver.xmla.proxy.XmlaOlap4jProxyException: This proxy encountered an exception while processing the query.
at org.olap4j.driver.xmla.proxy.XmlaOlap4jHttpProxy.getResponse(XmlaOlap4jHttpProxy.java:181)
at org.olap4j.driver.xmla.proxy.XmlaOlap4jAbstractHttpProxy.get(XmlaOlap4jAbstractHttpProxy.java:181)
at org.olap4j.driver.xmla.proxy.XmlaOlap4jHttpProxy.get(XmlaOlap4jHttpProxy.java:42)
at org.olap4j.driver.xmla.XmlaOlap4jConnection.executeMetadataRequest(XmlaOlap4jConnection.java:876)
... 12 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.olap4j.driver.xmla.proxy.XmlaOlap4jHttpProxy.getResponse(XmlaOlap4jHttpProxy.java:136)
It's difficult to know what went wrong for you. Few things you could do,
Don't specify cube in connection. This is not listed as property in XMLA driver.
You can install fiddler and see what's going on with the requests.
Not sure if single quotes are needed in user name and password.
I'm trying to write a Java program that will connect to a MongoDB database. I already have the IP address, port, userDB, username, and password of the database I'm trying to access.
I have the mongodb-driver-3.0.0.jar file set as a referenced library in Eclipse. I created a MongoDBDriver.java file in the src folder (shown below):
import com.mongodb.MongoClient;
public class MongoDBDriver {
public static void main(String[] args) {
MongoClient client = new MongoClient("10.66.80.152", 27017);
String connectPoint = client.getConnectPoint();
System.out.println(connectPoint);
client.close();
}
}
When I run the script, I get the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError:
com/mongodb/connection/BufferProvider
at MongoDBDriver.main(MongoDBDriver.java:7)
Caused by: java.lang.ClassNotFoundException:
com.mongodb.connection.BufferProvider
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
So, what am I doing wrong and how can I fix it?
Exception means that you have the class path mismatch.
I create small app that connect java and mongodb and do some CURD operations.
eMongoDB-Java-app
I think it will be better solution to connect database.
MongoClient does not have method getConnectPoint(), class Mongo does.
You can read the official website, it will help you out.mongodb official website java tutorial
I can't seem to get this working. I'm just look at it for basic instruction for a lab, but I've no experience with RMI at all. I can't seem to get why I'm getting the error.
Server
public static void runServer() {
// Install security manager, if none is present
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
Registry registry = LocateRegistry.getRegistry();
System.out.println("Reg: " + registry.toString());
String name = "Server";
Server server = new Server();
I_Server stub = (I_Server) UnicastRemoteObject.exportObject(server, 0);
registry.rebind(name, stub);
System.out.println("All is well :-)\n");
} catch (RemoteException re) {
System.err.println("Remote Exception in DisplayGetEngine.main()\n");
re.printStackTrace();
}
}
}
I have the following run commands and arguments in NetBeans
Arguments: -cp C:\rmi\Server\src;C:\rmi\Server\dist\Server.jar -Djava.rmi.server.codebase=file:/C:/rmi/Server/dist/Server.jar
Working Directory: C:\rmi\Server
My stacktrace is, at the rebind method.
Reg: RegistryImpl_Stub[UnicastRef [liveRef: [endpoint:[10.50.18.205:1099](remote),objID:[0:0:0, 0]]]]
Remote Exception in DisplayGetEngine.main()
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: server.I_Server
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
at sun.rmi.transport.Transport$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at server.Server.runServer(Server.java:50)
at server.Server.main(Server.java:31)
If I don't run rmiregistry, this is my stacktrace
Remote Exception in DisplayGetEngine.main()
java.rmi.ConnectException: Connection refused to host: 10.50.18.205; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at server.Server.runServer(Server.java:50)
at server.Server.main(Server.java:31)
Try calling createRegistry() first to make sure that you have a running registry. Also, port 0 should be a reserved port so you won't be able to make your server listen on that particular port. Try the default one 1099.
There is no problem in running rmiregistry. If you look into the stacktrace closely,the problem seems to be ClassNotFoundException while the arguments are being unmarshalled in the rmi registry. You will have to check the code base of the RMI server whether server.I_Server class is present in the Server.jar while running it in the classpath.
From RMI FAQs
A.4 Why am I getting a ClassNotFoundException?
Most likely the java.rmi.server.codebase property has not been set (or has not been set correctly) on a VM that is exporting your remote object(s). Please take a look at our tutorial, Dynamic code downloading using Java RMI (Using the java.rmi.server.codebase Property).
The issue was in the build file. I needed to insert this statement.
<target name="startRMI" depends="init">
<exec executable="C:\Program\Files\Java\jdk1.7.0_51\jre\bin\rmiregistry"
dir="${build.classes.dir}"></exec>
</target>