//GetUserInfo.java
package pvgs;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
public class GetUserInfo {
final String DATABASE_URL = "jdbc:odbc:MySQLDB";
final String DATABASE_USERNAME = "sa";
final String DATABASE_PASSWORD = "";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
public HashMap getAccountInfo() {
HashMap result = new HashMap();
getConnection();
int i = 0;
try {
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM BANKACCOUNT");
while (rs.next()) {
result.put(String.valueOf(i++), rs.getString("AccountNo"));
result.put(String.valueOf(i++), rs.getString("AccountAmount"));
}
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}
public Connection getConnection() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(DATABASE_URL, DATABASE_USERNAME,
DATABASE_PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
}
//XmlRpcServiceServer.java
package pvgs;
import java.io.IOException;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.WebServer;
public class XmlRpcServiceServer {
private static final int port = 9999;
public static void initXMLRpcServer() {
WebServer webServer = new WebServer(port);
XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
PropertyHandlerMapping phm = new PropertyHandlerMapping();
try {
phm.addHandler("userInfo", pvgs.GetUserInfo.class);
xmlRpcServer.setHandlerMapping(phm);
XmlRpcServerConfigImpl serverConfig = (XmlRpcServerConfigImpl) xmlRpcServer
.getConfig();
serverConfig.setEnabledForExtensions(true);
serverConfig.setContentLengthOptional(false);
System.out.println("Starting the server....");
webServer.start();
} catch (XmlRpcException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException, XmlRpcException {
initXMLRpcServer();
}
}
//XmlRpcServiceClient.java
package pvgs;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Array;
import java.util.*;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
public class XmlRpcServiceClient {
public static void main(String[] args)
{
try {
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://127.0.0.1:9999"));
config.setEnabledForExtensions(true);
config.setConnectionTimeout(60 * 1000);
config.setReplyTimeout(60 * 1000);
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
List params = new ArrayList();
HashMap data = (HashMap) client.execute("userInfo.getAccountInfo",
params);
for (int i = 0; i < data.size(); i++)
System.out.println(data.get(String.valueOf(i)));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (XmlRpcException e) {
e.printStackTrace();
}
}
}