dblevins    2004/09/23 15:23:18

  Modified:    modules/core/src/java/org/openejb/client JNDIContext.java
                        JNDIRequest.java JNDIResponse.java
                        RequestMethods.java ResponseCodes.java
  Added:       modules/core/src/java/org/openejb/client
                        AppClientJNDIContext.java ContextImpl.java
  Log:

  Added AppClient support for JNDI
  
  Revision  Changes    Path
  1.3       +10 -20    
openejb/modules/core/src/java/org/openejb/client/JNDIContext.java
  
  Index: JNDIContext.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/client/JNDIContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JNDIContext.java  30 Jul 2004 19:03:44 -0000      1.2
  +++ JNDIContext.java  23 Sep 2004 19:23:18 -0000      1.3
  @@ -44,21 +44,13 @@
    */
   package org.openejb.client;
   
  +import javax.naming.*;
  +import javax.naming.spi.InitialContextFactory;
   import java.io.Serializable;
   import java.net.InetAddress;
   import java.net.URL;
   import java.net.UnknownHostException;
   import java.util.Hashtable;
  -
  -import javax.naming.ConfigurationException;
  -import javax.naming.Context;
  -import javax.naming.InvalidNameException;
  -import javax.naming.Name;
  -import javax.naming.NameNotFoundException;
  -import javax.naming.NameParser;
  -import javax.naming.NamingEnumeration;
  -import javax.naming.NamingException;
  -import javax.naming.spi.InitialContextFactory;
   /**
    * JNDI client
    * 
  @@ -80,7 +72,6 @@
        *
        * @param environment
        * @exception NamingException
  -     * @see NamingServer
        */
       JNDIContext(Hashtable environment) throws NamingException{
           init( environment );
  @@ -108,7 +99,6 @@
        *
        * @param environment
        * @exception NamingException
  -     * @see NamingServer
        */
       public void init(Hashtable environment) throws NamingException{
       }
  @@ -160,8 +150,8 @@
           String psswrd    = (String) env.get(Context.SECURITY_CREDENTIALS);
           Object serverURL = env.get(Context.PROVIDER_URL);
   
  -        if (userID == null) throw new ConfigurationException("Context property 
cannot be null: "+Context.SECURITY_PRINCIPAL);
  -        if (psswrd == null) throw new ConfigurationException("Context property 
cannot be null: "+Context.SECURITY_CREDENTIALS);
  +//        if (userID == null) throw new ConfigurationException("Context property 
cannot be null: "+Context.SECURITY_PRINCIPAL);
  +//        if (psswrd == null) throw new ConfigurationException("Context property 
cannot be null: "+Context.SECURITY_CREDENTIALS);
           if (serverURL == null) throw new ConfigurationException("Context property 
cannot be null: "+Context.PROVIDER_URL);
           
           URL url;
  @@ -200,11 +190,11 @@
           AuthenticationRequest  req = new AuthenticationRequest(userID, psswrd);
           AuthenticationResponse res = null;
   
  -     try {
  -         res = requestAuthorization(req);
  -     } catch (java.rmi.RemoteException e) {
  -         throw new javax.naming.AuthenticationException(e.getLocalizedMessage());
  -     }
  +        try {
  +            res = requestAuthorization(req);
  +        } catch (java.rmi.RemoteException e) {
  +            throw new javax.naming.AuthenticationException(e.getLocalizedMessage());
  +        }
           
           switch (res.getResponseCode()) {
               case AUTH_REDIRECT:
  
  
  
  1.2       +14 -4     
openejb/modules/core/src/java/org/openejb/client/JNDIRequest.java
  
  Index: JNDIRequest.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/client/JNDIRequest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JNDIRequest.java  1 Mar 2004 07:14:43 -0000       1.1
  +++ JNDIRequest.java  23 Sep 2004 19:23:18 -0000      1.2
  @@ -55,6 +55,13 @@
   public class JNDIRequest implements Request {
       
       private transient int requestMethod = -1;
  +
  +
  +    public void setClientModuleID(String clientModuleID) {
  +        this.clientModuleID = clientModuleID;
  +    }
  +
  +    private transient String clientModuleID;
       private transient String requestString;
   
       public JNDIRequest() {
  @@ -85,7 +92,10 @@
           this.requestString = requestString;
       }
   
  -    
  +    public String getClientModuleID() {
  +        return clientModuleID;
  +    }
  +
       /**
        * The object implements the readExternal method to restore its
        * contents by calling the methods of DataInput for primitive
  @@ -100,6 +110,7 @@
        */
       public void readExternal(ObjectInput in) throws 
IOException,ClassNotFoundException {
           requestMethod = in.readByte();
  +        clientModuleID = in.readUTF();
           requestString = in.readUTF();
       }
       /**
  @@ -119,9 +130,8 @@
        */
       public void writeExternal(ObjectOutput out) throws IOException {
           out.writeByte((byte)requestMethod);
  +        out.writeUTF(clientModuleID);
           out.writeUTF (requestString);
       }
   
   }
  -
  -
  
  
  
  1.2       +86 -1     
openejb/modules/core/src/java/org/openejb/client/JNDIResponse.java
  
  Index: JNDIResponse.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/client/JNDIResponse.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JNDIResponse.java 1 Mar 2004 07:14:43 -0000       1.1
  +++ JNDIResponse.java 23 Sep 2004 19:23:18 -0000      1.2
  @@ -44,6 +44,10 @@
    */
   package org.openejb.client;
   
  +import javax.naming.Binding;
  +import javax.naming.Context;
  +import javax.naming.NamingEnumeration;
  +import javax.naming.NamingException;
   import java.io.IOException;
   import java.io.ObjectInput;
   import java.io.ObjectOutput;
  @@ -54,12 +58,22 @@
    */
   public class JNDIResponse implements Response {
   
  +
  +    private transient ServerMetaData serverMetaData;
       private transient int responseCode = -1;
       private transient Object result;
  +    private static final int CONTEXT = 1;
  +    private static final int EJBHOME = 2;
  +    private static final int OBJECT = 3;
  +    private static final int END = 99;
   
       public JNDIResponse(){
       }
   
  +    public JNDIResponse(ServerMetaData serverMetaData) {
  +        this.serverMetaData = serverMetaData;
  +    }
  +
       public JNDIResponse(int code, Object obj){
           responseCode = code;
           result = obj;
  @@ -112,9 +126,46 @@
                   m.readExternal(in);
                   result = m;
                   break;
  +            case JNDI_CONTEXT_TREE:
  +                result = readContextTree(in);
  +                break;
           }
       }
   
  +    private Context readContextTree(ObjectInput in) throws IOException, 
ClassNotFoundException {
  +
  +        ContextImpl context = new ContextImpl();
  +
  +        CONTEXT_LOOP: while (true) {
  +            byte type = in.readByte();
  +            String name = null;
  +            Object obj = null;
  +            switch (type) {
  +                case CONTEXT:
  +                    name = in.readUTF();
  +                    obj = readContextTree(in);
  +                    break;
  +                case END:
  +                    break CONTEXT_LOOP;
  +                default:
  +                    name = in.readUTF();
  +                    obj = in.readObject();
  +            }
  +
  +            try {
  +                context.internalBind(name,obj);
  +            } catch (NamingException e) {
  +
  +            }
  +        }
  +
  +
  +        return context;
  +    }
  +
  +
  +
  +
       /**
        * The object implements the writeExternal method to save its contents
        * by calling the methods of DataOutput for its primitive values or
  @@ -148,7 +199,41 @@
                   EJBMetaDataImpl m = (EJBMetaDataImpl)result;
                   m.writeExternal(out);
                   break;
  +            case JNDI_CONTEXT_TREE:
  +                writeContextTree(out, (Context)result);
  +                break;
   
           }
       }
  +
  +
  +
  +    private void writeContextTree(ObjectOutput out, Context context)  throws 
IOException {
  +        String name = null;
  +        try {
  +            NamingEnumeration enum = context.listBindings( "" );
  +            while (enum.hasMoreElements()){
  +                Binding pair = (Binding)enum.next();
  +                name = pair.getName();
  +
  +                Object obj = pair.getObject();
  +
  +                if ( obj instanceof Context ){
  +                    out.write(CONTEXT);
  +                    out.writeUTF(name);
  +                    writeContextTree(out, (Context)obj);
  +                } else {
  +                    out.write(OBJECT);
  +                    out.writeUTF(name);
  +                    out.writeObject(obj);
  +                }
  +            }
  +            out.write(END);
  +        } catch (NamingException e) {
  +            IOException ioException = new IOException("Unable to pull data from 
JNDI: "+name);
  +            ioException.initCause(e);
  +            throw ioException;
  +        }
  +    }
  +
   }
  
  
  
  1.2       +3 -2      
openejb/modules/core/src/java/org/openejb/client/RequestMethods.java
  
  Index: RequestMethods.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/client/RequestMethods.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RequestMethods.java       1 Mar 2004 07:14:43 -0000       1.1
  +++ RequestMethods.java       23 Sep 2004 19:23:18 -0000      1.2
  @@ -90,7 +90,8 @@
       public static final int JNDI_LOOKUP                 = 27;
       public static final int JNDI_LIST                   = 28;
       public static final int JNDI_LIST_BINDINGS          = 29;
  -    
  +    public static final int JNDI_APP_CTX_PULL           = 30;
  +
   
   }
   
  
  
  
  1.2       +2 -1      
openejb/modules/core/src/java/org/openejb/client/ResponseCodes.java
  
  Index: ResponseCodes.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/client/ResponseCodes.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ResponseCodes.java        1 Mar 2004 07:14:43 -0000       1.1
  +++ ResponseCodes.java        23 Sep 2004 19:23:18 -0000      1.2
  @@ -72,5 +72,6 @@
       public static final int JNDI_RUNTIME_EXCEPTION   = 18;
       public static final int JNDI_ERROR               = 19;
       public static final int EJB_OK_FOUND_ENUMERATION = 20;
  +    public static final int JNDI_CONTEXT_TREE        = 21;
   }
   
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/client/AppClientJNDIContext.java
  
  Index: AppClientJNDIContext.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce the
   *    above copyright notice, this list of conditions and the
   *    following disclaimer in the documentation and/or other
   *    materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.sf.net/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: AppClientJNDIContext.java,v 1.1 2004/09/23 19:23:18 dblevins Exp $
   */
  package org.openejb.client;
  
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GBeanInfoFactory;
  
  import javax.management.ObjectName;
  import javax.naming.Context;
  import javax.naming.NamingException;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/09/23 19:23:18 $
   */
  public class AppClientJNDIContext implements 
org.apache.geronimo.client.AppClientPlugin {
  
      private final String host;
      private final int port;
      private Context context;
  
      public AppClientJNDIContext(String host, int port) {
          this.host = host;
          this.port = port;
      }
  
      public void startClient(ObjectName appClientModuleName) throws Exception {
          try {
              ServerMetaData serverMetaData = new ServerMetaData(host, port);
  
              JNDIResponse res = new JNDIResponse(serverMetaData);
              JNDIRequest req = new JNDIRequest(JNDIRequest.JNDI_LOOKUP, "");
  
              req.setClientModuleID(appClientModuleName.toString());
  
              Client.request(req, res, serverMetaData);
  
              context = (Context) res.getResult();
          } catch (Exception e) {
              NamingException namingException = new NamingException("Unable to 
retrieve J2EE AppClient's JNDI Context");
              e.initCause(namingException);
              throw namingException;
          }
      }
  
      public void stopClient(ObjectName appClientModuleName) throws Exception {
      }
  
      public static final GBeanInfo GBEAN_INFO;
  
      static {
          GBeanInfoFactory infoFactory = new 
GBeanInfoFactory(AppClientJNDIContext.class);
  
          infoFactory.addOperation("startClient", new Class[]{ObjectName.class});
          infoFactory.addOperation("stopClient", new Class[]{ObjectName.class});
          infoFactory.addAttribute("host", String.class, true);
          infoFactory.addAttribute("port", int.class, true);
          infoFactory.addAttribute("context", Context.class, false);
          infoFactory.setConstructor(new String[]{"host", "port"});
  
          GBEAN_INFO = infoFactory.getBeanInfo();
      }
  
  
      public static GBeanInfo getGBeanInfo() {
          return GBEAN_INFO;
      }
  }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/client/ContextImpl.java
  
  Index: ContextImpl.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce the
   *    above copyright notice, this list of conditions and the
   *    following disclaimer in the documentation and/or other
   *    materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.sf.net/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: ContextImpl.java,v 1.1 2004/09/23 19:23:18 dblevins Exp $
   */
  package org.openejb.client;
  
  import org.apache.geronimo.naming.java.ReadOnlyContext;
  
  import javax.naming.NamingException;
  import java.util.Hashtable;
  import java.util.Iterator;
  import java.util.Map;
  
  class ContextImpl extends ReadOnlyContext {
  
      public ContextImpl() {
          super();
      }
  
      public ContextImpl(Map entries) throws NamingException {
          super();
          for (Iterator iter = entries.entrySet().iterator(); iter.hasNext();) {
              Map.Entry entry = (Map.Entry) iter.next();
              String key = (String) entry.getKey();
              Object value = entry.getValue();
              internalBind(key, value);
          }
      }
  
      protected ContextImpl(ReadOnlyContext clone, Hashtable env) {
          super(clone, env);
      }
  
      protected Map internalBind(String name, Object value) throws NamingException {
          return super.internalBind(name, value);
      }
  }
  
  
  

Reply via email to