Trying to access JNDI source on Tomcat server - sql-server

I have a application running on Jboss server. on Jboss it uses JNDI sources for DB connection name cc.xml & iv.xml.(jboss/server/default/deploy/ Both jndi xml are here)
Now i have to deploy the same war on Tomcat and trying to create & access the JNDI sources from tomcat. I made following changes -
Added following code to META-INF/Context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/R2">
<ResourceLink name="ivrDataSource" global="ivrDataSource" type="javax.sql.DataSource" />
<Resource
name="ivrDataSource"
type="javax.sql.DataSource"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
password=""
maxIdle="2"
maxWait="5000"
username="user"
url="jdbc:jtds:sqlserver://abc:1433;DatabaseName=IVR_GUARDIAN;tds=8.0;lastupdatecount=false;socketKeepAlive=true;"
maxActive="4"/>
<ResourceLink name="ccDataSource" global="ccDataSource" type="javax.sql.DataSource" />
<Resource
name="ccDataSource"
type="javax.sql.DataSource"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
password=""
maxIdle="2"
maxWait="5000"
username="web"
url="jdbc:jtds:sqlserver://xyz:1433;DatabaseName=CC_GUARDIAN;tds=8.0;lastupdatecount=false;socketKeepAlive=true;"
maxActive="4"/>
</Context>
ADDED BELOW TO WEB.XML ----
<!-- FOR TOMCAT DEPLOYMRNT -TESTING -->
<resource-ref>
<description>ccDataSource</description>
<res-ref-name>ccDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>ivrDataSource</description>
<res-ref-name>ivrDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
But i am getting error-
javax.naming.NameNotFoundException: Name ccDataSource,ivrDataSource is not bound in this Context.
Always worked on JBOSS so this is new to me..Missing something here.Please suggest.

You do not have to use <ResourceLink>. Try removing <ResourceLink>s.
<ResourceLink> is used to create a link to a global JNDI resource.
Please see following links for more details.
http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource%20Links
Hope this helps.

Related

Issues while setting up vespa on multiple docker containers

I have two dockers sitting on two different machines, both running the vespa. When I submit an application which have two nodes - vespa1 and vespa2 (resolved in /etc/hosts). I get the following error.
Uploading application '/vespa-eval/src/main/application/' using http://localhost:19071/application/v2/tenant/default/session?name=application
Session 6 for tenant 'default' created.
Preparing session 6 using
http://localhost:19071/application/v2/tenant/default/session/6/prepared
Request failed. HTTP status code: 400
Invalid application package: default.default: Error loading model:
Could not find host in the application's host system: 'vespa-container'. Hostsystem=host 'vespa1',host 'vespa2'
I do not have a problem when using only localhost.
hosts.xml
<?xml version="1.0" encoding="utf-8" ?>
<hosts>
<host name="vespa1">
<alias>node0</alias>
</host>
<host name="vespa2">
<alias>node1</alias>
</host>
</hosts>
services.xml
<?xml version="1.0" encoding="utf-8" ?>
<services version="1.0">
<admin version="2.0">
<adminserver hostalias="node0"/>
<configservers>
<configserver hostalias="node0"/>
</configservers>
</admin>
<container id="container" version="1.0">
<document-api />
<search />
<nodes>
<node hostalias="node0" />
<node hostalias="node1" />
</nodes>
</container>
<content id="product" version="1.0">
<redundancy>1</redundancy>
<documents>
<document type="product" mode="index" />
</documents>
<nodes>
<node hostalias="node0" distribution-key="0" />
<node hostalias="node1" distribution-key="1" />
</nodes>
</content>
</services>
Looks like a host named vespa-container is already deployed but not in the new application package. To debug, try
vespa-model-inspect hosts
on the config server and see if it lists the host. Maybe a good idea to try from scratch, I don't see anything wrong with the enclosed files. To clean the config server, search for
vespa-configserver-remove-state
in the documentation
I came across the same issue, and fixed the error by replacing 'vespa-container' (below command) to the hostname of physical box. However, this caused a couple of other errors in rpc connection. Did you fix the problem yet? #aman.gupta
docker run --detach --name vespa --hostname vespa-container --privileged \
--volume $VESPA_SAMPLE_APPS:/vespa-sample-apps --publish 8080:8080 vespaengine/vespa

