Remote EJB3 access from Spring - spring

I have 2 applications - one EAR containing EJB3.0 and other its Spring client. Both deployed on same Websphere app server 7 instance i.e. same JVM.
Here are couple of client parts:
applicationContext.xml:
<bean id="ruleService" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
<property name="jndiName" value="com.ecrd.ruleservice.Customer_Management_Service_JavaBusiness"/>
<property name="businessInterface" value="com.ecrd.ruleservice.Customer_Management_Service_JavaBusiness"/>
<property name="jndiEnvironment">
<props>
<prop key="java.naming.factory.initial">com.ibm.websphere.naming.WsnInitialContextFactory</prop>
<prop key="java.naming.provider.url">corbaloc:iiop:localhost:2809</prop>
</props>
</property>
</bean>
Client code snippet:
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
Customer_Management_Service_JavaBusiness ruleService
= (Customer_Management_Service_JavaBusiness)ctx.getBean("ruleService");
This works fine. EJB access deployed in other application in same container, works.
But it does not work if I move that client to other machine in same network and just change provider URL and give remote server IP instead of localhost. JNDI lookup problem occurs
Exact Error:
Error 500: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ruleService' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Context: CFSDDVM2399Node01Cell/nodes/CFSDDVM2399Node01/servers/server1, name: com.ecrd.ruleservice.Customer_Management_Service_JavaBusiness: First component in name com.ecrd.ruleservice.Customer_Management_Service_JavaBusiness not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
I can't figure out what changes (and where) are required to connect to EJB hosted in different server JVM. Any help or suggestion are welcome.

Answering myself. Error is resolved.
I work on virtual machine. All developer images were copied from a particular VM and that
brought over WAS configs (hostname, cell, node etc) with it. Remote access
worked after fixing all occurances of hostnames in serverindex.xml of the server
hosting EJB.

Related

Tibco EMS with Tomcat configuration

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")?

Should I change value of mongo bean when deploying in production server?

So, I am deploying my spring web app in tomcat server in production environment. I have my production server ip address. Should I replace the value of mongo bean from localhost to my ipaddress, in order to access the db?
<!-- Factory bean that creates the Mongo instance -->
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
<property name="host" value="localhost" />
</bean>
What else should I change, in order to make my web app work with mongodb in production environment?
You need to change all the relevant details in wht mongo bean to point to your production database. If you are hosting it externally (i.e. not on localhost) then you need to point it to URL and potentially port as well to ensure you have connectivity.
Don't forget login details as well, i've made that mistake a lot of times.

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>

Tomcat/Spring no longer sending emails to SMTP server using authentication

I've got a strange problem with either tomcat or spring. I put up a major revision to my site and emails are no longer being delivered. I use authsmtp, which requires authentication (so they can properly account for my using of their services). No problem, I have this config in spring:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="mail.authsmtp.com"/>
<property name="username" value="my_authsmtp_username"/>
<property name="password" value="my_authsmtp_password"/>
</bean>
works great normally. However, now I get this error:
Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 513 5.0.0 Your email system must authenticate before sending mail.
My log4j emails continue to work fine though. A test telnet to port 25 of mail.authsmtp.com worked good with a sample SMTP conversation as well. I did a diff of that mailSender config above with the previous version of the site and there are no differences (was thinking maybe I had a character off in the password). What could be the problem?
The only thing I can think of is that I initially started the server without the username/password elements above (was a bug in our deployment mechanism). So initially actually this made complete sense. Since then I've corrected it and added the username/password elements, but the problem persists. I'm thinking maybe the old config is cached somewhere? Would tomcat cache this anywhere? I've deleted the work and temp directories to no avail. Though I've actually changed the host to abcd1234authsmtp.com and it appropriately failed with this error:
Mail server connection failed; nested exception is javax.mail.MessagingException: Unknown SMTP host: mail.abcd1234authsmtp.com;
nested exception is:
java.net.UnknownHostException: mail.abcd1234authsmtp.com
So I know I'm working with the correct config and tomcat/spring sees the latest version, for some reason Spring just no longer authenticates... I'm using the same version of Spring (v3.0.2) as before as well. Any ideas?
Try adding
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">false</prop>
</props>
</property>
`

Resources