We seem to be ecperiencing the same problem many of you have with JRUN. We are using a 
very simple servlet that accepts a "POST" from a java applet, verifies the user id and 
password that was passed in to an LDAP server, and returns a result string to the 
Applet. We use this to provide application security to our applets.

The problem is that after a period of time we get the "Out Of Memeory" Exceptions. The 
time period can be a day or a week or anything.

We have tried to increase the amount of memory available by using the
-mx64M, but it did not help. We are running on HPUX 10.20.

I have read in other postings that it could be running out of file handles instead of 
memory. How can you tell?

The process is only using around 8MB when you run the TOP command. The support staff 
from JRUN has not been able to help yet. Any ideas?

Also, how can you tell how many concurrent requests are hitting the Servlet? I have 
around 1000 users, but it only takes a couple seconds for the server to perform its 
operations.

I've included the code from our servlet if anyone wants to recommend modifications....

---------Source Code ------------------------------

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import netscape.ldap.*;
import java.util.*;
import java.net.*;

public class AuthServPlusGroups extends HttpServlet
{

  /**
    * <p>Performs the HTTP POST operation
    *
    * @param req The request from the client
    * @param resp The response from the servlet
    */

  public void doPost(HttpServletRequest req,
                     HttpServletResponse resp)
    throws ServletException, java.io.IOException
    {
        String machineip;
        String group;

      ServletInputStream in = req.getInputStream();
      byte[] b = new byte[202];
      in.readLine(b,0,202);
      String myString = new String(b);
      myString = myString.trim();
      resp.setContentType("application/octet-stream");
      ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(byteOut);

      int nameEql = myString.indexOf("=")+1;
      int nameEnd = myString.indexOf("&");
      String userid=myString.substring(nameEql,nameEnd);

      String nextString = myString.substring(nameEnd+1);
      int pwdEql = nextString.indexOf("=")+1;
      int pwdEnd = nextString.indexOf("&");
      String userpwd = nextString.substring(pwdEql,pwdEnd);
      String lastString = nextString.substring(pwdEnd+1);

      int ipEql = lastString.indexOf("=")+1;
      int ipEnd = lastString.indexOf("&");
      if (ipEnd == -1){
          machineip = lastString.substring(ipEql);
          group = "NONE";
      }else{
          machineip = lastString.substring(ipEql,ipEnd);
          String nextString2 = lastString.substring(ipEnd+1);
          int groupEql = nextString2.indexOf("=")+1;
          int groupEnd = nextString2.indexOf("&");
          group = nextString2.substring(groupEql, groupEnd);
      }

      String results = verifyPassword(machineip,userid,userpwd);
      if (!group.equals("NONE"))
      {
        String groupdn="cn=" + group + ", o=EDS.com";
         String entrydn = "uid=" + userid + ", o=EDS.com";
         results = results + "," + checkGroup(machineip,groupdn,entrydn);
      }

      out.writeObject(results);
      out.flush();
      out.close();
      byte[] buf = byteOut.toByteArray();
      byteOut.close();
      resp.setContentLength(buf.length);
      ServletOutputStream servletOut = resp.getOutputStream();

      //wrap up
      servletOut.write(buf);
      servletOut.close();
    destroy();
    }

  /**
    * <p>Initialize the servlet. This is called once when the
    * servlet is loaded. It is guaranteed to complete before any
    * requests are made to the servlet
    *
    * @param cfg Servlet configuration information
    */

  public void init(ServletConfig cfg)
    throws ServletException
    {
      super.init(cfg);
    }

  /**
    * <p>Destroy the servlet. This is called once when the servlet
    * is unloaded.
    */

  public void destroy()
    {
      super.destroy();
    }

    /**
     * The checkGroup method checks the LDAP attributes to see
     * the entered entry.
     * @param  GROUPDN       Group DN
     * @param  groupattr     LDAP directory attribute
     * @param ipAddress The ipAddress of the LDAP directory server.
     */
    public boolean checkGroup(String ipAddress, String GROUPDN, String ENTRYDN)
    {
        boolean rc=false;
        LDAPConnection ld=makeConnection(ipAddress);
        try {
            LDAPAttribute groupAttr = new LDAPAttribute( "uniquemember", ENTRYDN );
            rc = ld.compare( GROUPDN, groupAttr );
            System.out.println("result of ld compare in checkGroup is "+rc);
        }catch(LDAPException e) {
            ErrLog.writeLog("DirectoryServerAccess 
checkGroup",e.errorCodeToString(e.getLDAPResultCode()) + "checkGroup failed");
        }
        endConnection(ld);
        return rc;
    }

    /**
     * The method verifyPassword, verifies the password entry for
     * a particular user id.
     *
     * @param  id        User id whose password is being checked
     * @param  pwd       Password that is verified
     * @param ipAddress The ipAddress of the LDAP directory server.
     */
    public String verifyPassword(String ipAddress, String id, String pwd)
    {
        String resultString = null;
        boolean ok=true;


        LDAPConnection ld = null;
        ld = makeConnection(ipAddress);
        String ENTRYDN = "uid=" + id + ", o=EDS.com";
        LDAPAttribute attr = new LDAPAttribute( "userPassword", "{crypt}" + pwd );

        try
        {
            ld.authenticate(ENTRYDN,pwd);
            resultString = "Authenticated";
         }catch (LDAPException e5)
         {
             ok=false;
             switch (e5.getLDAPResultCode())
             {
                       case e5.INVALID_CREDENTIALS:
                       
ErrLog.writeLog("AuthServ",e5.errorCodeToString(e5.getLDAPResultCode()) + "Invalid 
password in verifyPassword for id = "+id);
                       resultString = "Invalid Password";
                       break;
                       case e5.NO_SUCH_OBJECT:
                       
ErrLog.writeLog("AuthServ",e5.errorCodeToString(e5.getLDAPResultCode()) + "Specified 
user does not exist "+ id);
                       resultString = "Not a Valid EDS NetConnect User";
                 break;
             }
          }// end catch block
    endConnection(ld);


    return resultString;
    }

    /**
     * The makeConnection method checks the LDAP attributes to see
     * the entered entry.
     * @param  GROUPDN       Group DN
     * @param  groupattr     LDAP directory attribute
     * @param ipAddress The ipAddress of the LDAP directory server.
     */
    public LDAPConnection makeConnection(String ipAddress)
    {
        LDAPConnection ld = null;
        try
        {
            ld = new LDAPConnection();
            int MY_PORT = 389;
            String MGR_DN = "uid=autoadmin,o=EDS.com";
            String MGR_PW = "1nicetry";     // password for plnet001
            ld.connect( ipAddress, MY_PORT, MGR_DN, MGR_PW);
        }catch( LDAPException e )
        {
           ErrLog.writeLog("AuthServ",e.errorCodeToString(e.getLDAPResultCode()) + 
"Error connecting to LDAP in makeConnection");
        }

    return ld;

    }

    /**
     * The endConnection method checks the LDAP attributes to see
     * the entered entry.
     * @param  GROUPDN       Group DN
     * @param  groupattr     LDAP directory attribute
     */
    public boolean endConnection(LDAPConnection ld)
    {
        boolean ok=true;

        if ( (ld != null) && ld.isConnected() )
        {
            try
            {
                ld.disconnect();
            }catch ( LDAPException e )
            {
             ErrLog.writeLog("AuthServ",e.errorCodeToString(e.getLDAPResultCode()) + 
"Error disconnecting from LDAP in endConnection");
             ok=false;
            }
        }
        return ok;
    }

}

----------------------------------------

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to