hello
I am making an application in which i want to add the name of the user into the directory server (LDAP) through the servlet
The code to add the entries to LDAP server is running quite fine but when i integrate the code into the servlet there is no result.
The log file is also not showing the error
As well as when i create any object as
Adder a = new Adder();
into the servlet for adding
The various classes that are lying in the Adder.java class (which adds the entries to the LDAP ) are bypassed
What maybe the problem
The code for the adding of the entries is
Code:
/*
* Copyright (c) 1997. Netscape Communications Corporation. All
* rights reserved.
*
* Add a new entry to the directory.
*
* Since it is an error to attempt to add an entry which already exists,
* you cannot run this example program twice in a row. You can use the
* del.java example program to delete the entry which this example adds.
*
*/
package com.chat;
import netscape.ldap.*;
import java.util.*;
import java.io.*;
import com.chat.LoginServlet;
public class Add {
public Add()
{
/* Specify the DN we're adding */
String dn = "uid, ou=People, o=Airius.com";
/* Specify the attributes of the entry */
// THIS STATEMENT DOES NOT EXECUTE
System.out.println("1");
String objectclass_values[] = { "top",
"person",
"organizationalPerson",
"inetOrgPerson" };
String cn_values[] = { "William B Jensen",
"William Jensen",
"Bill Jensen" };*/
String sn_values[] = { "Jensen" };
String givenname_values[] = { "William", "Bill" };
String telephonenumber_values[] = { "+1 415 555 1212" };
LDAPAttributeSet attrs = new LDAPAttributeSet();
LDAPAttribute attr = new LDAPAttribute( "objectclass" );
for( int i = 0; i < objectclass_values.length; i++ )
{
attr.addValue( objectclass_values[i] );
}
attrs.add( attr );
attrs.add( new LDAPAttribute( "uid") );
/* Create an entry with this DN and these attributes */
LDAPEntry myEntry = new LDAPEntry( dn, attrs );
LDAPConnection ld = null;
int status = -1;
try {
ld = new LDAPConnection();
/* Connect to server */
String MY_HOST = "localhost";
int MY_PORT = 389;
ld.connect( MY_HOST, MY_PORT );
/* Authenticate to the server as directory manager */
String MGR_DN = "dc=monarch,dc=com";
String MGR_PW = "ali";
ld.authenticate( MGR_DN, MGR_PW );
System.out.println("Entry established");
/* Now add the entry to the directory */
ld.add( myEntry );
System.out.println( "Entry added" );
System.out.println("Entry established1111");
}
catch( LDAPException e ) {
if ( e.getLDAPResultCode() == LDAPException.ENTRY_ALREADY_EXISTS )
System.out.println( "Error: Entry already present" );
else
System.out.println( "Error: " + e.toString()+"AA che error" );
}
}
}
The code for the servlet is
Code:
package it.com.chat.java;
import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.swing.*;
import it.com.chat.Chatter;
import it.com.chat.ChatRoomList;
import it.com.chat.ChatRoom;
public class LoginServlet extends HttpServlet
{
boolean flag = false;
String s1,s2;
int i = 1800;
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doPost(req,res);
}
public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
String s = "jdbc:odbc:chat";
contextPath = httpservletrequest.getContextPath();
s1 = httpservletrequest.getParameter("nickname");
s2 = httpservletrequest.getParameter("pwd");
System.out.println(s1);
System.out.println(s2);
s1 = s1.trim().toLowerCase();
if(s2.length() > 0)
s2 = s2.trim().toLowerCase();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection(s);
Statement statement = connection.createStatement();
for(ResultSet resultset = statement.executeQuery("select * from Login"); resultset.next();)
{
String s3 = resultset.getString(1);
String s4 = resultset.getString(2);
if(s1.equals(s3) && s2.equals(s4))
{
flag = true;
}
}
}//try ends here
catch(SQLException sqlexception)
{
System.out.println("Error...." + sqlexception);
}
catch(ClassNotFoundException classnotfoundexception)
{
System.out.println("Error...." + classnotfoundexception);
}
out = new ObjectOutputStream(httpservletresponse.getOutputStream());
out.writeBoolean(flag);
out.flush();
out.close();
if(flag=true)
{
try
{
System.out.println("Control is here now...");
ChatRoomList chatroomlist = (ChatRoomList)getServletContext().getAttribute("chatroomlist");
boolean flag1 = chatroomlist.chatterExists(s1);
//HERES WHERE THE CODE IS PLACED TO ADD THE ENTRIES TO THE LDAP SERVER
//THE OBJECT OF ADD.JAVA CLASS WHICH IS CALLED
if(flag1)
{
JOptionPane.showMessageDialog(null,"U have already Login......","Information",JOptionPane.INFORMATION_MESSAGE);
}
else
{
httpsession = httpservletrequest.getSession(true);
String s2 = getServletContext().getInitParameter("sessionTimeout");
if(s2 != null)
try
{
i = Integer.parseInt(s2);
i *= 60;
}
catch(NumberFormatException numberformatexception) { }
}
httpsession.setMaxInactiveInterval(i);
httpsession.setAttribute("nickname", s1);
ChatRoom chatroom = chatroomlist.getRoom("StartUp");
s1 = s1.toLowerCase();
Chatter chatter = null;
chatter = new Chatter(s1);
chatroom.addChatter(chatter);
ChatRoom chatRoom = null;
Chatter[] chatters = chatRoom.getChattersArray();
out = new ObjectOutputStream(httpservletresponse.getOutputStream());
out.writeObject(chatters);
out.flush();
out.close();
}//try ends
catch(Exception exception)
{
System.out.println("Exception thrown in LoginServlet: " + exception.getMessage());
exception.printStackTrace();
}
}//if ends here
else
{
JOptionPane.showMessageDialog(null,"Server is saying that Invalid User","Information",JOptionPane.INFORMATION_MESSAGE);
}
}//do post ends here
private final void _mththis()
{
contextPath = "";
}
public LoginServlet()
{
_mththis();
}
private String contextPath;
ObjectOutputStream out=null;
HttpSession httpsession;
}
I am using Netscape sdk for java and openldap server and web server is Apache Tomcat
Plz tell
Regards
Jignesh