Obtain remote interface using PortableRemoteObject

Hello,
I have sample code from "Applying Enterprinse JavaBeans" book.
Plan plan = (Plan)PortableRemoteObject.narrow(
it.next(), Plan.class);
... plan.getPlanInfo() ...
here:
Plan is a remote interface of the entity bean (e.g.. MyPlanBean).
getPlanInfo() is one of the business methods in Plan.
In this case, the remote interface is obtained by using PortableRemoteObject.narrow(...). could anyone explane the creation using the concept of life cycle of an entity bean instance? That means if any ejbCreate() methods or any callback methods are involved in the creation or not?
Thanks.

I am not sure if you are doing the right thing.
The home interface represents the life-cycle methods of the component (create, destroy, find) while the remote interface represents the business method of the bean.
Clients use the bean's home interface to obtain references to the bean's remote interface. Following is the life-cycle of
entity bean creation:
1. Client invokes create() on home object
2. Home object allocates a bean from the free pool
3. Home object passes on the create args to the ejbCreate(..)
in the bean
4. the bean inserts a row into the database table
5. the bean returns the primary key of the row to the home object
6. The container creates an EJB object for the bean and populates
it with the primary key
7. The home object calls the ejbPostCreate() on the bean
8. The home object returns the remote reference to the EJB
object back to the client
9. Client now makes business calls to the bean instance.
No bean instance is associated with the EJB object
10. EJB object communicates to the container that a bean
instance is needed
11. The container allocates a bean instance from the pool
and associates it with the EJB object (ejbActivate() is called)
12. home object invokes the ejbLoad method on the bean to
tell it to load itself(BMP) or to tell it that it has just been
loaded (CMP)
13. the bean uses the primary key stored in the EJB object to load the approp row's data from the database
14. EJB object dispatches the client's business method call to the
bean
Hope this helps.
Regards,
Sun-DTS

