I actually have two app configs - server one and client one. Here they are:
server-config.xml
Code:
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- ============= -->
<!-- Service Beans -->
<!-- ============= -->
<bean id="oaService"
class="com.trilogy.orderagent.OrderAgentServiceImpl">
<property name="entityManagerFactory">
<ref bean="entityManagerFactory" />
</property>
</bean>
<!-- ================ -->
<!-- Remote Exporters -->
<!-- ================ -->
<bean name="hessianOaService" class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service">
<ref bean="oaService"/>
</property>
<property name="serviceInterface">
<value>com.package1.IOAService</value>
</property>
</bean>
<!-- ================ -->
<!-- URL Mapping -->
<!-- ================ -->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/oa.service">hessianOaService</prop>
</props>
</property>
</bean>
<!-- ========================= -->
<!-- Spring Bridge with JPA -->
<!-- ========================= -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
<property name="database" value="SQL_SERVER"/>
</bean>
</property>
</bean>
<!-- ====================================================== -->
<!-- Datasource Declaration -->
<!-- ====================================================== -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="net.sourceforge.jtds.jdbc.Driver" />
<property name="url"
value="jdbc:jtds:sqlserver://localhost/NewDB" />
<property name="username" value="sa" />
<property name="password" value="sa" />
</bean>
<!-- ========================= -->
<!-- Transaction Manager -->
<!-- ========================= -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
client-config.xml
Code:
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="oaService"
class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl">
<value>http://localhost:8080/oaService/oa.service</value>
</property>
<property name="serviceInterface">
<value>com.package1.IOAService</value>
</property>
</bean>
<!-- ====================================================== -->
<!-- Datasource Declaration -->
<!-- ====================================================== -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="net.sourceforge.jtds.jdbc.Driver" />
<property name="url"
value="jdbc:jtds:sqlserver://localhost/NewDB" />
<property name="username" value="sa" />
<property name="password" value="sa" />
</bean>
<!-- ========================= -->
<!-- Spring Bridge with JPA -->
<!-- ========================= -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
<property name="database" value="SQL_SERVER"/>
</bean>
</property>
</bean>
<!-- ========================= -->
<!-- Transaction Manager -->
<!-- ========================= -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
The test code is quite trivial:
Code:
public class MiscTests extends AbstractJpaTests
{
private IOAService oaService;
public void setOaService(IOAService oaService)
{
this.oaService = oaService;
}
protected String[] getConfigLocations()
{
return new String[] {"classpath:/client-test.xml"};
}
protected void onSetUpInTransaction() throws Exception
{
//prepare test database structure
jdbcTemplate.execute(.....);
}
public void testGetUser() throws Exception
{
String username = "John_Doe_login";
String password = "password_test";
Dosuser user = oaService.getUser(username, password);
assertNotNull(user);
assertEquals(1000, user.getUserKey());
assertEquals(4, user.getDealers().size()); //this user has 4 dealers
}
As you can see, my client config file is set up for obtaining a reference to IOAService via Spring Remote mechanism (Hessian in this case) and Spring is also responsible for injecting this reference into my unit test class MiscTests. This works just fine. The server-side code berofe running the test suite is properly deployed into a servlet container (Tomcat), which is up and running.
What is NOT working (for now) is my unit test method testGetUser() which freezes somewhere inside oaService.getUser(username, password) (or after) I guess that the database IS being hit, because in the Tomcat console I can see SQL for the operation:
Code:
Hibernate:
select
alias0_.UserName as UserName1_,
alias0_.UserKey as UserKey1_
from
NewDB.dbo.Alias alias0_
where
alias0_.UserName=?
Why the application flow freezes after that is a mystery for me. Hope this information will help someone to point me to what I'm doing wrong here.