Results 1 to 2 of 2
  1. #1
    bigmac15 is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default java.rmi.UnmarshalException; on client side

    Java Code:
    //implementation of the remote interface
    
    import java.rmi.*;
    import java.rmi.server.*;
    import java.sql.*;
    import java.util.ArrayList;
    import java.net.*;
    import java.io.*;
    import java.applet.*;
    import java.io.Serializable;
    
    class DuplicatedAddressException extends RemoteException implements Serializable {
    	DuplicatedAddressException() { }
    	DuplicatedAddressException(String s) { super(s); }
    }
    
    public class DataAccessImpl extends UnicastRemoteObject implements DataAccess
    {
    	private String name;
    	static final String driverName = "com.mysql.jdbc.Driver";
    	static final String sysName = "zenit.senecac.on.ca";
    	static final String dbName = "--";
    	static final String userId = "--";
    	static final String password = "--";
    	private ArrayList alAddress = new ArrayList();
    	private ArrayList alX = new ArrayList();
    	private ArrayList alY = new ArrayList();
    	private Connection conn;
    	
    	
    	
    	public DataAccessImpl(String s) throws java.rmi.RemoteException
    	{
    		name = s;
    		try
    		{
    			Class.forName(driverName);
    		}
    		catch(ClassNotFoundException ec)
    		{
    			ec.printStackTrace();
    			System.out.println("MySQL JDBC driver not found!");
    			System.exit(1);
    		}
    		System.out.println("JDBC class found");
    	}
    	public boolean connectToDatabase() throws java.rmi.RemoteException
    	{
    		System.out.println("Connection to the MYSQL server: " + sysName + "...");
    		try
    		{
    			conn = DriverManager.getConnection("jdbc:mysql:" + "//" + sysName 
    					+ "/" + dbName, userId, password);
    			Statement stat = conn.createStatement();
    			ResultSet rs = stat.executeQuery("SELECT * FROM locations");
    			System.out.println("**Query Result**");
    			while(rs.next())
    			{
    				alAddress.add(rs.getString(1));
    				alX.add(rs.getDouble(2));
    				alY.add(rs.getDouble(3));
    			}
    			for(int i = 0; i < alAddress.size(); i++)
    			{
    				System.out.println(alAddress.get(i) + " "
    						+ alX.get(i) + " " + alY.get(i));
    			}
    			rs.close();
    			stat.close();
    		}
    		catch(SQLException exc)
    		{
    			System.out.println("connection failed with: " + exc.getMessage());
    			return false;
    		}
    		System.out.println("database connection-OK");
    		GetClientIP getIp = new GetClientIP();
    		return true;
    	}
    	public boolean disconnectToDatabase() throws java.rmi.RemoteException
    	{
    		System.out.println("Close the database connection....");
    		try
    		{
    			if(conn != null)
    				conn.close();
    		}
    		catch(SQLException se) {se.printStackTrace(); return false;}
    		System.out.println("disconnected from database....");
    		alAddress = new ArrayList();
    		alX = new ArrayList();
    		alY = new ArrayList();
    		return true;	
    	}
    	public boolean add(Location l) throws java.rmi.RemoteException, DuplicatedAddressException
    	{
    		//boolean flag = true;
    		for(int checkDup = 0; checkDup < alAddress.size();checkDup++)
    		{
    			if(l.getAddress().equals(alAddress.get(checkDup).toString()))
    				{
    					throw new DuplicatedAddressException( "The address you entered is already inserted" );
    					//flag = false;
    				}
    		}
    		alAddress.add(l.getAddress());
    		alX.add(l.getX());
    		alY.add(l.getY());
    		/*for(int i = 0; i < alAddress.size(); i++)
    		{
    			System.out.println(alAddress.get(i) + " "
    					+ alX.get(i) + " " + alY.get(i));
    		}*/
    		try
    		{
    			int getSize = alAddress.size();
    			Statement stat = conn.createStatement();
    			stat.executeUpdate("INSERT INTO locations ( address, coorx, coory )" +
    					" VALUES ('" + alAddress.get(getSize-1).toString() + "', '" + Double.parseDouble(alX.get(getSize-1).toString()) + "', '" + Double.parseDouble(alY.get(getSize-1).toString()) + "')");
    			alAddress = new ArrayList();
    			alX = new ArrayList();
    			alY = new ArrayList();
    			ResultSet rs = stat.executeQuery("SELECT * FROM locations");
    			System.out.println("**Query Result**");
    			while(rs.next())
    			{
    				alAddress.add(rs.getString(1));
    				alX.add(rs.getDouble(2));
    				alY.add(rs.getDouble(3));
    			}
    			for(int i = 0; i < alAddress.size(); i++)
    			{
    				System.out.println(alAddress.get(i) + " "
    						+ alX.get(i) + " " + alY.get(i));
    			}
    			rs.close();
    			stat.close();
    		}
    		catch (SQLException exc)
    		{
    			System.out.println("query failed with: " + exc.getMessage());
    			return false;
    		}
    		return true;
    	}
    	
    	public Location[] createReport() throws java.rmi.RemoteException
    	{
    		int locationSize = alAddress.size();
    		String tempAddress;
    		double tempX;
    		double tempY;
    		Location[] retLocations = new Location[locationSize];
    		for(int i=0;i<locationSize;i++)
    		{
    			tempAddress = alAddress.get(i).toString();
    			tempX = Double.parseDouble(alX.get(i).toString());
    			tempY = Double.parseDouble(alY.get(i).toString());
    			retLocations[i] = new Location(tempAddress, tempX, tempY);
    			//retLocations[i].set(tempAddress, tempX, tempY);
    			//retLocations[i].display();
    		}
    		//System.out.println(locationSize);
    		return retLocations;
    	}
    	
    	public class GetClientIP extends Applet 
    	{
    		  public GetClientIP() 
    		  {
    			    try 
    			    {
    				     InetAddress thisIp =
    				        InetAddress.getLocalHost();
    				     System.out.println("Clients IP: " + thisIp.getHostAddress());
    			    }
    			    catch(Exception e) 
    			    {
    			     	e.printStackTrace();
    			    }
    		   }
    	}
    }
    The DuplicatedAddressException works on the client side (in a try and catch it catches when a duplicate entry is made) but it gives me the errors

    java.rmi.UnmarshalException; error unmarshaling retun; nested exception is:
    java.lang.ClassNotFoundException: DuplicatedAddressException <no security manager:
    RMI class loader disabled>

  2. #2
    gauravfzd's Avatar
    gauravfzd is offline Member
    Join Date
    Oct 2010
    Location
    India
    Posts
    72
    Rep Power
    0

    Default

    Use policy file in your application. On both sides i.e. at the server side and at client side.
    To create a policy file use the command "policytool" provided with the jdk.

    In your code use

    Java Code:
    if(System.getSecurityManager() == null){
         System.setSecurityManager(new RMISecurityManage());  
    }
    after that start the program with the following switch:

    >java -Djava.security.policy=<PathToPolicyFile> <Your Class having Main method.>

Similar Threads

  1. Need help in socket programming, client side.
    By rushabh in forum Networking
    Replies: 0
    Last Post: 01-20-2011, 07:33 PM
  2. session management ON CLIENT SIDE.
    By alfonz19 in forum Java Servlet
    Replies: 1
    Last Post: 01-15-2011, 03:57 PM
  3. Replies: 1
    Last Post: 03-20-2010, 07:03 PM
  4. Replies: 2
    Last Post: 05-07-2009, 04:06 AM
  5. Replies: 1
    Last Post: 03-27-2009, 10:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •