Can a remote service return a remote object?

Hi all,
please consider a business logic for a typical forum service :
public interface ForumManager extends Remote
Forum createNewForum(String Name);
Forum getForum(String Name);
public interface Forum extends Remote
void postNewArticle(String Title, String Content);
Article [] getArticles();
public class Article implements Serializable
There are two interfaces of remote objects: ForumManager and Forum, both of two interfaces are extended from interface Remote. I created two classes implementing these interfaces respectively, and created two stub classes from the implementation with rmic.
As the logic, a ForumManager creates and manages forums on the server. A client can retrieve a remote stub of a forum instance from the manager stub, and post articles to the forum stub. The forum stub then sends the new articles to the real ForumImpl on the server, and the real implementation of Forum on the server then save the articles into disks or DBs. So, you can see, the most important thing is that clients have to be able to get the stub of a forum.
Codes in createForum() of the implementation class of ForumManager is like this:
ForumImpl TheNewForum = new ForumImpl(this.getRef());
// ^ Because ForumImpl is a remote object, without a ref, it can not be marshaled.
ForumTable.put(Name, TheNewForum);
return TheNewForum;
The problem is, the Forum instance my client retrieved from FourmManagerImpl_Stub (gotten from Naming.lookup()) is a ForumImpl, but not a Forum_Stub. So that articles posted to the forum will not be sent to the server, and different clients can not share articles with each other. I found a bunch of documents about RMI, but they did not illustrated how to retrieve a stub of a remote object from another remote object (like a manager). If you know how to cope this problem, please tell me.
Edited by: DBPZ on Apr 2, 2008 3:33 AM

why does this base class exist?It's really only there to support stubs. The only thing it gives you over Object is the remote equality semantics, and only stubs need that. (It also provides the RemoteReference but only RMI needs that, internally, you don't.)
When should we use RemoteObject instead of UnicastRemoteObject?Never, but if you do, or you use Object (or indeed anything other than UnicastRemoteObject and Activatable), you have to export it yourself as indicated above.

Similar Messages

  • Can a WCF Service return a Datatable ??

    The snippet shown below is not working ??? Why is it 
    namespace MLA_CRM_Service
        [DataContract]
        public class MLAContact : DataTable  //(Cant i do this ?)
            [DataMember]
            private string MLAMemberType;
            [DataMember]
            private string MLAMemberNo ;
            [DataMember]
            private string fullName;
            [DataMember]
            private string companyName;
            [DataMember]
            private string addressLine1;
            [DataMember]
            private string addressLine2;
            [DataMember]
            private string suburb;
            [DataMember]
            private string state;
            [DataMember]
            private string postCode;
            [DataMember]
            private string country;
            [DataMember]
            private string emailAddress;
            [DataMember]
            public string _MLAMemberType
                get;
                set;
            [DataMember]
            public string _MLAMemberNo
                get;
                set;
            [DataMember]
            public string FullName
                get;
                set;
            [DataMember]
     .// All Getters and setter are implemented 
            [DataMember]
            public string EmailAddress
                get;
                set;
     public MLAContact()
                this.Columns.Add(new DataColumn("MLAMemberType", typeof(string)));
                this.Columns.Add(new DataColumn("MLAMemberNo", typeof(string)));
                this.Columns.Add(new DataColumn("FullName", typeof(string)));
                this.Columns.Add(new DataColumn("CompanyName", typeof(string)));
                this.Columns.Add(new DataColumn("AddressLine1", typeof(string)));
                this.Columns.Add(new DataColumn("AddressLine2", typeof(string)));
                this.Columns.Add(new DataColumn("Suburb", typeof(string)));
                this.Columns.Add(new DataColumn("State", typeof(string)));
                this.Columns.Add(new DataColumn("PostCode", typeof(string)));
                this.Columns.Add(new DataColumn("Country", typeof(string)));
                this.Columns.Add(new DataColumn("EmailAddress", typeof(string)));
    public DataRow AddRows(usp_SecondaryContactCollectionResult content) {
    DataRow dr = this.NewRow(); dr["FullName"] = content.FullName.ToString();
    dr["EmailAddress"] = content.emailaddress.ToString(); return dr;
    public DataRow AddRows(usp_GetUserDetailsResult content) {
    DataRow dr = this.NewRow(); dr["MLAMemberType"] = content.MLAMemberType;
    dr["MLAMemberNo"] = content.MemberNumber;
    dr["FullName"] = content.FullName;
    dr["CompanyName"] = content.CompanyName;
    dr["AddressLine1"] = content.AddressLine1;
    dr["AddressLine2"] = content.AddressLine2;
    dr["Suburb"] = content.Suburb;
    dr["State"] = content.State;
    dr["PostCode"] = content.PostCode;
    dr["Country"] = content.Country;
    dr["EmailAddress"] = content.emailaddress;
    return dr;
    Now the Service method implementation
    public DataTable SecondaryContactCollection(int contactID, string token)
                try
                    using (ContactDataContext = new MLAWebUsers_ContactsDataContext())
                        MLAContact mlaContact = new MLAContact();
                        DataTable dt = new MLAContact();
                       var container = ContactDataContext.usp_SecondaryContactCollection(contactID, token);
                        foreach (usp_SecondaryContactCollectionResult item in container)
                            dt.ImportRow( mlaContact.AddRows(item));
                        return dt;
                catch (Exception ex)
                    throw ex;
    Now the above code compiles perfectly .... But when i try to consume it in the client side ...
    Exception is thrown 
    Client side Code
    protected void Page_Load(object sender, EventArgs e)
                    DataTable dt = new DataTable();
                    int i = 0;
                    int a = 145417;
                    string x = "A1F3CKeog&";
                    MLA_CRM_ServicesClient clientEndPoint = new MLA_CRM_ServicesClient("BasicHttpBinding_IMLA_CRM_Services");
                    dt = clientEndPoint.SecondaryContactCollection(a, x);
                    i = dt.Rows.Count;
                    Label1.Text = i.ToString();
    The above line that is Bold in the client code, thats the place where the exception is thrown .... Have gone through the stack trace still not able to fix it !!!!
    Regards,
    Chandra.

    you have two options
    Option 1
    Simply give your Table a name. If you don’t,it will block the client and time out which throws an unexpected exception.
    DataTable dt = new MLAContact("SomeTableName");
    Option 2
    Create a dataset and Add your datatable and return datatable from dataset i.e
    DataTable dt = new MLAContact();
    DataSet ds =
    new
    DataSet
    ds.Tables.Add(dt);
    return
    ds.Tables[0];
    Reason:
    The root reason is the DataTable inside a dataset inherits a schema namespace from the dataSet, but an independent datatable has an empty namespace (unless we change it).  Data cannot be changed between two dataTables with different namespace.
    If
    this helps do not forget to mark it as Answer
      I would recomend you to go ahead with Option 1. And share your views.
    Lingaraj Mishra

  • Data service returning an empty object

    Hi
    I am trying to call a data service from the flex to load my
    data grid. In the debug, i saw that the arrraycollection in the
    fill method is being returned empty. here are the details....
    My .java file has the same names with the set and get
    functions which are set by my java assembler class.
    I am calling other fill methods and they seems to be working
    fine except this one....

    The problem was that the name of the destination
    "codecoverage" was same as that of one of the packages where my
    .java file was there. Changed this name and things started to
    work..:-)

  • Can MDM Web Services return qualifier values?

    We are running MDM 5.5 SP06 Patch04 (we will be doing a technical upgrade to MDM 7 later this year).
    I am investigating the MDM web services and came upon a potential problem. In the test harness, I searched for a record, specifying ALL for the result definition and everything seemed to come back except qualifiers; lookup values came back, taxonomy values came back, qualified lookup display values came back, qualified link ids came back, but no qualifier values.
    I searched again on the qualified link record ids in the qualified lookup table and I got the non-qualifiers, which is the expected behavior. The qualifiers have to come back with the main table record, though.
    Are qualifiers not fully supported in the MDM 5.5 web services, or am I not searching properly?
    Thanks for any help you can provide.
    Doug

    Hi Doug
    For me all  are working good.
    Can you look at pages 24-26 from "Portal content development guide"
    https://websmp201.sap-ag.de/~sapidb/011000358700001119612007E
    Regards
    Kanstantsin

  • Remote object trying to return another remote object and a ClassCastExcepti

    I have a server running with a TreeModel (the tree model implements Remote). I also have the the TreeNodes all linked together on the server. Now, I can get to the TreeModel on the server and the root node of the remote tree model.
    treeModelStub = (treeModelIface)Naming.lookup(url+"remoteTM"); //works
    rootStub = (remoteTreeNodeIface)treeModelStub.getRoot(); //works. The call to getRoot returns Object
    But when I call
    remoteTreeNodeIface aChild = (remoteTreeNodeIface)rootStub.getChildAt(index) //Does not work. "Exception in thread "main" java.lang.ClassCastException
    at remoteTreeNode_Stub.getChildAt(Unknown Source)
    The remote tree node method getChildAt returns TreeNode because the class implements TreeNode:
    public class remoteTreeNode extends UnicastRemoteObject implements rdcaDataIface, Comparable, TreeNode {
    public TreeNode getChildAt(int idx) {
    System.out.println("DEBUG: class is "+this.getClass()); // class is remoteTreeNode
    return (remoteTreeNode)children.get(idx);
    The remote interface is defined as:
    public interface rdcaDataIface extends java.rmi.Remote {
    public TreeNode getChildAt(int idx) throws RemoteException;
    Any ideas why this does not work. Why can a remote object of type Object be returned just fine, but a TreeNode not be returned?
    Thank you for your help,
    Brent

    I have a server running with a TreeModel (the tree
    model implements Remote). I also have the the
    TreeNodes all linked together on the server. Now, I
    can get to the TreeModel on the server and the root
    node of the remote tree model.
    treeModelStub =
    (treeModelIface)Naming.lookup(url+"remoteTM");
    //works
    rootStub =
    (remoteTreeNodeIface)treeModelStub.getRoot();
    //works. The call to getRoot returns Object
    But when I call
    remoteTreeNodeIface aChild =
    (remoteTreeNodeIface)rootStub.getChildAt(index)******************************************
    can only be casted to rdcaDataIface. The returned object is an instanceof the rdcaDataIface_stub, which have nothing to do with TreeNode.
    //Does not work. "Exception in thread "main"
    java.lang.ClassCastException
    at remoteTreeNode_Stub.getChildAt(Unknown
    t(Unknown Source)
    The remote tree node method getChildAt returns
    TreeNode because the class implements TreeNode:
    public class remoteTreeNode extends
    UnicastRemoteObject implements rdcaDataIface,
    Comparable, TreeNode {
    public TreeNode getChildAt(int idx) {
    System.out.println("DEBUG: class is
    lass is "+this.getClass()); // class is
    remoteTreeNode
    return (remoteTreeNode)children.get(idx);
    The remote interface is defined as:
    public interface rdcaDataIface extends java.rmi.Remote
    public TreeNode getChildAt(int idx) throws
    ows RemoteException;
    Any ideas why this does not work. Why can a remote
    object of type Object be returned just fine, but a
    TreeNode not be returned?
    Thank you for your help,
    Brent

  • Remote Object - not able to get the returned value from java method

         Hi ,
    I am developing one sample flex aplication that connects to the java code and displays the returned value from the
    java method in flex client. Here I am able to invoke the java method but not able to collect the returned value.
    lastResult is giving null .  I am able to see the sysout messages in server console.
    I am using flex 3.2 and blazeds server  and java 1.5
    Here is the code what I have written.
    <?xml version="1.0" encoding="utf-8"?><mx:WindowedApplication  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" initialize="initApp()">
     <mx:Script><![CDATA[
    import mx.controls.Alert; 
    import mx.binding.utils.ChangeWatcher; 
    import mx.rpc.events.ResultEvent; 
    import mx.messaging.*; 
    import mx.messaging.channels.* 
    public function initApp():void { 
         var cs:ChannelSet = new ChannelSet(); 
         var customChannel:Channel = new AMFChannel("my-amf", "http://localhost:8400/blazeds/messagebroker/amf");     cs.addChannel(customChannel);
         remoteObj.channelSet = cs;
    public function writeToConsole():void {      remoteObj.writeToConsole(
    "hello from Flash client");
          var returnedVal:String = remoteObj.setName().lastResult;     Alert.show(returnedVal);
    //[Bindable] 
    // private var returnedVal:String; 
    ]]>
    </mx:Script>
    <mx:RemoteObject id="remoteObj" destination="sro" /> 
    <mx:Form width="437" height="281">
     <mx:FormItem>  
    </mx:FormItem>  
    <mx:Button label="Write To Server Console" click="writeToConsole()"/>
     </mx:Form>
     </mx:WindowedApplication>
    Java code
    public  
         public SimpleRemoteObject(){  
              super();     }
      class SimpleRemoteObject { 
         public void writeToConsole(String msg) {          System.out.println("SimpleRemoteObject.write: " + msg);     }
         public String setName(){          System.
    out.println("Name changed in Java"); 
              return "Name changed in Java";
    And I have configured destination in  remote-config.xml
    <destination id="sro">
       <properties>    
        <source>SimpleRemoteObject</source>
        <scope>application</scope>
       </properties>
      </destination>
    Please help me .

    You are not able to get the returned value because if you see the Remote object help you will realise you have to use result="resultfn()" and fault = "faultfn()"
    In this you define what you wish to do.
    More importantly in the remote object you need to define which method you wish to call using the method class like this
    <mx:RemoteObject id="remoteObj" destination="sro" result="r1" fault="f1"  >
         <Method name="javaMethodName" result="r2" fault="f2"/>
    <mx:RemoteObject>
    r2 is the function where you get the result back from java and can use it to send the alert.

  • Flex/Air and Web Services/Remote Objects

    If I'm calling a web service operation, either through the
    mx:webservice or mx:remoteobject tags, do I need to configure my
    Flex or Air project (I'm using the latest Flex Builder IDE) with
    the "use remote object access service" when creating the project?
    When do I need to configure services-config.xml or
    remoting-config.xml?
    Can't I simply call a web service operation by specifying the
    endpoint (if using mx:remoteobject) or the wsdl location for the
    service and then invoking one of its methods? I'm having a very
    difficult time consuming a web service through either method (even
    on my own local ColdFusion 8 developer instance) and need some
    assistance. I've looked all over the internet for help, but, so
    far, without success.
    Thanks,
    -Jose

    You do not need to specify any server to use any of the RPC
    protocols.
    Have you looked at an example?
    You have not said what problems you are having.
    Be aware of crossdomain security issues.
    Tracy

  • $25 Reward - Calling a CFC via Remote Object or Web Service without making the result public

    I am just getting into Flex 2, so please forgive me for my
    newbe vocab.
    Here is how my applications have worked in the past, i.e.
    ColdFusion:
    <cfscript>
    //Create an instance of component
    order = CreateObject( 'component', 'PEK.Catalog.Order' );
    //Call methd
    theOrder = order.getOrder(1234);
    </cfscript>
    Display the order via HTML and CFML.
    getOrder() returns a query and 1234 is a sample orderID. The
    most important part of the solution I am looking for is that the it
    must not expose my getOrder() as a public web service. I am able to
    run the application with WS by making the mothod URL visible and
    remote, but this is no way near the security I would like to have.
    Here is my folder structure where components folder has been maped
    to CF.
    Application
    |__extentions
    | ... |__components
    | ... ... |__PEK
    |__wwwroot
    I guest there should be a way to call CFC with the thing
    remote object that I have no idea how to set up. So please what
    would be a solution to my security issues.
    Thank you in advance!

    Click
    Here for Link to Article
    I guess this article answers part of the question. It is very
    important to note that if the CFC is sitting on the same server as
    the CFC the component methods could be public and not remote, thus
    making it alot more secure.

  • Can we cache the remote object?

    hi,
    can we cache the remote object?
    is this right way of doing?
    please suggest me
    regards
    crr

    Yes, caching EJBHome, EJBObject, and Remote business references is fine. They can also
    be portably stored in an HttpSession. However, when caching in the web tier you must still
    be careful to prevent concurrent access to the same stateful session bean. The fact that
    remote references to stateful session beans can be cached does not guarantee they can
    be accessed by more than one client at a time.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Can't kill remote objects!

    OK, from what i've read and seen, there are 4 things that must happen in order to successfully release a server-side remote object and have it garbage-collected:
    1) The server must call unexportObject
    2) The client must release all references (stubs) to the remote object;
    3) The server must release all local references to the original object
    4) Wait for outstanding leases to expire
    My application is doing 1, 2 and 3 - but 4 never happens because for some unknown reason the client continues [unnecessarily] to renew the leases!!!!
    I'm convinced this Is a bug! I know for a fact that 1 is happening - the client's reference becomes invalid. I have confirmed 2 and 3 using a heap analysis tool.
    If i forcibly terminate the client, the leases DO eventually expire, but I need a slightly more elegant solution than this.
    What could possibly be causing the persistent renewal of leases on unused objects? What can I look for on the Client side [or Server side]?
    Perhaps it is possible to simulate a clean() call somehow, but most of the classes required to do so are not 'public'.
    Over time, this problem is causing memory issues and VERY poor performance. Help!!!

    Thanks, but these objects are not bound to the registry.
    However, that raises an excellent point. For anyone else watching this topic, step 1.5 would be to call Registry.unbind() if the object was previously boud using bind() or rebind(). Otherwise, the RMI runtime would be holding on to a strong reference to the instance.

  • I can't use remote object in Flex to save an image to the server.

    I have a situation where I can't use remote object in Flex to save an image to the server.
    Could someone help me with an alterntaive?
    private function doSave():void {
                    var bd:BitmapData = new BitmapData(canvas.width,canvas.height);
                    var pe:PNGEncoder = new PNGEncoder;
                    bd.draw(canvas);
                    var ba:ByteArray = pe.encode(bd);
                    myService.doUpload(ba,sIP);
        <cffunction name="doUpload" displayname="Save Signature" hint="Saves a PNG Signature" access="remote" output="false" returntype="any">
            <cfargument name="sigbytes" required="true" type="binary">
            <cfargument name="ip_suffix" required="true" type="string">
            <cfset myUUID =  RandomString('ABCDEFGHIJKLMNOPQRSTUVWXYZ',15)>
            <cfset name = expandPath("converted_pngs/signature_#arguments.ip_suffix#_#myUUID#.png")>
            <cffile action="write" file="#name#" output="#arguments.sigbytes#" />
        <cfset SigFileName = "#arguments.ip_suffix#_#myUUID#">
            <cfreturn SigFileName />
        </cffunction>

    Try assigning binary arg to <cfimage/> then save.

  • Can I cache the Remote object

    I am using Stateless session bean. Can I cache the reference of the remote objects to this bean ?
    I read that some containers support the fearture of pre creating the EJB objects in the pool , during startup
    using some custom configuration ( like connection pool ). How is this performed ?`

    I am using Stateless session bean. Can I cache the
    reference of the remote objects to this bean ?No, but you can cache the HomeHandle of the Home interface references - that saves you the overhead of JNDI lookups, which are far more "expensive" time-wise than calling the create method to get the Remote implemenation.
    I read that some containers support the fearture of
    pre creating the EJB objects in the pool , during
    startup using some custom configuration ( like connection pool
    ). How is this performed ?Ask your vendor - it's vendor-specific.

  • Can't update remote object (RMI)

    I have made a class "A" that implements a remote interface "RI". I then rebind it to the rmiregistry:
    RI bob = new A();
    Naming.rebind("bob",bob);Class A has a few methods that I call that changes som private fields.
    After some time I start another class B that makes a look up:
    RI found  = (RI)Naming.lookup("//localhost/bob");But the private fields have not been changed in this looked up object.
    Is it necessary to call rebind each time I make a change to a remote object??

    If you'd stick to the same thread instead of starting a new one all over the place you'd find that I've already answered this question three days ago: http://forum.java.sun.com/thread.jspa?threadID=770735&messageID=4393030#4393030
    Can you stick to that thread please.

  • Can't load all properties of a remote object

    Hi,
    I have a java class called
    Employe which has a field of type
    Group(an java class)
    when i get the Employe Object in flex using remote Object and
    try to access Group's properties like
    employe.goup.name, i get:
    "Error #1009: Cannot access a property or method of a null
    object reference".
    Can some one please help me! Thank you.

    Please check your Node Object, I mean all Objects that you are going to save is serialized or not.

  • Can i remotely erase my iphone after the service is suspended from the wireless provider?

    Can I remotely erase my iphone via icloud after the wireless service is suspended?

    As AppleClubSuport states, it needs a data connection to the internet.  If your wireless service is suspended, it will have to be connected to wifi for the remote wipe command to be executed.

Maybe you are looking for