User: reverbel
  Date: 02/02/15 13:42:35

  Modified:    iiop/src/main/org/jboss/ejb/plugins/iiop/server
                        IIOPContainerInvoker.java
  Log:
    - Changes to make it compile and run with the RH codebase:
        * Pre-RH invocation class org.jboss.ejb.MethodInvocation replaced
          by org.jboss.invocation.Invocation.
        * ContainerInvoker methods do not throw RemoteException anymore.
    - System.err.println calls replaced by logger calls.
    - Exception handling cleanup (ServerExceptions replaced by
      RuntimeExceptions).
    - Added instanceof check to get around the fact that the container
      parent classloader is not a WebClassLoader anymore. (This is an awful
      hack that will go away soon.)
  
  Revision  Changes    Path
  1.12      +139 -116  
contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/IIOPContainerInvoker.java
  
  Index: IIOPContainerInvoker.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/iiop/src/main/org/jboss/ejb/plugins/iiop/server/IIOPContainerInvoker.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- IIOPContainerInvoker.java 13 Feb 2002 20:45:34 -0000      1.11
  +++ IIOPContainerInvoker.java 15 Feb 2002 21:42:34 -0000      1.12
  @@ -11,11 +11,8 @@
   import java.io.ObjectInputStream;
   import java.io.ObjectOutputStream;
   import java.io.IOException;
  -import java.lang.reflect.Method;
   import java.net.URL;
   import java.rmi.Remote;
  -import java.rmi.RemoteException;
  -import java.rmi.ServerException;
   import java.security.Principal;
   import java.util.ArrayList;
   import java.util.Collection;
  @@ -49,7 +46,7 @@
   import org.omg.CORBA.portable.UnknownException;
   import org.omg.CORBA.SetOverrideType;
   import org.omg.PortableServer.Current;
  -import org.omg.PortableServer.CurrentHelper; // not available in jdk1.4
  +import org.omg.PortableServer.CurrentHelper;
   import org.omg.PortableServer.POA;
   import org.omg.PortableServer.POAManager;
   import org.omg.PortableServer.POAPackage.WrongPolicy;
  @@ -71,7 +68,7 @@
   import org.jboss.ejb.Container;
   import org.jboss.ejb.ContainerInvokerContainer;
   import org.jboss.ejb.ContainerInvoker;
  -import org.jboss.ejb.MethodInvocation;
  +import org.jboss.invocation.Invocation;
   import org.jboss.ejb.plugins.iiop.client.StubStrategy;
   import org.jboss.ejb.plugins.iiop.EJBMetaDataImpl;
   import org.jboss.ejb.plugins.iiop.HandleImpl;
  @@ -83,6 +80,7 @@
   import org.jboss.iiop.rmi.AttributeAnalysis;
   import org.jboss.iiop.rmi.OperationAnalysis;
   import org.jboss.iiop.rmi.InterfaceAnalysis;
  +import org.jboss.logging.Logger;
   import org.jboss.metadata.EntityMetaData;
   import org.jboss.metadata.MetaData;
   import org.jboss.metadata.SessionMetaData;
  @@ -118,7 +116,7 @@
    * CORBA reference for the corresponding <code>EJBObject</code>.
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Francisco Reverbel</a>
  - * @version $Revision: 1.11 $
  + * @version $Revision: 1.12 $
    */
   public class IIOPContainerInvoker
         extends Servant
  @@ -128,6 +126,8 @@
      // Constants  --------------------------------------------------------------
   
      private static final byte[] nullId = createNullId();
  +   private static final Logger staticLogger = Logger.getLogger(
  +                                                   IIOPContainerInvoker.class);
   
      // Attributes -------------------------------------------------------------
   
  @@ -209,14 +209,25 @@
       */
      private InterfaceRepository iri;
   
  +   /**
  +    * This <code>IIOPContainerInvoker</code>'s logger. Initialized with a
  +    * per-class logger. Once the enterprise bean's JNDI name is known, the
  +    * per-class logger will be replaced by a per-instance logger whose name
  +    * includes the JNDI name.
  +    */ 
  +   private Logger logger = staticLogger;
  +
      // Implementation of the interface ContainerPlugin -------------------------
   
  -   public void setContainer(Container con) 
  +   public void setContainer(Container container) 
      {
  -      this.container = con;
  +      this.container = container;
  +      String loggerName = IIOPContainerInvoker.class.getName() + '.' 
  +                                + container.getBeanMetaData().getJndiName(); 
  +      logger = Logger.getLogger(loggerName);
      }
   
  -   public void init() throws Exception 
  +   public void create() throws Exception 
      {
         // Initialize orb, homePoa, and iri references
         try {
  @@ -245,7 +256,7 @@
         }
   
         // Create bean method mappings for container invoker
  -      System.err.println("Bean methods: ---------------------");
  +      logger.debug("Bean methods: ---------------------");
   
         //iri.mapClass(((ContainerInvokerContainer)container).getRemoteClass());
         //iri.finishBuild();
  @@ -259,14 +270,14 @@
         for (int i = 0; i < attrs.length; i++) {
            OperationAnalysis op = attrs[i].getAccessorAnalysis();
   
  -         System.err.println("    " + op.getJavaName());
  -         System.err.println("                " + op.getIDLName());
  +         logger.debug("    " + op.getJavaName()
  +                      + "\n                " + op.getIDLName());
            beanMethodInvokerMap.put(op.getIDLName(), 
                                     new SkeletonStrategy(op.getMethod()));
            op = attrs[i].getMutatorAnalysis();
            if (op != null) {
  -            System.err.println("    " + op.getJavaName());
  -            System.err.println("                " + op.getIDLName());
  +            logger.debug("    " + op.getJavaName()
  +                         + "\n                " + op.getIDLName());
               beanMethodInvokerMap.put(op.getIDLName(), 
                                        new SkeletonStrategy(op.getMethod()));
            }
  @@ -274,8 +285,8 @@
   
         OperationAnalysis[] ops = interfaceAnalysis.getOperations();
         for (int i = 0; i < ops.length; i++) {
  -         System.err.println("    " + ops[i].getJavaName());
  -         System.err.println("                " + ops[i].getIDLName());
  +         logger.debug("    " + ops[i].getJavaName()
  +                      + "\n                " + ops[i].getIDLName());
            beanMethodInvokerMap.put(ops[i].getIDLName(),
                                     new SkeletonStrategy(
                                           ops[i].getMethod()));
  @@ -285,7 +296,7 @@
         beanRepositoryIds = interfaceAnalysis.getAllTypeIds();
   
         // Create home method mappings for container invoker
  -      System.err.println("Home methods: ---------------------");
  +      logger.debug("Home methods: ---------------------");
   
         //iri.mapClass(((ContainerInvokerContainer)container).getHomeClass());
         //iri.finishBuild();
  @@ -299,14 +310,14 @@
         for (int i = 0; i < attrs.length; i++) {
            OperationAnalysis op = attrs[i].getAccessorAnalysis();
   
  -         System.err.println("    " + op.getJavaName());
  -         System.err.println("                " + op.getIDLName());
  +         logger.debug("    " + op.getJavaName()
  +                      + "\n                " + op.getIDLName());
            homeMethodInvokerMap.put(op.getIDLName(), 
                                     new SkeletonStrategy(op.getMethod()));
            op = attrs[i].getMutatorAnalysis();
            if (op != null) {
  -            System.err.println("    " + op.getJavaName());
  -            System.err.println("                " + op.getIDLName());
  +            logger.debug("    " + op.getJavaName()
  +                         + "\n                " + op.getIDLName());
               homeMethodInvokerMap.put(op.getIDLName(), 
                                        new SkeletonStrategy(op.getMethod()));
            }
  @@ -314,8 +325,8 @@
   
         ops = interfaceAnalysis.getOperations();
         for (int i = 0; i < ops.length; i++) {
  -         System.err.println("    " + ops[i].getJavaName());
  -         System.err.println("                " + ops[i].getIDLName());
  +         logger.debug("    " + ops[i].getJavaName()
  +                      + "\n                " + ops[i].getIDLName());
            homeMethodInvokerMap.put(ops[i].getIDLName(),
                                     new SkeletonStrategy(ops[i].getMethod()));
         }
  @@ -327,12 +338,13 @@
         jndiName = container.getBeanMetaData().getJndiName();
   
         // Create codebasePolicy containing the container's codebase string
  -      System.err.println("container classloader: "
  -                         + container.getClassLoader());
  -      System.err.println("container parent classloader: "
  -                         + container.getClassLoader().getParent());
  +      logger.debug("container classloader: " + container.getClassLoader()
  +                   + "\ncontainer parent classloader: "
  +                   + container.getClassLoader().getParent());
         URL[] codebaseURLs = // TODO: get rid of this ugly hack!!!
  -         ((WebClassLoader)container.getClassLoader().getParent()).getURLs();
  +         (container.getClassLoader().getParent() instanceof WebClassLoader)
  +           ? ((WebClassLoader)container.getClassLoader().getParent()).getURLs()
  +           : new URL[0];
         StringBuffer sb = new StringBuffer();
         for (int i = 0; i < codebaseURLs.length; i++) {
            sb.append(codebaseURLs[i].toString());
  @@ -343,7 +355,7 @@
         Any codebase = orb.create_any();
         codebase.insert_string(sb.toString());
         codebasePolicy = orb.create_policy(CodebasePolicy.TYPE, codebase);
  -      System.err.println("codebasePolicy: " + codebasePolicy);
  +      logger.debug("codebasePolicy: " + codebasePolicy);
   
         // Activate ejbHome and get a CORBA reference to it
         ejbHomeServant = new HomeServant();
  @@ -357,8 +369,8 @@
                     SetOverrideType.ADD_OVERRIDE);
   
         // Just for testing
  -      System.err.println("EJBHome reference for " + jndiName + ":");
  -      System.err.println(orb.object_to_string(corbaRef));
  +      logger.debug("EJBHome reference for " + jndiName + ":\n"
  +                  + orb.object_to_string(corbaRef));
   
         ejbHome = (EJBHome)PortableRemoteObject.narrow(corbaRef, EJBHome.class);
   
  @@ -405,15 +417,15 @@
                              metaData.getPrimKeyField()).getClass();
            } 
            catch (NoSuchFieldException e) {
  -            System.err.println("Unable to identify Bean's Primary Key class! "
  -                  + "Did you specify a primary key class and/or field? "
  -                  + "Does that field exist?");
  +            logger.error("Unable to identify Bean's Primary Key class! "
  +                         + "Did you specify a primary key class and/or field? "
  +                         + "Does that field exist?");
               throw new RuntimeException("Primary Key Problem");
            } 
            catch (NullPointerException e) {
  -            System.err.println("Unable to identify Bean's Primary Key class! " 
  -                  + "Did you specify a primary key class and/or field? "
  -                  + "Does that field exist?");
  +            logger.error("Unable to identify Bean's Primary Key class! " 
  +                         + "Did you specify a primary key class and/or field? "
  +                         + "Does that field exist?");
               throw new RuntimeException("Primary Key Problem");
            }
   
  @@ -470,8 +482,8 @@
         poa.the_POAManager().activate();
         
         // Just for testing
  -      System.err.println("EJBHome reference for " + jndiName + ":");
  -      System.err.println(orb.object_to_string((org.omg.CORBA.Object)ejbHome));
  +      logger.info("EJBHome reference for " + jndiName + ":\n"
  +                  + orb.object_to_string((org.omg.CORBA.Object)ejbHome));
   
         Context initialContext = null;
         try {
  @@ -484,11 +496,11 @@
                                                  (org.omg.CORBA.Object)ejbHome)),
                        HomeFactory.class.getName(),
                        null));
  -         System.err.println("Bound " + container.getBeanMetaData().getEjbName()
  -                            + " to " + jndiName);
  +         logger.info("Bound " + container.getBeanMetaData().getEjbName()
  +                     + " to " + jndiName);
         } 
         catch (NamingException e) {
  -         throw new ServerException("Could not bind EJBHome in JNDI", e);
  +         throw new RuntimeException("Could not bind EJBHome in JNDI:\n" + e);
         }
   
         NamingContextExt corbaContext = null;
  @@ -500,16 +512,16 @@
   
         } 
         catch (NamingException e) {
  -         throw new ServerException("Cannot lookup java:/"
  -                                   + CorbaORBService.NAMING_NAME + ": " + e);
  +         throw new RuntimeException("Cannot lookup java:/"
  +                                   + CorbaORBService.NAMING_NAME + ":\n" + e);
         }
         try {
            // Register bean home in local CORBA naming context
            rebind(corbaContext, jndiName, (org.omg.CORBA.Object)ejbHome);
         }
         catch (Exception e) {
  -         throw new ServerException(
  -               "Could not bind EJBHome in CORBA naming service", e);
  +         throw new RuntimeException(
  +               "Could not bind EJBHome in CORBA naming service:\n" + e);
         }
   
         // TODO: this should be after all beans were deployed
  @@ -548,7 +560,7 @@
                        false  /* wait_for_completion */ );
         }
         catch (Exception e) {
  -         e.printStackTrace(System.err);
  +         logger.warn(null, e);
         }
      }
   
  @@ -563,13 +575,12 @@
         return ejbMetaData;
      }
   
  -   public EJBHome getEJBHome() 
  +   public Object getEJBHome() 
      {
         return ejbHome;
      }
   
  -   public EJBObject getStatelessSessionEJBObject()
  -         throws RemoteException 
  +   public Object getStatelessSessionEJBObject()
      {
         try {
            return (EJBObject)PortableRemoteObject.narrow(
  @@ -577,13 +588,12 @@
                  EJBObject.class);
         }
         catch (WrongPolicy wrongPolicy) {
  -         throw new ServerException("Wrong POA policy in IIOPContainerInvoker", 
  -                                   wrongPolicy);
  +         throw new RuntimeException("Wrong POA policy in IIOPContainerInvoker:"
  +                                    + "\n" + wrongPolicy);
         }
      }
   
  -   public EJBObject getStatefulSessionEJBObject(Object id)
  -         throws RemoteException 
  +   public Object getStatefulSessionEJBObject(Object id)
      {
         try {
            return (EJBObject)PortableRemoteObject.narrow(
  @@ -592,19 +602,21 @@
                  EJBObject.class);
         }
         catch (WrongPolicy wrongPolicy) {
  -         throw new ServerException("Wrong POA policy in IIOPContainerInvoker", 
  -                                   wrongPolicy);
  +         throw new RuntimeException("Wrong POA policy in IIOPContainerInvoker" 
  +                                    + "\n" + wrongPolicy);
         }
      }
   
  -   public EJBObject getEntityEJBObject(Object id)
  -         throws RemoteException 
  +   public Object getEntityEJBObject(Object id)
      {
  -      //System.err.println(">>> getEntityEJBObject(), id class is " +
  -      //                   id.getClass().getName());
  -      //if (id instanceof CacheKey)
  -      //   System.err.println(">>>                       CacheKey contains a " 
  -      //                    + ((CacheKey)id).getId().getClass().getName());    
  +      if (logger.isTraceEnabled()) {
  +         logger.trace("getEntityEJBObject(), id class is "
  +                      + id.getClass().getName()
  +                      + ((id instanceof CacheKey) 
  +                            ? ("                      CacheKey contains a "
  +                                 + ((CacheKey)id).getId().getClass().getName())
  +                            : ""));
  +      }
         try {
            id = (id instanceof CacheKey) ? id : new CacheKey(id);
            return (EJBObject)PortableRemoteObject.narrow(
  @@ -613,21 +625,24 @@
                  EJBObject.class);
         }
         catch (WrongPolicy wrongPolicy) {
  -         throw new ServerException("Wrong POA policy in IIOPContainerInvoker",
  -                                   wrongPolicy);
  +         throw new RuntimeException("Wrong POA policy in IIOPContainerInvoker"
  +                                    + "\n" + wrongPolicy);
         }
      }
      
      public Collection getEntityCollection(Collection ids)
  -         throws RemoteException 
      {
  -      //System.err.println(">>> entering getEntityCollection()");
  +      if (logger.isTraceEnabled()) {
  +         logger.trace("entering getEntityCollection()");
  +      }
         ArrayList list = new ArrayList(ids.size());
         Iterator idEnum = ids.iterator();
         while(idEnum.hasNext()) {
            list.add(getEntityEJBObject(idEnum.next()));
         }
  -      //System.err.println(">>> leaving getEntityCollection()");
  +      if (logger.isTraceEnabled()) {
  +         logger.trace("leaving getEntityCollection()");
  +      }
         return list;
      }
   
  @@ -650,7 +665,10 @@
                                  InputStream in,
                                  ResponseHandler handler) 
      {
  -      //System.err.println("EJBObject invocation: " + opName);
  +
  +      if (logger.isTraceEnabled()) {
  +         logger.trace("EJBObject invocation: " + opName);
  +      }
   
         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(container.getClassLoader());
  @@ -665,11 +683,13 @@
            Object id;
            try {
               id = toObject(poaCurrent.get_object_id());
  -            //System.out.println("                      id class is " 
  -            //                   + id.getClass().getName());
  +            if (logger.isTraceEnabled()) {
  +               logger.trace("                      id class is " 
  +                            + id.getClass().getName());
  +            }
            }
            catch (Exception e) {
  -            e.printStackTrace(System.err);
  +            logger.warn(null, e);
               throw new UnknownException(e);
            }
   
  @@ -691,14 +711,13 @@
               else {
                  Object[] params = 
                     op.readParams((org.omg.CORBA_2_3.portable.InputStream)in);
  -               MethodInvocation mi =  
  -                  new MethodInvocation(id, 
  -                                       op.getMethod(), 
  -                                       params,
  -                                       null, /* tx */
  -                                       null, /* identity */
  -                                       null  /* credential */);
  -               retVal = container.invoke(mi);
  +               Invocation inv = new Invocation(id, 
  +                                               op.getMethod(), 
  +                                               params,
  +                                               null, /* tx */
  +                                               null, /* identity */
  +                                               null  /* credential */);
  +               retVal = container.invoke(inv);
               }
               out = (org.omg.CORBA_2_3.portable.OutputStream) 
                     handler.createReply();
  @@ -707,7 +726,7 @@
               }
            }
            catch (Exception e) {
  -            e.printStackTrace(System.err);
  +            logger.warn(null, e);
               out = (org.omg.CORBA_2_3.portable.OutputStream) 
                     handler.createExceptionReply();
               op.writeException(out, e);
  @@ -728,7 +747,9 @@
                    Object credential)
         throws Exception
      {
  -      //System.err.println("EJBObject local invocation: " + opName);
  +      if (logger.isTraceEnabled()) {
  +         logger.trace("EJBObject local invocation: " + opName);
  +      }
   
         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(container.getClassLoader());
  @@ -743,21 +764,23 @@
            Object id;
            try {
               id = toObject(poaCurrent.get_object_id());
  -            //System.out.println("                      id class is " 
  -            //                   + id.getClass().getName());
  +            if (logger.isTraceEnabled()) {
  +               logger.trace("                      id class is " 
  +                            + id.getClass().getName());
  +            }
            }
            catch (Exception e) {
  -            e.printStackTrace(System.err);
  +            logger.warn(null, e);
               throw new UnknownException(e);
            }
            
  -         MethodInvocation mi =  new MethodInvocation(id, 
  -                                                     op.getMethod(), 
  -                                                     arguments,
  -                                                     null, /* tx */
  -                                                     null, /* identity */
  -                                                     null  /* credential */);
  -         return container.invoke(mi);
  +         Invocation inv = new Invocation(id, 
  +                                         op.getMethod(), 
  +                                         arguments,
  +                                         null, /* tx */
  +                                         null, /* identity */
  +                                         null  /* credential */);
  +         return container.invoke(inv);
         }
         finally {
            Thread.currentThread().setContextClassLoader(oldCl);
  @@ -890,7 +913,6 @@
       * reference.
       */
      protected static byte[] toByteArray(Object obj) 
  -         throws RemoteException 
      {
         try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
  @@ -903,12 +925,11 @@
            return a;
         }
         catch (IOException ioe) {
  -         throw new ServerException("Object id serialization error", ioe);
  +         throw new RuntimeException("Object id serialization error:\n" + ioe);
         }
      }
      /*----------------------------------------------------------------------
      protected static byte[] toByteArray(Object obj) 
  -         throws RemoteException 
      {
         try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
  @@ -921,7 +942,7 @@
            return a;
         }
         catch (IOException ioe) {
  -         throw new ServerException("Object id serialization error", ioe);
  +         throw new RuntimeException("Object id serialization error\n" + ioe);
         }
      }
      ------------------------------------------------------------------------*/
  @@ -982,7 +1003,9 @@
                                     InputStream in,
                                     ResponseHandler handler) 
         {
  -         //System.err.println("EJBHome invocation: " + opName);
  +         if (logger.isTraceEnabled()) {
  +            logger.trace("EJBHome invocation: " + opName);
  +         }
   
            ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(
  @@ -1012,14 +1035,13 @@
                  else {
                     Object[] params = op.readParams(
                                     (org.omg.CORBA_2_3.portable.InputStream)in);
  -                  MethodInvocation mi = new MethodInvocation(
  -                                                       null, 
  -                                                       op.getMethod(), 
  -                                                       params,
  -                                                       null, /* tx */
  -                                                       null, /* identity */
  -                                                       null  /* credential*/);
  -                  retVal = container.invokeHome(mi);
  +                  Invocation inv = new Invocation(null, 
  +                                                  op.getMethod(), 
  +                                                  params,
  +                                                  null, /* tx */
  +                                                  null, /* identity */
  +                                                  null  /* credential*/);
  +                  retVal = container.invokeHome(inv);
                  }
                  out = (org.omg.CORBA_2_3.portable.OutputStream) 
                     handler.createReply();
  @@ -1028,7 +1050,7 @@
                  }
               }
               catch (Exception e) {
  -               e.printStackTrace(System.err);
  +               logger.warn(null, e);
                  out = (org.omg.CORBA_2_3.portable.OutputStream) 
                     handler.createExceptionReply();
                  op.writeException(out, e);
  @@ -1049,7 +1071,9 @@
                       Object credential)
            throws Exception
         {
  -         //System.err.println("EJBHome local invocation: " + opName);
  +         if (logger.isTraceEnabled()) {
  +            logger.trace("EJBHome local invocation: " + opName);
  +         }
            
            ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(
  @@ -1062,14 +1086,13 @@
                  throw new BAD_OPERATION(opName);
               }
               
  -            MethodInvocation mi =  
  -               new MethodInvocation(null, 
  -                                    op.getMethod(), 
  -                                    arguments,
  -                                    null, /* tx */
  -                                    null, /* identity */
  -                                    null  /* credential */);
  -            return container.invokeHome(mi);
  +            Invocation inv = new Invocation(null, 
  +                                            op.getMethod(), 
  +                                            arguments,
  +                                            null, /* tx */
  +                                            null, /* identity */
  +                                            null  /* credential */);
  +            return container.invokeHome(inv);
            }
            finally {
               Thread.currentThread().setContextClassLoader(oldCl);
  @@ -1078,7 +1101,7 @@
   
      }
   
  -   // Inner class HomeFactory -------------------------------------------------
  +   // Nested class HomeFactory ------------------------------------------------
   
      public static class HomeFactory implements ObjectFactory {
   
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to