Application-Independent Middleware
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Merag_M
Posted On:   Thursday, May 19, 2005 03:24 PM

Hi, This project is about designing application independent middleware.I used JAVA to write client applications and server interface.There is a problem I guess it is on RMI functionality coz this code do not connect well to database. If any one interest mail me to meno_80@yahoo.com //---------------------------CLIENT-SIDE FOLDER-------------------// /////////////fILE1 "ClientApplication.java"//////////////////// import java.rmi.*; import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.server.*; import java.rmi.registry.*; import java.util.*; import java.rmi.server.*; import java.rmi.RMISecurityManager; import java.rmi.server.Uni   More>>

Hi, This project is about designing application independent middleware.I used JAVA to write client applications and server interface.There is a problem I guess it is on RMI functionality coz this code do not connect well to database. If any one interest mail me to meno_80@yahoo.com

			

//---------------------------CLIENT-SIDE FOLDER-------------------//
/////////////fILE1 "ClientApplication.java"////////////////////
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import java.rmi.server.*;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;
public class ClientApplication{
// constructor
public ClientApplication() {
// do nothing !
}
// main program
public static void main(String[] args) {


try{

//connect with server
Environment e=new Environment("localhost","6500","Flight");

//Create connection
Connexion C=new Connexion(e);

C.Connection("jdbc:odbc:Alia","","");

Requte R=C.Create_Requte();

Result RS=R.ExcuteQuery("select arrivalTime from FlightTimes where flightNo = " + args[0] );



} //end try


catch ( Exception e)
{ System.out.println ("Error: " + e);
} // end catch
} // end of main

}//end class



///////////FILE2 "ServerInterface.java"//////////////////
import java.rmi.*;


public interface ServerInterface extends java.rmi.Remote
{
public int Create_Connexionss() throws java.rmi.RemoteException ;

public void Establish_Connection(String dbName,String UserName, String Pwd, int index) throws java.rmi.RemoteException ;


public int Create_Requtess(int i) throws java.rmi.RemoteException ;

public int Create_Resultss(int i,String query)throws java.rmi.RemoteException ;

} //end of interface


/////////////////FILE3"Environment.JAVA"/////////////////
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import java.rmi.server.*;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;
public class Environment{
private ServerInterface myI;

//constructor
public Environment(String IP_add,String Port_no,String Service_name)
{
try {
ServerInterface myI=(ServerInterface) Naming.lookup("rmi://" + IP_add + ":" + Port_no + "/" + Service_name);
}
catch (NotBoundException nbe) {

System.out.println(nbe.getMessage());
}//end catch nbe

catch (java.net.MalformedURLException mfu) {

System.out.println(mfu.getMessage());
}//end catch mfu

catch (RemoteException re) {

System.out.println(re.getMessage());
}//end catch nbe
}

public ServerInterface getServerInterfaceObject()
{
return myI;
}

}//end class

/////////////////////////FILE4 "Connexion.JAVA" ////////////////////
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import java.rmi.server.*;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;


public class Connexion{
private ServerInterface myI;
private int index;

//constructor
public Connexion(Environment e)
{
myI=e.getServerInterfaceObject();
try {

index=myI.Create_Connexionss();
}

catch ( Exception err)
{ System.out.println ("Error: " + err);
} // end catch


}

public void Connection(String dbName,String userName,String Pwd) throws RemoteException
{
try{

myI.Establish_Connection(dbName,userName,Pwd,index);
}

catch (Exception e) {
throw new RemoteException(e.getMessage());
}
}


public Requte Create_Requte() throws RemoteException
{
try
{
int i;
Requte O;
i=myI.Create_Requtess(index);
O=new Requte(i,myI);
return O;
}


catch (Exception e) {
throw new RemoteException(e.getMessage());
}

}



}//end class
//////////////////////////////FILE5 "Requete.java"/////////////
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import java.rmi.server.*;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;

public class Requte{
private int index;
private ServerInterface myI;


//constructor
public Requte(int i,ServerInterface myInterface)
{
index=i;
myI=myInterface;
}
public Result ExcuteQuery(String query) throws RemoteException
{
try{
int i;
i=myI.Create_Resultss(index,query);
Result O=new Result(i,myI);
return O;
}
catch (Exception e) {
throw new RemoteException(e.getMessage());
}
}



}//end class
/////////////////////////////FILE 6 "Result.java"//////////////////
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import java.rmi.server.*;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;

public class Result{
private ServerInterface myI;
private int index;

//constructor
public Result(int i,ServerInterface myInterface)
{
index=i;
myI=myInterface;
}
} //end class

//---------------------------SERVER-SIDE FOLDER-------------------//