Tomcat connection pooling reset by sql server 2008 and 2012

I have 5 different modules connecting sql server 2008 and 2012 using Tomcat connection pooling.
In the Tomcat7\conf\context.xml
<Resource auth="Container" driverClassName="net.sourceforge.jtds.jdbc.Driver" logAbandoned="true" maxActive="100" maxIdle="30" maxWait="10000" name="jdbc/testservice2" password="abc" removeAbandoned="true" removeAbandonedTimeout="60" type="javax.sql.DataSource"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor" username="abc"/>
Module 1 - In the Tomcat7\conf\localhost\Module1.XML
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/Module1">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
Module 2 - In the Tomcat7\conf\localhost\Module2.XML
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/Module2">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
</Context>
Module 3 - In the Tomcat7\conf\localhost\Module3.XML
<Context antiJARLocking="true" path="/Module3">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
</Context>
Module 4 - In the Tomcat7\conf\localhost\Module4.XML
<Context antiJARLocking="true" path="/Module4">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
</Context>
I'm experiencing the below error on QA server as well as staging server?
06-Apr-2015 07:43:28 ERROR DBAccess:49 - I/O Error: Connection reset by peer: socket write error
What's wrong with my Tomcat 7 connection pool configuration? why it's rejected by sql server
You are trying to use all the modules simultaneously in which you have defined the 'Resource' with same name i.e. name="jdbc/testdb" as far as i know this name has to be unique because it is jndi bound with the value you give to name attribute(see tomcat document https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Definitions ). If you define a datasource with same name in different modules(web apps) see that they are not in use simultaneously. Somewhere in your server this is happening. To be safe use different name for 'Resource'.
Another thing-Is 'Resource' with name="jdbc/testservice2" being used in any of your five modules you have mentioned. Cause I don't see a connection between any of your five modules with this 'Resource'.

tomcat JNDI database configuration

I have the following in C:/Tomcat6/conf/context.xml:
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ResourceLink global="jdbc/MyDatasource" name="jdbc/MyDatasource" type="javax.sql.DataSource"/>
</Context>
and the following in C:/Tomcat6/conf/server.xml:
<Resource name="jdbc/MyDatasource"
auth="Container"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
maxactive="100"
maxidle="30"
maxwait="10000"
type="javax.sql.DataSource"
jdbcUrl="jdbc:jtds:sqlserver://localhost/SAFEHOUSE-UK;integratedSecurity=true;">
I have jtds-1.2.5.jar in C:/Tomcat6/lib.
Yet when I hit my application I get the following:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
driver of class 'net.sourceforge.jtds.jdbc.Driver' for connect URL
'null' at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at
com.safehouse.safeservices.authenticate.AdminLoginForm.getpassword(Unknown
Source)
Any help would be much appreciated
1、modify the connection url
jdbcUrl="jdbc:jtds:sqlserver://localhost:1305;DatabaseName=your databasename"
From Apache Tomcat 6 documentation: https://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
maybe the mistake was in attribute name, try to use url instead of jdbcUrl

IllegalStateException on camel cxf route in FUSE (servicemix) ESB

