Tibco EMS with Tomcat configuration - spring

I searched for and answer before posting, but didn't find a solution. If I missed it please link me to it.
Here is my problem. I'm trying to use jndi to connect my tibco server.
Right now I have my resource tag setup inside my tomcat server.xml file:
<Resource name="tibcoConnection"
auth="Container"
type="com.tibco.tibjms.naming.TibjmsInitialContextFactory"
factory="com.tibco.tibjms.naming.TibjmsObjectFactory"
severUrl=<tibcourl>
userName=xxxxxxx
password=xxxxxxx />
For the factory I originally had com.tibco.tibjms.TibjmConnectionFactory but tomcat threw an error cast it to ObjectFactory. So I changed it.
I have my ResourceLink tag in context.xml pointing to the tibcoConnectoin name and type com.tibco.tibjms.naming.TibjmsInitialContextFactory.
My Spring bean is <jee:jndi-lookup id="tibco" jndi-name="tibcoConnection"/>
I'm using the connection for:
<bean class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory" ref="tibco"/>
</bean>
I my logs I'm getting a javax.naming.NameNotFoundException: Name [tibco] is not bound in the Context. Unable to find [tibco]
I'm lost since there isn't much documentation out there for tomcat and tibco that I could find. If anyone has had any luck with configuring tomcat with tibco and spring, please help.

Is it possible that the issue might be that you define your resource name as "tibcoConnectoin" ("o" before "i"), but you refer to it in your jndi-lookup as "tibcoConnection" ("o" after "i")?

Related

Apache Camel + Spring Boot + IBM MQ

I want to use Apache Camel to get a message on IBM MQ in a spring boot project.
I use sprin boot annotation based.
I dont find any fully example: pom.xml, receiver, configuration class, ...
Is there anyone to help me? Any link, documentation, ...?
Thanks a lot of
Take a look at a new Spring Boot Starter for MQ that may help here. The README shows how to modify the JMS Getting Started sample here to use IBM MQ instead of ActiveMQ. And the MQ jars - including this starter - are all on Maven Central for easy access.
You could search for an example that uses Spring Boot, Camel and ActiveMQ to get a first impression. Since you use Camel most differences between IBM MQ and ActiveMQ should be hidden.
However, you have to use the standard JMS component instead of the dedicated ActiveMQ component of Camel.
In your Application class, you will need create a bean for a IBM component, I just did it for an application in spring xml, like this:
<bean id="cf" class="com.ibm.mq.jms.MQConnectionFactory">
<property name="transportType" value="1" />
<property name="hostName" value="localhost" />
<property name="port" value="1414" />
<property name="queueManager" value="QMGRSCORE" />
<property name="channel" value="EXTAPP.SRVCONN" />
</bean>
But once I did a bean connection for a MongDB in spring boot, may you can do something like this:
#Bean(name = "myDb")
public MongoClient myDb() {
return new MongoClient();
}
But putting the IBM values inside this bean.

Spring application should start even database is not available at startup

I have an old spring application which uses jee:jndi-lookup for datasource. This application running on Tomcat 8.
<jee:jndi-lookup id="datasource" jndi-name="java:/comp/env/jdbc/Tomcat8Database" destroy-method="close" expected-type="javax.sql.DataSource" lookup-on-startup="false"/>
The database may be sometime down at startup of the application, but as I also tried to lazy-init spring beans it did not helped as what it seems like that JNDI lookup in spring happened on Startup always or its not in spring controls as Server provide Pooling over connections.
Any idea or code example will be helpful.
According to spring javadoc, For a lazy lookup, a proxy interface needs to be specified.
Proxy interface specify the proxy interface to use for the JNDI object.
Typically used in conjunction with "lookupOnStartup"=false and/or "cache"=false. Needs to be specified because the actual JNDI object type is not known in advance in case of a lazy lookup.
Try:
<jee:jndi-lookup id="datasource" jndi-name="java:/comp/env/jdbc/Tomcat8Database" destroy-method="close" expected-type="javax.sql.DataSource" lookup-on-startup="false" proxy-interface="javax.sql.DataSource"/>

Can't seem to get a JNDI JDBC resource working in Liferay