Similar Messages

  • Creating Remote Interface using workshop

    I created a session EJB using weblogic workshop 8.1 sp3. It autogenerated the remote interface that extends EJBObject, and is uneditable. I want my remote interface to extend com.bea.p13n.property.EntityPropertyManager. How can I create my own remote interface while creating a session bean using workshop? Appreciate your help.

    Hi,
    I am in the same boat. Did you find any solution to it?.
    Thank You.

  • Reflection of remote interface

    Hi. was wondering if you could use reflection to ennumerate the remote interface used by a java RMI server. I dont have anything specific in mind just a point at some documentation about this kind of reflection would be cool.......or any obsticles that would prevent me from doing so.
    Thanks!

    why do we have remote/home interface.What for? You'd just restrict the use of inheritance, without providing any additional implementation details or better design "semantics".

  • Remote Interface

    Hey. I was wondering if there was a way to enumerate the remote interface used by an RMI server if you do not have the RMI Client. Ive been looking at reflection but from what ive seen it assumes you know what type of object you will be dealing with.

    You can use reflection on the server or the stub to enumerate the interfaces it implements. You have to filter them so you only look at interfaces which extend java.rmi.Remote.

  • Remote Interface problem using Sun ONE App & web server

    HI,
    1) I am using an S'less SB. I have local & remote interfaces. I am using the sun one appserver7 & the sun ones's htttp server. By default it doesnt pick up the remote interfaces is it ? How do i make my remote interfaces work ? what are the changes required in config/xml ?
    2) However i changed my client code (i.e my action class which is called by the struts action servlet ) to access the localhome rather than the remote home, but then i get java.lang.classcastexception.
    pls help !
    sanjay

    Hi parsuram,
    Thanks for the tip. After looking at the sample source code, I did finally figure out the solution - so I'll post it in case anyone else happens to be working with websphere studio has the same issue deploying on sun one.
    To access local interface ejb, you must have the following
    1. ejb-local-ref tag in the ejb-jar.xml like so underneath the <session> or <entity> tag of the bean which you plan to access the local ejb with.
    <ejb-local-ref>
    <ejb-ref-name>TestL</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local-home>memory.simple.TestLLocalHome</local-home>
    <local>memory.tool.simple.TestLLocal</local>
    <ejb-link>TestL</ejb-link>
    </ejb-local-ref>
    2. similar ejb-ref tag in sun-ejb-jar.xml
    <ejb-ref>
    <ejb-ref-name>TestL</ejb-ref-name>
    <jndi-name>localejbs/module_memory.betaEJB/TestL68640023372300293</jndi-name>
    </ejb-ref>
    note: sun generates the <jndi-name> and overwrites whatever you put in that tag no matter what you put in there.
    3. here is the code to access
    Context initial = new InitialContext();
    TestLLocalHome tlHome=(TestLLocalHome) Initial.lookup
    ("TestL");
    //the string must match <ejb-ref-name> underneath <ejb-local-ref>
    4. note that the jndi name for the local interface bean becomes irrelevant. only the <ejb-ref-name> in the ejb-jar and sun-ejb-jar matter. furthermore, both <ejb-ref-name> must be the same or you won't be able to deploy.
    5. This is completely my fault for not checking the "proper" way to access local interfaces. in websphere, they let you get away without the ejb-ref tags and just use the string "local:/TestL"!
    -matt

  • Configure webapp to use local or remote interface based on environment

    Hi,
    I have the following problem I am trying to solve (app server is Weblogic 10g by the way).
    I have a webapp (war-project) and an ear project containing stateless session beans.
    In our development environment I would like to deploy the war and ear separately, because that is easier for development (war-project can then be deployed as a directory, so changes to jsp's and such have immediate effect).
    Deploying the war and ear separately means that the war-project can only call the session beans through their remote interfaces. For development this is not a problem.
    In a production environment however we would like to package the war INSIDE the ear, so that the webapp can use the local interfaces to call the session beans, as this will improve performance.
    So I am looking for a solution where I can configure the way beans are called. Local if the war is inside the ear, remote if the war is separate from the ear. I was thinking along the lines of packaging a properties file with the war that determines the mode (local or remote). Or maybe packaging a different deployment descriptor, if that is a possibility.
    This is what I have so far:
    Business Interface_
    package be.cegeka.test.ejb3.service;
    public interface TestService {
         public void doSomething();
    Remote Interface_
    package be.cegeka.test.ejb3.service;
    public interface TestServiceRemote extends TestService {
    Local Interface_
    package be.cegeka.test.ejb3.service;
    public interface TestServiceLocal extends TestService {
    Bean implementation_
    package be.cegeka.test.ejb3.service;
    import javax.ejb.Local;
    import javax.ejb.Remote;
    import javax.ejb.Stateless;
    @Stateless(mappedName="ejb/TestService")
    @Local(TestServiceLocal.class)
    @Remote(TestServiceRemote.class)
    public class TestServiceBean implements TestService {
         @Override
         public void doSomething() {
              System.out.println("I'm doing something");
         @Override
         public void doSomethingLocal() {
              System.out.println("I'm doing something local");
    JSF backing bean_
    package be.cegeka.test.ui;
    public class MyWebAppBackingBean {
         @EJB(mappedName="ejb/TestService", beanInterface=TestServiceRemote.class)
         private TestService testService;
         public String doSmth() {
              testService.doSomething();
              return "success";
    }The part that I would like to be configurable is the "+beanInterface=TestServiceRemote.class+" part in the JSF backing bean. Depending on the environment (development vs. production), this should be "+beanInterface=TestServiceRemote.class+" for development and "+beanInterface=TestServiceLocal.class+" for production.
    Is something like this possible?
    I would like to avoid having to fill my web.xml with ejb-refs and having to do the JNDI-lookups myself if at all possible, to keep things as easy and clean as possible.
    Any ideas are welcome!
    Steven

    Hey Manish,
    comments inline.
    "manish kumar" <[email protected]> wrote in message
    news:1794338.1102557677925.JavaMail.root@jserv5...
    So If they are supposed to be in the same JVM -
    then
    1. the cluster of 3 weblogic servers are three JVMs. So does that meanLOCAL INTERFACES CAN'T BE USED IN CLUSTERED ENVIORONMENT ?
    Sure they can, but the calling component in an enterprise app will not call
    an intance of the local bean on another node in the cluster. It will make a
    by-reference call to the local component in the same EAR. Local interfaces
    are not Remote, so they cannot be used with by-value RMI semantics.
    >
    2. ARE YOU SURE ABOUT THIS FACT THAT THAT LOCAL INTERFACES CAN BE USEDONLY INSIDE THE SAME APPLICATION, I THOUGHT IT CAN BE USED AS LONG AS CLINET
    IS IN THE SAME JVM?
    PLEASE CONFIRM.........!!!!!!!!!!!!!Dead sure:
    http://e-docs.bea.com/wls/docs81/programming/classloading.html#1073506
    http://e-docs.bea.com/wls/docs81/ejb/understanding.html#1126831
    http://e-docs.bea.com/wls/docs61/ejb/cmp.html#1085452
    http://www.theserverside.com/discussions/thread.tss?thread_id=14628
    Also, search the ejb newsgroups. I know Rob Woollen has addressed this in
    here somewhere. And, if Rob says it's so, trust me, it's so.
    Bill

  • Calling Remote interface from client

    Hi there!
    I am working on a BMP (using weblogic 6.1)
    My problem is - How do I contact remote interface from client. In my jndi tree I have mentioned only Home interface. Right now I am calling my remote interface like this:
    //contact home interface
    Object obj = ctx.lookup("APIHome");
    APIHome home = (APIHome) javax.rmi.PortableRemoteObject.narrow(obj, APIHome.class);
    //creating remote somehow - I got this clue from a website
    rem = home.findByPrimaryKey(new EntityPK("test1","test2"));
    //calling getter & setter methods
    rem.setWidth()
    rem.getId();
    This works...but doesn't make any sense to me. Why should we initialize remote interface as above. Or is there any other option. Can somebody please explain me more clearly about this concept.
    Thanks very much
    regards
    -Manasvi

    The HomeInterface contains two types of methods - create and find. The create methods create an instance of the entity bean(i.e., a record in the database) and the finder methods finds an existing record in the database, constructs an entity bean representing this row and returns the remote interface of this bean to the client for further manipulations.

  • Get a remote interface from a local instance

    hi,
    I want to construct a bean locally on a server and then I want to pass the remote interface for that constructed bean back to a client. Is this possible?
    Thanks

    Yes. Take a look at SessionContext class. You can't construct a bean yourself, as its life is managed by container.
         * Obtain an object that can be used to invoke the current bean through
         * the given business interface.
         * @param businessInterface One of the local business interfaces
         *        or remote business interfaces for this session bean.
         * @return The business object corresponding to the given business
         *         interface.
         * @exception IllegalStateException Thrown if this method is invoked
         *         with an invalid business interface for the current bean.
        <T> T getBusinessObject(Class<T> businessInterface) throws IllegalStateException;

  • When do remote interface get invaliated? Can I cache them?

    Hello,
    I am designing an application, and considering using the "Service Locator" pattern, acting as a singleton that will cache jndi context, and bean home and remote interfaces. However I am unsure whether caching of remote interface is a problem or not:
    1) Under what circumstances will the cached remote interface for a stateless session bean be invalidated?
    2) Under what circumstances will the cached remote interface for an Entity Bean be invalidated?
    3) Assuming that I cache Stateful session bean remote interfaces in a Servlet HTTPSESSION, under what circumstances will the cached remote interface for Stateful session bean be invalidated?
    4) Finally, do I have to utilise home handles instead of remote interfaces for any of these situations? If so, why?
    Thanks

    I understand that caching the Home Interface or HomeHandle of this, is the solution for
    reconnection to EJB's problems.
    But I do not succeed in getting a working solution for handling the reconnection
    to a restarted EJB server after some downtime.
    First the HomeHandle of the Home Interface is successfully saved with:
    "myHomeHandle = myHome.getHomeHandle();"
    Later the HomeHandle is used to restore the Home Interface with:
    "MyHome myHome = (MyHome) myHomeHandle.getEJBHome();"
    But this gives an Exception like
    Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property,
    or as an applet parameter, or in an application resource file: java.naming.factory.initial
    I have followed the recommandations in this postings, but in some way I lack a bit information.
    Has somebody a code example in Java of how to do this?
    Here is my code which throws the exception
    InitialContext context = new InitialContext( properties );
    Object obj = context.Lookup( "My" );
    MyHome myHome = (MyHome) PortableRemoteObject.narrow( obj, MyHome.class );
    myBean = myHome.create();
    myHomeHandle = myHome.getHomeHandle();
    // At this point everything fine, and a myBean is created.
    // Now I try to recreate the myHome Interface
    MyHome myHome = (MyHome) myHomeHandle.getEJBHome();
    // In order to (re)create the myBean EJB.
    myBean = myHome.create();
    // But the second create is never executed, as the method call "...myHomeHandle.getEJBHome();"
    throws the above Exception.
    So, any help I will Appreciate.

  • Slowness in Retrieval of Remote Interface

    We are running Weblogic 6.1 with service pack 2. Recently we saw that it was taking
    from 1 to 2 minutes to get a remote interface to a session bean. Normally this
    takes less than a second. My question is, what "gotchas" are out there when it
    comes to the timeliness of accessing a session bean?

    The two lines of code causing the delay are:
    home = (TRSSessionHome)javax.rmi.PortableRemoteObject.narrow(contextForBean.lookup(TRSSessionHome.beanHomeName),TRSSessionHome.class);
    remote = home.create();
    What makes you think it is DNS? We are thinking that we are blocking on a thread
    somewhere? But this still doesn't account for the 2 minute delay. We saw no errors
    in our logs either. Any help is greatly appreciated because we haven't gotten a
    solution and the tech support guy is out of ideas until the problem happens again
    and I get him a thread dump.
    thanks,
    lisa
    Rob Woollen <[email protected]> wrote:
    Are you talking about the JNDI look-up, or the call to home.create. Is
    this a
    stateless session bean or a stateful session bean? Is the caller within
    the WebLogic
    Server or in an outside process/machine?
    My first guess is that you're having problems with your DNS. Try using
    the IP address
    instead.
    -- Rob
    Michael Dunnigan wrote:
    We are running Weblogic 6.1 with service pack 2. Recently we saw thatit was taking
    from 1 to 2 minutes to get a remote interface to a session bean. Normallythis
    takes less than a second. My question is, what "gotchas" are out therewhen it
    comes to the timeliness of accessing a session bean?

  • How can I access a database remote without using dblink, synonyms,aliases?

    My store procedure access a remote tables using dblink, synonyms, alias, but by business company requirenments I nedd to use another data base access method. My PL/SQL statement looks like
    select c.cus_id, c.cus_name, p.bankaccno
    into v_cus_id, v_cus_name, v_bankaccno
    from customer c, payment@finantial p
    where c.cus_id = p.cus_id
    Are any method else to connect to several remote databases concurrently?
    If Yes, plase say me how is it, or tell me where do I obtain some examples, or any documentation.
    Edited by: user518321 on Apr 21, 2009 1:58 PM
    Ok, But I must not use any of these data base access method, metioned: dbliks, aliases, synonyms.
    Edited by: user518321 on Apr 21, 2009 2:05 PM
    Ok, It is enough for now, I am surprised for the response time and for their arguments, thanks a lot.
    Edited by: user518321 on Apr 21, 2009 2:50 PM

    If you want to access a table in a remote database using SQL, you will need a database link. It would be exceptionally odd for the business to require that you access a remote database and to prohibit the use of database links. What is the business reason for that combination?
    If you want to look into rather more esoteric solutions, you could load a JDBC driver for the remote database, write a Java stored procedure that queries the remote table using that JDBC driver, and then cobble together some PL/SQL that joins the two result sets. You won't be able to reference the remote table in SQL and the solution won't scale well as data volumes increase and you'll be writing a whole lot of code to manually join tables together, but it does avoid database links. Of course, whatever concerns lead to the ban on database links would probably apply to loading a JDBC driver into the database and writing Java stored procedures to access the remote database, but since you haven't explained the reasoning behind the restrictions, we're just guessing.
    Justin

  • How to specify a base class for Remote Interface in Workshop 9.2? -- URGENT

    Hi,
    I am trying to create a UUP EJB in WebLogic 9.2 workshop. I am using @FileGeneration to create my home & remote interfaces. And the generated remote interface is extending javax.ejb.EJBObject;I want my remote interface to extend com.bea.p13n.property.EntityPropertyManager which in turn implements javax.ejb.EJBObject. Can someone tell how i can do it in Workshop?.
    I came across Predefined Variable: remote.baseClass and as per docume
    ntation..."If specified, the value of this variable will be used as the base class for all generated remote classes. Where i should specify it?. @FileGeneration does nt have any option for it. Any help is grtly appreciated.
    Following are my code snippets:
    IMPL Class
    @FileGeneration(remoteClass = Constants.Bool.TRUE,remoteHome = Constants.Bool.TRUE, localClass = Constants.Bool.FALSE, localHome = Constants.Bool.FALSE,remoteClassName = "MyEntityPropertyManager",remoteHomeName = "MyEntityPropertyManagerHome")
    public class MyEntityPropertyManagerImpl extends GenericSessionBean implements
              SessionBean {
    //code
    }

    This question was posted to both the bea.workshop.developer.general and weblogic.developer.interest.workshop (I had replied to the later on 10/19); after seeing an identical question today on this list want to include a reference to that reply here:
    http://forums.bea.com/bea/message.jspa?messageID=600044925&tstart=0
    -Rob

  • EJB3 - More than one remote interface for Session Bean?

    Hi,
    Is it possible in EJB3 to have more than one remote interface for a SessionBean?
    I have seen it posetd on here that it is possible but never been able to find any other information.
    Using JBoss as my App Server, I have deployed an App, where a SessionBean is defined as implementing 2 interfaces, both of which are annotated using @remote.
    However when I examine the JBoss JMX Console, Global JNDI Namespace only one remote interface is listed, and indeed it is the first one defined in the SessionBean.
    Considering I use a String similar to (MyApp/MyBean/remote) to do the JNDI lookup, this would indicate that it is not possible to have more than one remote interface.
    1. Is this a JBoss specific limitation?
    2. Is there another way of performing the JNDI lookup?
    Thanks,
    Alan.

    Hi,
    Thanks for prompt response! I tried the suggestion in my application, and the output from JBoss JMX Console was
    +- XXXBean (class: org.jnp.interfaces.NamingContext)
      |   |   +- remote (proxy: $Proxy291 implements No ClassLoaders found for: xxx.xxx.xxx.xxx.xxx.Remote1 (no security manager: RMI class loader disabled))Again only displaying the remote interface that is first in the @remote ({ Remote1.class , Remote2.class}) list. This would lead me to believe that JBoss does not support this.
    Can anyone confirm this?
    Alan.

  • SJSAS 9.1 does not expose EJB 3.0 remote Interface via JNDI

    I have successfully deployed a simple Stateful EJB 3.0 bean (CartBean, like the one in the Java EE 5 tutorial remote interface Cart) on SJSAS 9.1, located on machine host1.
    After I deployed the CartBean, I browsed the SJSAS and noticed the existence of the following JNDI entries:
    ejb/Cart
    ejb/Cart__3_x_Internal_RemoteBusinessHome__
    ejb/Cart#main.Cart
    ejb/mgmt
    ejb/myOtherEJB_2_x_bean ( +myOtherEJB_2_x_bean+ is a different 2.x bean that I have deployed as well)So, I am trying to access the remote interface of the CartBean from a remote machine, host2. The client application is a Java-standalone client.
    I am using the Interoperable Naming Service syntax: corbaname:iiop:host1:3700#<JNDI name>
    The problem is that the remote interface of the bean does NOT seem to be available via JNDI. I get the javax.naming.NameNotFoundException when I try to do a lookup like:
    corbaname:iiop:host1:3700#ejb/Cart
    On the other hand, the following lookups succeed:
    corbaname:iiop:host1:3700#ejb/mgmt
    corbaname:iiop:host1:3700#myOtherEJB_2_x_bean
    and also the following succeeds:
    corbaname:iiop:host1:3700#ejb/Cart__3_x_Internal_RemoteBusinessHome__So it seems like the Remote interface is not available via JNDI, rather only some internal SJSAS implementation (the object returned from the ejb/Cart__3_x_Internal_RemoteBusinessHome__ lookup is of type: com.sun.corba.se.impl.corba.CORBAObjectImpl
    Why is this happening? I know there used to be a bug in Glassfish, but I thought it had been fixed since 2006.
    Many thanks in advance, any help would be greatly appreciated.

    The EJB 3.0 Remote Business references are not directly stored in CosNaming. EJB 3.0 Remote references do not have the cross-vendor interoperability requirements that the EJB 2.x Remote view had.
    You can still access Remote EJB references from a different JVM as long as the client has access to SJSAS naming provider. Please see our EJB FAQ for more details :
    https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html

  • Enhancement request: Remote interface java file generation

    Problem:
    In release 9.0.3, If you want to write a method that is suppossed to be exposed in the remote interface, you have to first right click on the ejb-jar.xml's appropriate EJB name node and then add the method, specify the argument types (say about 25 in number in a small width textbox), return type, etc and check the check box 'Expose in remote interface'. Then only remote interface's java source gets updated and only after doing all this can you actually sit down to write the business logic in that method. If you first code the method and then try to add the same, it gives an error saying "duplicate method exists"
    Suggestion:
    The similiar feature in release 9.0.2 was much better and flexible as it allowed the generation of remote interface source after coding the actual method in the EJB source. You can first write the method and then expose it in the interface by just choosing it from a method browser and opting for exposing it in the remote interface. You donot have to write the name and number of arguments like we have to currently do in the 9.0.3 release.
    (1) Actually, all public methods in the EJB source should by default be exposed in the remote interface because EJB are supposed to be used by other EJBs and JSPs only and all methods that are public but not exposed in the remote interface should actually be private or protected.
    (2) Leave it up to the developer to edit the remote interface
    (3) When the EJB source file is changed (public methods changed) compiled the remote interface should also be updated automatically. Why? already you have provision to change the remote interface source, so just dump all the public methods in the remote interface source when the EJB source is compiled.
    (4) Ditto for EJB Homes
    (5) Actually whenever the developer changes and compiles the EJB source, the remote and home source should automatically be updated AND COMPILED. (Refer: Pramati Studio 3.0 SP3 :- URL: www.pramati.com )
    I was very happy with the earlier option. If anybody other then the JDeveloper Team finds this interesting, please respond. A suite like developer should be more User-friendly.
    And yes expect more like this from me in the future

    Hi Raghu,
    Thanks for the quick response. This flexiblity in Remote interface generation and choice of methods in it at any given point in the development cycle is very much desired feature.
    The other thing I would like to suggest is you look at another enhancement request in my name regarding batch updates of the "web.xml" file. You will find the thread updated today i.e. on 15th September with a reply
    I will shortly post one more for lack of modularity in EJB components descriptors.
    My Company Four Soft Pvt. Ltd. (www.four-soft.com) is Oracle's development partner and we use and support Oracle products. They are good but naturally we would like them to be better and more User-friendly.
    Thanks once again.
    Amit

Maybe you are looking for

  • Connecting together a Siemens router/modem and linksys E2500

    Hi: Unfortunately, I'm not good with this stuff but I think I can learn ... I have a Siemens Gigaset SE567, which was set-up by my IP. I'm using its Modem via the #1 Ethernet port to my desktop. It broadcasts wifi but I got tired of paying $10 p/m fo

  • In-app purchase will not download on my iPad air.

    Received an iPad Air and went to buy an in-app purchase I had on an older iPad. Recieve You've already purchased this but it hasn't been downloaded. Ok. I press okay and nothing happens.

  • IOS 7, iPad 4: keyboard problems with Shift key

    Since I have upgraded my iPad 4 to iOS 7 a few days ago the keyboard drives me mad: I did not experience the overall slowness of the keyboard as reported by so many others. Anyway, I reset my settings just to be safe. But the reset had absolutely no

  • Removing residue from iMac

    Can anyone advise me on how to remove the sticky glue left over from my iMac packaging. The plastic sheaf that covers the iMac when it first arrives has a sticky label that, in my case, had also been stuck to part of the back of the computer. It's le

  • No display port adapters??

    Just got my new Macbook and the Chicago store doesn't have the displayport to vga or dvi adapters yet... any other options out there? Are they in other stores?