Latest Entries »

Showing posts with label JNDI. Show all posts
Showing posts with label JNDI. Show all posts

Tuesday, April 28, 2009

javax.naming.NameNotFoundException: Name java:comp is not bound in this Context


To resolve this exception, need to cross check context.xml, web.xml and jar files.

Creation of context.xml in your META-INF auto generates the xml file with the project name in TOMCAT/conf/ ( C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.18\conf\Catalina\localhost ) cross check this file.

compare context.xml and web.xml with the reference files posted in my previous posting.









No need to create an entry in TOMCAT context.xml and server.xml files.

Finally you need to check your lib folders, both tomcat and project lib.

If you have the following jar's in your lib folder, then remove those

a) naming-common.jar
b) naming-factory.jar
c) naming-resources.jar

clean and rebuild your project and then deploy it, before starting tomcat delete xml file from C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.18\conf\Catalina\localhost

Stack Trace:

javax.naming.NameNotFoundException: Name java:comp is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:765)
at org.apache.naming.NamingContext.lookup(NamingContext.java:147)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.sravan.As400Connection.getConnection(As400Connection.java:47)
at com.sravan.GetValuesFromDB.getViolationCodeQM(GetValuesFromDB.java:1054)
at com.sravan.InsertintoDB.insertFromIntofiles(InsertintoDB.java:746)
at com.parseWEB.Services.ProjectNameSoapBindingImpl.getRequest(ProjectNameSoapBindingImpl.java:545)
at com.parseWEB.Services.ProjectNameSoapBindingSkeleton.getRequest(ProjectNameSoapBindingSkeleton.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)

Stack Trace of TOMCAT:

May 31, 2009 10:01:39 AM org.apache.tomcat.util.modeler.Registry registerComponent
SEVERE: Null component Catalina:type=DataSource,path=/ProjectName,host=localhost,class=javax.sql.DataSource,name="jdbc/DataSourceAS400"
May 31, 2009 10:01:39 AM org.apache.tomcat.util.modeler.Registry registerComponent
SEVERE: Null component Catalina:type=DataSource,path=/ProjectName,host=localhost,class=javax.sql.DataSource,name="jdbc/DataSource"

Thursday, March 5, 2009

Apache Tomcat 6.0 JNDI Datasource

Configuration of JNDI

1. Create context.xml file in META-INF folder.











2. Create an entry for resource-ref in web.xml.











3. Make sure that the following JAR's added in your TOMCAT/lib
( C:\Program Files\Apache Software Foundation\apache-tomcat-6.0.18\lib )
a. commons-collections-3.2.jar
b. commons-dbcp-1.2.2.jar
c. commons-pool-1.4.jar




















Note: for mysql add mysql-connector-java-5.1.5-bin.jar in TOMCAT/lib and for as400 add jt400.jar etc...









Java Code:
/*===========================================================================+
| Copyright (c) 2009 Sravan Modugula, |
| All rights reserved. |
+===========================================================================+
| HISTORY
| Created By : Sravan Modugula
| Date : 12-10-2008
| Description: class represents As400Connection
|
+===========================================================================*/

package com.sravan.modugula.as400database;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import org.apache.log4j.Logger;

public class As400Connection {

/**
* logger instance
*/
private static final Logger log = Logger.getLogger(As400Connection.class);

public static Connection getConnection() {
log.info(" Starting establish as400 connection");

Connection as400Connection = null;
try {
Context ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx
.lookup("java:comp/env/jdbc/databaseAS400");
if (dataSource != null) {
as400Connection = dataSource.getConnection();
return as400Connection;
}
} catch (Exception e) {
e.printStackTrace();
log.fatal("Got Exception when getting as400 connection");
log.fatal("Exception is ", e);
}
// log.info(" ConnectionPtest Ending"+System.currentTimeMillis()/1000);
return as400Connection;
}

public static void closeConnection(Connection as400Connection) {
try {
if (as400Connection != null) {
as400Connection.close();
as400Connection = null;
}
} catch (SQLException e) {
log.error(e.getMessage(), e);
} finally {
if (as400Connection != null)
try {
as400Connection.close();
log.info("Closed connection");
} catch (SQLException e) {
log.error(e.getMessage(), e);
}
}
}

}