Remote Exception
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Remote Exception

  1. #1
    Join Date
    May 2000
    Posts
    116

    Remote Exception

    Hi
    In the case of EJB , where should the remote exceptions be thorwn. Is it ok for the remote exception to be thrown in Home , Remote and EJB ?

  2. #2
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104
    What kind of bean are you creating? For session beans (processes, not data persistence):

    Home
    - A utility interface for creating (or finding) implemented-beans. The naming standard for the home interface is "<BEAN_NAME>Home"
    The spec mandates that the create() [and create(String name) in the case of stateful session beans] must throw a RemoteException:

    Code:
    //MyBeanHome.java
    import java.rmi.*;
    import javax.ejb.*;
    
    public interface MyBeanHome extends EJBHome  {
      public MyBean create() throws RemoteException, CreateException;
      public MyBean create(String name) throws RemoteException, CreateException;
    }
    (The code in blue is only present in stateful session beans)

    _____________
    Remote
    -A general interface that defines the methods your bean actually will have. If you were writing a CreditCardVerifier bean, then here within, you may have a "VerifyDetails(String cc_number)" method.
    The naming standard for the remote interface is "<BEAN_NAME>"
    All methods in the Remote interface must also throw remote exception:
    Code:
    //MyBean.java
    import java.rmi.*;
    import javax.ejb.*;
    
    public interface MyBean extends EJBObject {
      public String getMyMethod() throws RemoteException;
      public void setMyMethod(String myParameter) throws RemoteException;
    }

    _____________
    Implementation
    -Here is here you actually write code for the methods. The naming standard for the implementation class is "<BEAN_NAME>EJB".
    Note that methods here do not throw the RemoteException, because the Home and Remote "interfaces" are not interfaces in the java sense; they do not mandate what the method signatures here must look like. The EJB container will generate extra classes to make everything work:

    Code:
    import java.rmi.*;
    import javax.ejb.*;
    
    public class MyBeanEJB implements SessionBean  {
      private String myString;
      private SessionContext context;
    
      public MyBeanEJB() {}
    
      public void setSessionContext(SessionContext c)  {
        context = c;
      }
    
      public void ejbCreate() throws CreateException  {
        myString = "Hello World"
      }
      public void ejbCreate(String name) throws CreateException  {
        myString = name
      }
    
      public void ejbActivate() {}
      public void ejbPassivate() {}
      public void ejbRemove() {}
    
      public String getMyMethod()  {
        return myString;
      }
    
      public void setMyMethod(String myParameter)  {
          myString = myParameter;
      }
    }
    Everything in blue, above, is my implementation of the business logic. THe black is the general skeleton of an implementation bean. Note that even though my methods were defined as throwing remote exception in the remote interface, and the home interface mandated that thre create() methods also throw remoteexceptions, the implementation of them do not throw remoteexceptions, and the create() methods only throw CreateExceptions.
    It is this way because, as note, the EJB container uses the home/remote to generate extra classes, that need to use RemoteException, but your implementation does not use RemoteException as it never sees the finer points of the RMI that makes it work..
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  3. #3
    Join Date
    May 2000
    Posts
    116
    Thanks a lot cjard
    .That was a very useful explanation. Is the naming standard defined by java ?

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center