/////////////////////////////FILE1 "ServerApplication.JAVA"/////////////
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import java.rmi.server.*;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;

public class ServerApplication{
public static void main(String[] args) {
//if (System.getSecurityManager() == null) {
// System.setSecurityManager(new RMISecurityManager());
//}
try {
//create object of ServerImplementation
ServerImplementation myService=new ServerImplementation();

LocateRegistry.createRegistry(6500);

//register the created object in RMI registry
Naming.rebind("rmi://localhost:6500/Flight", myService);

System.out.println("The server is waiting request on port 6500 ...");
}// end try

catch(Exception ex) {
System.out.println("Hello : There is a problem ...."+ex.getMessage());
ex.printStackTrace();
}//end catch

}// end main

} // end class ServerApplication

//////////////////////////FILE2 "ServerImplementation.JAVA"/////////////
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import java.rmi.server.*;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;
import java.net.*;
import java.sql.*;

public class ServerImplementation extends UnicastRemoteObject implements ServerInterface{
private Connexionss table_Connexionss[];
private int last_conn;

private Requtess table_Requetss[];
private int last_stm;

private Resultss table_Resultss[];
private int last_set;

//------------------------------------------------------
//constructor
public ServerImplementation() throws RemoteException
{
super();
try{
//do nothing

} //end try


catch (Exception e) {
throw new RemoteException(e.getMessage());
}

}//end constructor

//------------------------------------------------------
public int Create_Connexionss() throws RemoteException
{
int i=0;
try{

Connexionss Q=new Connexionss();
table_Connexionss[last_conn]=Q; //saving obj in server
i=last_conn;
last_conn++;

} //end try

catch (Exception e) {
throw new RemoteException(e.getMessage());
}

return i;

} //end function
//------------------------------------------------------

public void Establish_Connection(String dbName,String UserName, String Pwd, int index) throws RemoteException
{
try{
//get reference of myI
Connexionss Q=table_Connexionss[index];
Q.Connect(dbName,UserName,Pwd);
} //end try

catch (Exception e) {
throw new RemoteException(e.getMessage());
}
}
//------------------------------------------------------

public int Create_Requtess(int i) throws RemoteException
{
try{
int j=0;
Requtess O=new Requtess();
Connexionss css=table_Connexionss[i]; //return connexionss obj from server

css.CreatejdbcStatment(O); //link with object O
table_Requetss[last_stm]=O; //save object in server
j=last_stm;
last_stm++;

return j;
}//end try

catch (Exception e) {
throw new RemoteException(e.getMessage());
}

}

//------------------------------------------------------
public int Create_Resultss(int i,String query) throws RemoteException
{
try{
int j=0;
Resultss O =new Resultss();
Requtess rss=table_Requetss[i]; //return Requtess object from server
rss.excutejdbcStatment(O,query);
table_Resultss[last_set]=O;
j=last_set;
last_set++;

return j;
} // end try

catch (Exception e) {
throw new RemoteException(e.getMessage());
}

}


}//end of class
////////////////////////////////////FILE3 "Connexionss.java"///////////
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import java.rmi.server.*;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;
import java.sql.*;

public class Connexionss{
private Connection con;


public void Connect(String dbName,String UserName,String Pwd) throws Exception
{
try{
con = DriverManager.getConnection(dbName,UserName,Pwd);
System.out.println ("The connection apparently succeeded");
}
catch (SQLException se) {
throw new RemoteException(se.getMessage());
}
}

public void CreatejdbcStatment(Requtess O) throws Exception
{
try{
Statement S; //jdbc statment
S=con.createStatement();
O.SetjdbcStatment(S);
}
catch (SQLException se) {
throw new RemoteException(se.getMessage());
}
}

} //end class

///////////////////////////FILE4 "Requtess.JAVA"////////////////////////
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import java.rmi.server.*;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;
import java.sql.*;

public class Requtess{
private Statement req;

public void SetjdbcStatment(Statement s)
{
req=s;
}

public void excutejdbcStatment(Resultss x, String query) throws RemoteException
{
try{

ResultSet rst; //jdbc resultset object
rst= req.executeQuery(query);

x.SetjdbcResult(rst);

} //end try

catch (Exception e) {
throw new RemoteException(e.getMessage());
}


}

} //end class
/////////////////////////////FILE5 "Resultss.JAVA"////////////////////
import java.rmi.*;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.*;
import java.rmi.server.*;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;
import java.sql.*;

public class Resultss{
private ResultSet res=null;

public void SetjdbcResult(ResultSet rst)
{
res=rst;
}
} //end class
   <<Less
About | Sitemap | Contact