I try to set up a camel (Ver. 2.4.0) route in a FUSE (Ver. 4.3.0) ESB/OSGi container.
It should be a simple cxf-proxy to route a WebService call from a 'proxy' address to a real service.
I read several documentation:
CXF Proxy Example
camel cxf component
and set up the following spring configuration:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://camel.apache.org/schema/osgi
http://camel.apache.org/schema/osgi/camel-osgi.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<import
resource="classpath:META-INF/cxf/cxf.xml" />
<import
resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import
resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
<import
resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />
<!-- the proxy service -->
<cxf:cxfEndpoint
id="myServiceProxy"
address="http://localhost:9003/cxf/myService"
serviceClass="foo.bar.iface.MyServiceInterface" />
<!-- my real existing cxf soap service -->
<cxf:cxfEndpoint
id="myService"
address="http://foo.bar/services/myService"
wsdlURL="http://foo.bar/services/myService?wsdl"
serviceClass="foo.bar.iface.MyServiceInterface"
serviceName="s:MyService"
endpointName="s:MyServiceEndpoint"
xmlns:s="http://foo.bar/iface/" />
<!-- route -->
<camel:camelContext>
<camel:route>
<camel:from
uri="cxf:bean:myServiceProxy" />
<camel:to
uri="cxf:bean:myService" />
</camel:route>
</camel:camelContext>
</beans>
Trying to start the bundle in FUSE leads to this exception
karaf#root> Exception in thread "SpringOsgiExtenderThread-22" org.apache.camel.RuntimeCamelException: java.lang.IllegalStateException: Endpoint address should be a relative URI wrt to the servlet address (use '/xxx' for example)
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1126)
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:103)
at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:231)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
I do not know what's wrong. I doubt that my Endpoint address is wrong and I do not know what my servlet address is (there is no cxf:cxfEndoint servelt address attribute).
Any help to lead me in the right direction to solve this problem would be appreciated.
Thanks
Klaus
I finally found out what's wrong.
Instead
<!-- the proxy service -->
<cxf:cxfEndpoint
id="myServiceProxy"
address="http://localhost:9003/cxf/myService"
serviceClass="foo.bar.iface.MyServiceInterface" />
it has to be
<!-- the proxy service -->
<cxf:cxfEndpoint
id="myServiceProxy"
address="/myService"
serviceClass="foo.bar.iface.MyServiceInterface" />
As the first approach worked well running the camel project outside FUSE (in this case a the http server will be started to provide the service) it has to be a relative address inside FUSE.
Inside FUSE the embedded HTTP server which runs on (localhost:8181) will be used and the service url will be extended to http://localhost:8181/cxf/myService.

From Netbeans Dev to Tomcat Production: DB Connection Not Found

I developed a Java web application in Netbeans 6.5 using a MySQL database and Hibernate. Both the development database server and development application server (Tomcat 6) reside on my development machine. Everything works; the application pulls data from the database correctly.
Now, I'm ready to move it to the production server. Again, the DB server and app server are on the same machine. I deploy the WAR file and try to access the application; I can access the static pages but the Servlets that use the database error out with the exception:
org.hibernate.exception.JDBCConnectionException: Cannot open connection
I'm pretty sure the problem relates to Tomcat not knowing about the data source. It seems as if Netbeans handles this for me. I've read that I might need to add a RESOURCE entry so I took some advice from this site which gave me a context.xml of:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/EmployeeDirectory">
<Resource
name="jdbc/employeedirectory" auth="Container"
type="javax.sql.DataSource" username="EmployeeDir"
password="EmployeeDirectory" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/EmployeeDirectory?autoReconnect=true"
maxActive="15" maxIdle="7"
validationQuery="Select 1" />
</Context>
a web.xml of:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Omit Servlet Info -->
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/employeedirectory</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
and a hibernate.cfg.xml of:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/employeedirectory</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Omit other Mappings -->
<mapping class="EmployeeDirectory.data.PhoneNumber" resource="EmployeeDirectory/data/PhoneNumber.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Now, I get a org.hibernate.HibernateException: Could not find datasource error.
Am I on the right path for moving from development to production? What am I missing?
I think you are on the right track. I would first set up the datasource and verify it out side of hibernate. Here is a good article on that: http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.htm and some examples here: http://www.mbaworld.com/docs/jndi-datasource-examples-howto.html
Then, I would configure hibernate to use the datsource. From looking at your hibernate.cfg.xml file I think you should try changing hibernate.connection.datasource to jdbc/employeedirectory
the jndi datasource should be defined in /tomcat/server.xml see Tomcat JNDI Datasource how-to and not in webapp/context.xml
Tomcat 6 requires that you add the resource tag to the context.xml, not the server.xml. You could in Tomcat 5.x. I have it working fine in a separate install of Tomcat, but I'm still trying to use connection pooling inside NB 6.5.
That same Apache site has a link to the Tomcat 6 version of JNDI and it tells you to add the resource tag to the context.xml.

Resources