wood burning stoves 2.0*
The moose likes JSP and the fly likes Array out of Bounds in Ldap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Array out of Bounds in Ldap " Watch "Array out of Bounds in Ldap " New topic
Author

Array out of Bounds in Ldap

sandhya balakrishnan
Greenhorn

Joined: Apr 07, 2005
Posts: 2
Hi ,
Iam using the following code:

public Vector sendRequest(String searchBase, HashMap matchRules, boolean ignoreCase, String[] returnAttrs) {
lastResult = new Vector();
NamingEnumeration response = null;
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,
"ldap://" + ldapServer + ":" + String.valueOf(ldapPort) + "/+ rootDn);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, ldapUserId);
env.put(Context.SECURITY_CREDENTIALS, ldapPassword);

DirContext ctx = new InitialDirContext(env);

Attributes matchAttrs = new BasicAttributes(ignoreCase);
if (matchRules != null) {
Iterator attrIter = matchRules.keySet().iterator();
while (attrIter.hasNext()) {
String key = (String) attrIter.next();
String value = (String) matchRules.get(key);
matchAttrs.put(new BasicAttribute(key, value));
}
}

response = ctx.search(searchBase, matchAttrs, returnAttrs);
lastResult = new Vector();
while (response.hasMore()) {
HashMap attrMap = new HashMap();
SearchResult sr = (SearchResult) response.next();
Attributes attrs = sr.getAttributes();
NamingEnumeration attrsEnum = attrs.getAll();
while (attrsEnum.hasMore()) {
Vector values = new Vector();
Attribute attr = (Attribute) attrsEnum.next();
for (int i = 0; i < attr.size(); i++) {
values.add(attr.get(i));
}
attrMap.put(attr.getID(), values);
}
lastResult.add(attrMap);
}
}
catch (NamingException e) {
System.err.println("Problem looking up name-------:" + e);
}
catch (Exception e) {
System.err.println("Exception:" + e);
}
return lastResult;

}

IAm getting this error in the tomcat server log,
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
at java.util.Vector.get(Vector.java:709)
at com.cisco.ipphone.sdk.User.loadAttributes(User.java:327)
at org.apache.jsp.push2phone_jsp._jspService(push2phone_jsp.java:180)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)



I traced out that the error is at this point in the code
DirContext ctx = new InitialDirContext(env);

Any suggestions wud be appreciated
Thanks
sandhya balakrishnan
Greenhorn

Joined: Apr 07, 2005
Posts: 2
Hi,
I found the solution to this myself after 2 days of googling. All i had to do was close ctx, ie ctx.close(). Thus each time a lapd request is made connection will opened and closed. Thus freeing the memory.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array out of Bounds in Ldap
 
Similar Threads
Struts error
Cannot find ActionMappings
parseInt problem
servlet exception with code
taglibs Working in tomcat3.22 but failing in tomcat4.1.31