No joy in the Liferay forum on this issue and the clock is ticking on this project. This may be caused by my lack of knowledge of Spring.
I have a JNDI global resource defined in server.xml and a resource link in context.xml in my Tomcat 7 /conf folder. I KNOW the JNDI resource is being loaded because I see the validation query being run as the server starts up. So far so good.
I have a portlet that just provides services to other portlets. In that portlet I have a hibernate.cfg.xml which has a session-factory that also points to the JDBC resource (don't know if this is needed or not). I also have an ext-spring.xml file in the services portlet that has the following:
<bean id="liferayHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration" >
<property name="dataSource" ref="MyJDBCResource" />
</bean>
<bean id="MyJDBCResource" class="org.springframework.jndi.JndiObjectFactoryBean" >
<property name="jndiName" value="java:comp/env/jdbc/MyJDBCResource" />
</bean>
Adding the above in ext-spring.xml fixed an issue with a bean error on that services portlet upon deployment. In that service builder built portlet, a services jar was created and I put that service jar in the Tomcat_Home/lib/ext folder so that I could use the services provided by the portlet in my portlet. So far so good. But, when I invoke the portlet method which calls the services provided by the other portlet with the JNDI references, I get a "user lacks privilege or object not found" error. It is definitely object not found. When the query is run I see absolutely NO activity on the JDBC connection specified by the JNDI resource entry and in drilling down on the connection properties I only see the HSQLDB driver in use. It should be using the MSSQL driver specified in my global resource JNDI entry as far as I understand it.
SO WHAT AM I DOING WRONG? Do I need to add some configuration entries in the portlet that invokes the services?
This seems so simple. In reading the many posts that give instructions on using JNDI/JDBC resources I seem to have followed them correctly. Is there some trick to using JNDI/JDBC resources in LR 6.1.1 and Tomcat 7 that I have missed?
Thanks (and really hoping for some answers!).
First, you could try rewrite JNDI resource reference like this:
<bean id="MyJDBCResource" class="org.springframework.jndi.JndiObjectFactoryBean" >
<property name="jndiName" value="jdbc/MyJDBCResource" />
</bean>
also, you could try different approach on JNDI resource lookup in Spring:
<jee:jndi-lookup id="MyJDBCResource" jndi-name="jdbc/MyJDBCResource" expected-type="javax.sql.DataSource" />
Not sure about first approch, but second will definitively fail early in case no JNDI resource could be found.
Hope this helps.

Spring Error: org.springframework.beans.factory.BeanCreationException

I have a web application which I am exporting as EAR and trying to deploy on Websphere 6.1 application server.
The deployment goes fine. Even, the index page loads fine which is a login screen.
However, on entering credentials and hitting enter, the next page does not load and HTTP 500 Internal Server Error is thrown.
The next page which gets loaded is a JSP having a country drop down, whose values gets fetched from database via hibernate.
I have Datasource created in Websphere with all details and even test connection succeeds.
However, I get the below error on checking the server System.out logs:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds':
Invocation of init method failed; nested exception is javax.naming.NameNotFoundException:
Context: uschwasvmdev04Cell01/clusters/URMDUS, name: jdbc/mydbXA: First component in name
mydbXA not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound:
IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
The description of NameNotFoundException says:
"This exception is thrown when a component of the name cannot be resolved because it is not bound. "
JNDI Lookup in my services.xml also seems fine:
<jee:jndi-lookup id="ds" jndi-name="jdbc/mydbXA" resource-ref="true" />
What am I missing here ?
Thanks for reading!
You are using resource-ref="true". Have you created the according resource-reference in your web.xml and did you map the DataSource to the application?
If you set it to false you can do a global lookup. Otherwise you have to configure it.
It's funny, but I've done the opposite: I created the resource-reference but I forget to tell Spring to use it.
Just in case, in the namespace it's done as you can see above: resource-ref="true"
If you're configuring your beans manually:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/database" />
<property name="resourceRef" value="true" /><!-- It's false by default -->
</bean>

spring not able to find JNDI data source

I am developing a spring web application . A JAR file which I use in my application , is looking for DataSource using JNDI. I configured the element in my tomcat's server.xml. The configuration is as below ,
<GlobalNamingResources>
<Resource name="jdbc/abcd"
auth="Container"
type="javax.sql.DataSource"
maxActive="70"
maxWait="10000"
username="xxxx" password="yyyy"
validationQuery="SELECT 1 from dual"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#xx.xxx.xx.xx:xxxx:zzzz"
testOnBorrow="false"
testOnReturn="false"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="120000"
minEvictableIdleTimeMillis="3600000"
/>
</GlobalNamingResources>
The Resource name configured above , "jdbc/abcd" is the same which the JAR is looking for,
But its not able to find this configured data source . Does anyone know what could be the reason ?
Am getting the below exception ,
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
You need to define a ResourceLink in the web application context that makes the global resource visible to the web application.
<ResourceLink
name="nameThatIsVisibleToTheWebApplication"
global="theGlobalName"
...
You need to do more than just configure Spring.
I'd recommend reading Tomcat JNDI documentation and this.

Resources