Simple RMI problem

I am trying to set up a client server RMI connection, but i get the following error when running the server. I am new to using RMI so any help would be great, thanks so much,
Fred
Exception in thread "main" java.lang.ClassCastExcepti
cast to IMServer
at OutwardFacing.main(OutwardFacing.java:14)
here is my code:
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class OutwardFacing {
     public static void main(String[] args)
     //get the remote object from the registry
          try
     String url = "//localhost/server1";
**14**     IMServer server1 = (IMServer)Naming.lookup(url);
     System.out.println("Got remote object");
     server1.Register("fred", "password");
     server1.ListRegistered();
     catch (RemoteException exc)
     System.out.println("Error in lookup: " + exc.toString());
     catch (java.net.MalformedURLException exc)
     System.out.println("Malformed URL: " + exc.toString());
     catch (java.rmi.NotBoundException exc)
     System.out.println("NotBound: " + exc.toString());
}

Cast the object you're looking up to the remote interface it implements, not to the type of the implementation class.

Similar Messages

  • Problem with a simple RMI program

    I'm trying to get a simple RMI program to work, by following the instructions in this link:
    http://developer.java.sun.com/developer/technicalArticles/RMI/CreatingApps/index.html#dro
    When it gets to this line:
    Lookup look_obj = (Lookup)Naming.lookup(name);this exception is generated:
    java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
    What's wrong, eh?

    Canadian, eh?
    Looks like your security settings on you computer are set to not allow a socket connection.
    Specifically is is saying that access to port 1099 on your local machine (127.0.0.1 is the loopback address) is being denied.
    There are two main reasons this could happen (off the top of my head), though someone else might know from the message exaclty which one.
    1. Your java security permissions do not allow an out going socket connection (are you writing an applet?)
    2. Your computer protects access to port 1099.

  • Simple RMI application

    Hi all
    I've wrote a simple RMI application; I've made a stub and a skeleton and I've started a rmiregistry; when I'm execute a server, I have this exception:
    java.rmi.UnmarshalException: error unmarshalling arguments; ecc.
    Where is the problem?

    Ok, but I'm a student and my teacher wants ....I'm 49 years old and have blond, long hair (other call it grey, but they are
    loonies) and I drive a Ford that doens't want to start when it's freezing
    but that's still no excuse for the RMI mechanism not to work properly ;-)
    Anyway, the problem was an sub-directory; now I catch a
    ConnectException: connection refused (to 127.0.0.1);
    any ideas?Yep, you have to start the server part first and then start your client. I also
    suspect that you don't have the 'rmiregistry' running ... (we can talk about
    that later).
    kind regards,
    Jos

  • Real simple xslt problem/question

    Hi, i have a real simple xslt problem but i just cant figure out how to do it by looking at various examples on the net. i have a xml document and in it are some elements with a "result" tag name. i want to use xslt to reproduce exactly the same xml document except with an attribute called "id" added to those elements with a "result" tag name. i'm sure that theres a simple solution to it but i just cant figure it out. any helps greatly appreciated, thanks

    Start with the XSLT identity transform (I don't have it handy and it's fairly long, but you should be able to google it up). Add this:<xsl:template match="result">
      <result id="">
        <xsl:apply-templates>
      </result>
    </xsl:template>

  • JDeveloper IDE simple setting problem

    Hi,
    Recently we switched to JDeveloper from Visual Cafe .I have a simple setting problem.How can I set the options so that IDE gives, the core java classes and packages,and our application classes and packeges, prompts in imports as well as in code.Where to set the options.
    eg: when I write
    import java. it should prompt all the pakages.
    Thanks in advance.
    -Gopal
    null

    I am not sure I understand what you are requesting, but ...
    You can configure JDeveloper projects to include various libraries by default.
    This is done by selecting menu Tools | Default Project Properties.../ Libraries tab.
    You should define a library for your classes.
    You can import any of the packages / classes from all the libraries which your project includes.
    It would be incorrect for a tool to automatically add a bunch of import lines at the top of every file because each file should import what it needs and just as importantly, not import what it does not need depending on the component type (e.g. a servlet should not include javax.swing.* ).
    An easy way to import elements into JDeveloper is to type in something like:
    import java.
    // and then type in Ctrl Space
    and this launches the package browser, you can select packages or classes to import.
    You can also do this at the variable declaratiton point such as typing in:
    foo() {
    Frame x
    // Press Control Alt Space
    and this will correctly change the type (Frame) to the type you select in the package browser and add the import statement.
    -John
    null

  • Simple OOP Problem. Help!

    This is just a simple OOP problem that i cant decide on a best
    implementation for.
    im passing an object to an instance of, 'TabbedFrame', which is just
    a frame with a Tabbed Pane in it that is holding custom panels.
    however, these custom panels need access to the object being
    passed to 'TabbedFrame' and to some methods in it.
    i cant make them static however so how do i gain access to them?
    is my only option to pass the 'TabbedFrame' to each panel?
    like - jtabbedpane.add( "Panel 1", new mypanel1(this));
    here is code:
    new TabbedFrame( DataObject );
    public class TabbedFrame{
    public TabbedFrame(DataObject do){
    this.do = do;
    jtabbedpane.add( "Panel 1", new mypanel1() );
    DataObject do;
    public class mypanel1{
    public mypanel1(){
    // need access to DataObject of the 'TabbedFrame' object that instantiated
    // this 'mypanel1' and to some of its methods
    }i would just pass the DataObject to evey panel (there are 12) but
    i also need to be able to call methods in the 'TabbedFrame'.
    Any help would be appreciated!

    Modify mypanel1's constructor:
    public class mypanel1{
    TabbedFrame tf;
    public mypanel1(TabbedFrame tf){
    this.tf = tf;
    // need access to DataObject of the 'TabbedFrame' object that instantiated
    // this 'mypanel1' and to some of its methods
    DataObject theDo = tf.getDataObject();
    tf.someMethod(); // Call method on the TabbedFrame
    }In TabbedFrame:
    public TabbedFrame(DataObject do){
    this.do = do;
    // Modify call to constructor to pass "this" TabbedFrame.
    jtabbedpane.add( "Panel 1", new mypanel1(this) );
    }

  • SIMPLE RMI PROB

    I have created a very simple rmi test class passing a bk obkect to a remote library class - the code is below but i keep getting the oops error as specified in the client class - any ideas would be appreciated.
    public class bk{
    String st;
    public bk(String s){
    st=s;
    import java.rmi.*;
    public interface libint extends Remote{
    public void addbook(bk b)throws RemoteException;
    import java.rmi.*;
    import java.rmi.server.*;
    import java.util.*;
    public class lib extends UnicastRemoteObject implements libint{
    Vector v;
    public lib()throws RemoteException{
    Vector v = new Vector();
    System.out.println("lib created");
    public void addbook(bk b){
    v.add(b);
    System.out.println("BOOK ADDED");
    import java.rmi.Naming;
    public class Server{
    public static void main(String args[]){
    try{
    Naming.rebind("libs", new lib());
    System.out.println("System ready");
    catch(Exception e){}
    import java.rmi.Naming;
    public class client{
    public static void main(String args[]){
    try{
    bk b = new bk("john");
    libint li = (libint)Naming.lookup("//127.0.0.1/libs");
    li.addbook(b);
    }catch(Exception e){System.out.println("oops2");}

    I kind of guessed it was something to do with the addbook method but i have no idea why - any suggestions would again be welcome - cheers
    java.lang.NullPointerException
    at lib.addbook(lib.java:15)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    at sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)
    at lib_Stub.addbook(Unknown Source)
    at client.main(client.java:8)

  • Simple RMI error

    Hello,
    I'm trying to compile and execute a simple RMI example. The compilation is OK.
    The rmiregistry is running.
    I'm using windows and java 1.5
    I have the files:
    Server <== the Server
    myStudentImpl <== remote object
    myStudent <== interface
    myStudentImpl_Stub <== the Stub of myStudentImpl (generated by rmic)
    When I'm trying to execute the command from the Server file
    Naming.rebind("john",student);
    I'm getting an error.
    Error:RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: myStudentImpl_Stub
    Then I executed
    C:\myrmi2>java -Djava.rmi.server.codebase=c:/myrmic2 Server
    .... and I got the below error
    Error:Error unmarshaling return; nested exception is:
    java.net.MalformedURLException: unknown protocol: c
    Probably, I have a mistake with the environment variables.
    Can anybody help me, please?
    Thanks

    Now I'm getting
    Error(2):error marshalling arguments; nested exception is:
         java.io.NotSerializableException: testprovider.DS.DS_TicketImpl
    This is my interface
    public interface DS_Ticket extends Remote
    public EncryptedTicket RequestTicket(RequestForTicket req) throws RemoteException;
    This is my return object
    public class EncryptedTicket implements java.io.Serializable
    public byte[] cipherToken2;
    public byte[] cipherSignToken2;
    public byte[] cipherSignature;
    public String Description;
    This is the parameter object
    public class RequestForTicket implements java.io.Serializable
    public PublicKey pubKey;
    public byte[] e_s_Token2;
    public byte[] e_Token2;
    public byte[] BeKey;
    public byte[] BeToken;
    public byte[] signature;
    Any idea what I'm doing wrong?
    Thank you very much

  • How to deploy simple RMI server WLS 7

    Hi,
    I understand that if I write a simple RMI server - not
    extending UnicastRemoteObject, no clustering or IIOP
    issues - I don't need to run an rmic program. I'm not
    clear, however, on what then gets deployed. Does the
    client get the interface or implementation class? And, in
    this simple case, no deployment descriptor configuration
    for RMI is required, correct? I seem to be making this
    harder than it's supposed to be ...
    Thanks, Garry

    Garry, WLS itself is a server , you dont need an additional RMI server. All you need is create an RMI object and bind it to the server JNDI (from the server side) , then your clients can lookup the RMI object via the JNDI and they will get the stubs to make method invocations on the RMI object.
    Check out documentation at :
    http://e-docs.bea.com/wls/docs81/rmi/rmi_api.html#1000008693

  • Problems running a simple RMI

    Hi there,
    I have had alot of problems running a small RMI program.
    It has now boiled down to a java.lang.NoClassDefFoundError
    when i try to use my policy file.
    The program complies, when i run javac *.java
    It also creates the stub, when i run rmic.
    I have trawled alot of forums and the closest answer i got was "add your classpath".
    As im a student of java, this does not really tell me much.
    The class/java files are in
    C:\Documents and Settings\MONDARIZ\workspace\RmiHello\server
    The policy file is also in the folder.
    I must add, that the program is from an example, so i would not think there is any coding errors.
    Also when i run it en eclipse, i get "Hello server failed: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)"
    So it seems something is running.

    The answer you found is correct. Java needs to know where to find the class files for execution.
    For starters, use the environment variable CLASSPATH. Set the value to:
    C:\Documents and Settings\MONDARIZ\workspace\RmiHello\server
    This way whatever you run (RMI Registry, Server, Client) has the proper class path. When you get everything running ok, then you can look into other methods of specifying where the class files are found.
    Eclipse, as well as command line Java starts, need to find the policy file. Set up this:
    -Djava.security.policy=C:\Documents and Settings\MONDARIZ\workspace\RmiHello\server\your_policy_file.xxx

  • Please help with an RMI problem

    Hi,
    This is probably a really simple problem which i can't spot, but i have the folloing 'HelloWorld' RMI program:
    The Client Program:
    import java.rmi.*;
    public class HelloClient {
         public static void main(String args[]) {
              if(System.getSecurityManager() == null) {
                   System.setSecurityManager(new RMISecurityManager());
              try {
                   HelloInterface obj = (HelloInterface)Naming.lookup("/HelloServer");
                   String message = obj.sayHello();
                   System.out.println(message);
                   Thread.sleep(10000);
              } catch (Exception e) {
                   System.out.println("HelloClient exception: " + e);
    }The Remote Interface:
    public interface HelloInterface extends java.rmi.Remote {
         public String sayHello() throws java.rmi.RemoteException;
    }The Server Program:
    import java.io.*;
    import java.rmi.*;
    import java.rmi.server.*;
    import java.util.Date;
    public class HelloServer extends UnicastRemoteObject implements HelloInterface {
         public HelloServer() throws RemoteException {
              super();
         public String sayHello() throws RemoteException {
              return "Hello World, the current system time is " + new Date();
    }And finally the class which binds the object to the registery:
    import java.rmi.*;
    public class RegisterIt {
         public static void main(String args[]) {
              try {
                   HelloServer obj = new HelloServer();
                   System.out.println("Object instantiated: " + obj);
                   Naming.rebind("/HelloServer", obj);
                   System.out.println("HelloServer bound to registery");
              } catch (Exception e) {
                   System.out.println(e);
    }Now, this program works fine on my computer at home(XP!!!!!) but when i try to run it on the computers in college which run NT, it comes up with the following exceptions when i try to run RegisterIt:
    Java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    Java.lang.ClassNotFoundException: HelloServer_StubThis is saying that it cannot find the stub which is generated, but i use the folloing .bat file to load up the program:
    echo Creating remote object skelton classes....
    rmic -d . HelloServer
    start rmiregistry -J-Djava.security.policy=test.policy
    start java RegisterIt
    start java -Djava.security.policy=test.policy HelloClientThe stub is definitely created(it worked at home and i have checked in the directory and there are clearly the files HelloServer_Stub.class and HelloServer_Skel.class). The PATH is set correctly otherwise the registery would not be able to run correctly etc and therefore i am completely stuck as to why it doesn't work.
    Please help as it is very important for me.
    Many Thanks
    Cath

    I did not have any problem with Windows 2000 at all but only with Windows XP (and to think XP is a 2000 hybrid!).
    I have the same error: a ClassNotFoundException on the stub file.
    Any help will be appreciated. Thanks.

  • Help! simple RMI app with Linux

    Hello,
    I am quite new to RMI, so I think this problem might be a simple one, but I don't get it.... I try to set up a sample RMI Demo on Suse Linux 9.3 with jdk1.5.0_02.
    On WIndows XP, everything is working just fine...same JDK, same environment vars, same java code. On Linux, I get the following error whne launchin the server (rmiregistry is running):
    non-JRMP Server at remote endpointhere's my Server Code:
    RemoteDateImpl im = new RemoteDateImpl();
    Registry r = LocateRegistry.getRegistry();
    Naming.rebind(RemoteDate.LOOKUPNAME,im);...an the Interface RemoteDate:
    public interface RemoteDate extends Remote
         public Date getRemoteDate() throws java.rmi.RemoteException;
         public final static String LOOKUPNAME = "rmi://192.168.0.1:1099/RemoteDate";
    }at last the Implementation Code:
    public class RemoteDateImpl extends UnicastRemoteObject implements RemoteDate
         public RemoteDateImpl() throws RemoteException
              super();
         public Date getRemoteDate() throws RemoteException
              return new Date();
    }so what is going wrong here?

    hello!!
    the only thing that comes to my mind regarding this exception is that the port 1099 might be in use by some other program (and rmiregistry is starting at a diff port)...
    try starting it manually at a different port to see what happens...
    are you running plain rmi? or rmi iiop?

  • Help me to run this simple RMI example

    When i m running this example in standalone pc it works but while running on to different pc it gives error though I m giving the IP address from client of server.. If anyone can help me out plz help.
    Code:
    ReceiveMessageInterface
    import java.rmi.*;
    public interface ReceiveMessageInterface extends Remote
    void receiveMessage(String x) throws RemoteException;
    Server code:
    import java.rmi.*;
    import java.rmi.registry.*;
    import java.rmi.server.*;
    import java.net.*;
    public class RmiServer extends java.rmi.server.UnicastRemoteObject
    implements ReceiveMessageInterface
    int thisPort;
    String thisAddress;
    Registry registry; // rmi registry for lookup the remote objects.
    // This method is called from the remote client by the RMI.
    // This is the implementation of the �ReceiveMessageInterface�.
    public void receiveMessage(String x) throws RemoteException
    System.out.println(x);
    public RmiServer() throws RemoteException
    try{
    // get the address of this host.
    thisAddress= (InetAddress.getLocalHost()).toString();
    catch(Exception e){
    throw new RemoteException("can't get inet address.");
    thisPort=3232; // this port(registry�s port)
    System.out.println("this address="+thisAddress+",port="+thisPort);
    try{
    // create the registry and bind the name and object.
    registry = LocateRegistry.createRegistry( thisPort );
    registry.rebind("rmiServer", this);
    catch(RemoteException e){
    throw e;
    static public void main(String args[])
    try{
    RmiServer s=new RmiServer();
    catch (Exception e) {
    e.printStackTrace();
    System.exit(1);
    Client code:
    import java.rmi.*;
    import java.rmi.registry.*;
    import java.net.*;
    public class RmiClient
    static public void main(String args[])
    ReceiveMessageInterface rmiServer;
    Registry registry;
    String serverAddress=args[0];
    String serverPort=args[1];
    String text=args[2];
    System.out.println("sending "+text+" to "+serverAddress+":"+serverPort);
    try{
    // get the �registry�
    registry=LocateRegistry.getRegistry(
    serverAddress,
    (new Integer(serverPort)).intValue()
    // look up the remote object
    rmiServer=
    (ReceiveMessageInterface)(registry.lookup("rmiServer"));
    // call the remote method
    rmiServer.receiveMessage(text);
    catch(RemoteException e){
    e.printStackTrace();
    catch(NotBoundException e){
    e.printStackTrace();
    }

    When we compile with rmic skeleton and stub get created then we hav to place stub at each client ???Your remote client applcation need only _Stub.class fiels.
    Is there way by which we can know how many clients are connected to the
    server and there IP address, can anyone give the code... I guess that you should use a RMI login/logout method to register/unregister your client connection information into a databse or a simple static Hashtable(Vector) object.

  • Simple button problem

    I am having a real problem creating a simple button - I have
    created a Flash file using Action script 2, and when I create a
    simple button - text with a rectangle as a background, (see
    http://www.elkhavenestate.com),
    and the over state is behaving in a bizarre fashion. This is my
    first time using CS3, so is there a new control that I'm
    missing?

    I take it that it's the Home button. It appears to have a
    selectable text field or something in it, which is causing the
    problem. Either change that to a static text field or set its
    selectable property to false. The other two buttons appear to be
    fine, so maybe you can just duplicate one of them and turn it into
    the Home button.
    If I picked the wrong button, let me know.

  • Simple RMI over HTTP in MIDP1.0 - open source project

    Hi All,
    For anyone interested in doing remote method calls (over HTTP) to a server from a MIDP 1.0 MIDlet there is an open source project now available for this. Please see MeRMI (Micro Edition RMI) at:
    http://mermi.dev.java.net
    You can use this to create a remote server class, much like you would in RMI. MeRMI then generates classes to do the remote communications for you. So you can just make nice, simple Java calls from your MIDlet, without having to worry about how the calls are passed to the server, etc. It's all pretty easy to use (especially if you have used RMI before) and takes a lot of the hard work out of building network applications.
    The toolkit is completely free (LGPL) and open source, you can use the code and do what you want with it.
    Hope it comes in useful to someone!
    zonski.
    Note: MeRMI does not support callbacks, but an event mechanism using blocking, polling requests can be used to create server to client messaging.

    It sounds interesting. It is only for MIDP 1.0?, what about MIDP 2.0?

Maybe you are looking for

  • Error while using MS Word with BI Publisher

    Hi All, I am working on XML publisher while opening the fields in the designed RTF it is saying the error like "Automation error,Unspecified error". Please suggest me on this. Thanks, Surya

  • Contact Form Issues When Email Received.

    Using the standard detailed contact form widget by Adobe, I added a few extra input boxes, I then moved them around so that the 'message' box was at the bottom. When testing the contact form the input from the 'message' box was in the middle with the

  • How to make the field as mandatory in module pool program.

    Hi Experts, Could you please advice me in making a screen field as mandatory input field in module pool programming. Thanks in advance.

  • Account for purchase orders

    Hello to everyone, how can I set in display mode the account number in a purchase order at item level?, because now it is possible to modify the value that appears by default. Regards

  • CF9 and Ehcache

    After ready an interesting article recently about CF and Ehcache (http://java.dzone.com/articles/building-high-performance), I became curious about the mention of using CF and Ehcache for Distributed Transactions.  Spent some time looking around, but