Kei
Jun 30th, 2005, 04:52 AM
I'm a newbie with both axis and spring and is trying to modify from jpetstore to have a bean exposed as web service, but failed.
I created a bean with:
package logicBean;
...
public interface UserService {
User auth(User u);
User updatePwd(User u, String newPwd);
Boolean isActive(String id);
}
package logicBean.impl;
import ...
import vo.system.User;
import dao.UserDao;
public class UserTarget implements Serializable, UserService {
UserDao userDao;
public UserTarget() {
super();
}
public UserDao getUserDao() {
return userDao;
}
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
public User auth(User u) {...}
...
}
And define the bean in application-Context.xml
<bean id="userDaoTarget" class="dao.impl.UserDaoTarget">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<bean id="userDao" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager"><ref local="transactionManager"/></property>
<property name="target"><ref local="userDaoTarget"/></property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="store*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="userTarget" class="logicBean.impl.UserTarget">
<property name="userDao"><ref bean="userDao"/></property>
</bean>
I believe the bean is working as I can access the database as expected in unit test.
Then I tried to expose the bean as web service.
the web.xml is modified:
<listener>
<listener-class>org.apache.axis.transport.http.AxisHTTPSessionList ener</listener-class>
</listener>
<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/axis/*</url-pattern>
</servlet-mapping>
An Endpoint is defined:
package logicBean.support;
import vo.system.User;
import org.springframework.remoting.jaxrpc.ServletEndpoin tSupport;
import logicBean.UserService;
public class UserServiceEndpoint extends ServletEndpointSupport implements UserService {
private UserService service;
public UserServiceEndpoint() {
super();
}
protected void onInit() {
this.service = (UserService) getWebApplicationContext().getBean("userTarget");
}
public UserService getService() {
return service;
}
public void setService(UserService service) {
this.service = service;
}
public User auth(User u) {
return service.auth(u);
}
...
}
the server-config.wsdd is added with:
<service name="UserService" provider="java:RPC">
<parameter name="className" value="logicBean.support.UserServiceEndpoint"/>
<parameter name="allowMethods" value="*"/>
<beanMapping qname="inventory:User" xmlns:inventory="urn:inventory" languageSpecificType="java:vo.system.User"/>
</service>
a clientContext.xml is created for the test case:
<beans>
<bean id="userWebService" class="org.springframework.remoting.jaxrpc.JaxRpcPortProx yFactoryBean">
<property name="serviceFactoryClass">
<value>org.apache.axis.client.ServiceFactory</value>
</property>
<property name="wsdlDocumentUrl">
<value>http://localhost:8080/inventory/axis/UserService?wsdl</value>
</property>
<property name="namespaceUri">
<value>http://localhost:8080/inventory/axis/UserService</value>
</property>
<property name="serviceName">
<value>UserServiceEndpointService</value>
</property>
<property name="serviceInterface">
<value>logicBean.UserService</value>
</property>
<property name="portName">
<value>UserServiceEndpoint</value>
</property>
<property name="servicePostProcessors">
<list>
<bean class="test.client.BeanMappingServicePostProcessor"/>
</list>
</property>
</bean>
</beans>
The test case is:
public class UserWsTest {
private final ListableBeanFactory beanFactory;
public UserWsTest(ListableBeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
public void invokeService(int nrOfCalls) {
StopWatch stopWatch = new StopWatch(nrOfCalls + " UserService call(s)");
Map userServices = this.beanFactory.getBeansOfType(UserService.class) ;
for (Iterator it = userServices.keySet().iterator(); it.hasNext();) {
String beanName = (String) it.next();
UserService userService = (UserService) userServices.get(beanName);
System.out.println("Calling UserService '" + beanName + "' ");
stopWatch.start(beanName);
User input = new User();
input.setId("kei");
input.setPwd("888");
User dbu = userService.auth(input);
stopWatch.stop();
System.out.println("got:" + dbu.getName());
}
System.out.println(stopWatch.prettyPrint());
}
public static void main(String[] args) {
try {
ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext("bin/test/client/clientContext.xml");
UserWsTest client = new UserWsTest(beanFactory);
client.invokeService(1);
} catch (Exception e) {
System.err.println(e.toString());
e.printStackTrace();
}
}
}
But when I run the test case, it always show:
[java] org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userWebService' defined in file [D:\mySrc\inventory.src\bin\test\client\clientCont ext.xml]: Initialization of bean failed; nested exception is javax.xml.rpc.ServiceException: Error processing WSDL document:
[java] java.io.IOException: Type {http://logicBean}UserService is referenced but not defined.
[java] org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userWebService' defined in file [D:\mySrc\inventory.src\bin\test\client\clientCont ext.xml]: Initialization of bean failed; nested exception is javax.xml.rpc.ServiceException: Error processing WSDL document:
[java] java.io.IOException: Type {http://logicBean}UserService is referenced but not defined.
[java] javax.xml.rpc.ServiceException: Error processing WSDL document:
[java] java.io.IOException: Type {http://logicBean}UserService is referenced but not defined.
[java] at org.apache.axis.client.Service.initService(Service .java:249)
[java] at org.apache.axis.client.Service.<init>(Service.java:164)
[java] at org.apache.axis.client.ServiceFactory.createServic e(ServiceFactory.java:198)
[java] at org.springframework.remoting.jaxrpc.LocalJaxRpcSer viceFactory.createJaxRpcService(LocalJaxRpcService Factory.java:181)
[java] at org.springframework.remoting.jaxrpc.JaxRpcPortClie ntInterceptor.prepare(JaxRpcPortClientInterceptor. java:290)
[java] at org.springframework.remoting.jaxrpc.JaxRpcPortClie ntInterceptor.afterPropertiesSet(JaxRpcPortClientI nterceptor.java:268)
[java] at org.springframework.remoting.jaxrpc.JaxRpcPortProx yFactoryBean.afterPropertiesSet(JaxRpcPortProxyFac toryBean.java:55)
[java] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:937)
[java] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:334)
[java] at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:222)
[java] at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:146)
[java] at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:271)
[java] at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:310)
[java] at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationContext.java:82)
[java] at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationContext.java:67)
[java] at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationContext.java:58)
[java] at test.client.UserWsTest.main(UserWsTest.java:82)
I've no idea with the http://logicBean. It appears inside the auto-generated wsdl as:
...
<wsdl:types>
<schema targetNamespace="urn:inventory">
<import namespace="http://logicBean"/>
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
...
Any clue?
I created a bean with:
package logicBean;
...
public interface UserService {
User auth(User u);
User updatePwd(User u, String newPwd);
Boolean isActive(String id);
}
package logicBean.impl;
import ...
import vo.system.User;
import dao.UserDao;
public class UserTarget implements Serializable, UserService {
UserDao userDao;
public UserTarget() {
super();
}
public UserDao getUserDao() {
return userDao;
}
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
public User auth(User u) {...}
...
}
And define the bean in application-Context.xml
<bean id="userDaoTarget" class="dao.impl.UserDaoTarget">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<bean id="userDao" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager"><ref local="transactionManager"/></property>
<property name="target"><ref local="userDaoTarget"/></property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="store*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="userTarget" class="logicBean.impl.UserTarget">
<property name="userDao"><ref bean="userDao"/></property>
</bean>
I believe the bean is working as I can access the database as expected in unit test.
Then I tried to expose the bean as web service.
the web.xml is modified:
<listener>
<listener-class>org.apache.axis.transport.http.AxisHTTPSessionList ener</listener-class>
</listener>
<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/axis/*</url-pattern>
</servlet-mapping>
An Endpoint is defined:
package logicBean.support;
import vo.system.User;
import org.springframework.remoting.jaxrpc.ServletEndpoin tSupport;
import logicBean.UserService;
public class UserServiceEndpoint extends ServletEndpointSupport implements UserService {
private UserService service;
public UserServiceEndpoint() {
super();
}
protected void onInit() {
this.service = (UserService) getWebApplicationContext().getBean("userTarget");
}
public UserService getService() {
return service;
}
public void setService(UserService service) {
this.service = service;
}
public User auth(User u) {
return service.auth(u);
}
...
}
the server-config.wsdd is added with:
<service name="UserService" provider="java:RPC">
<parameter name="className" value="logicBean.support.UserServiceEndpoint"/>
<parameter name="allowMethods" value="*"/>
<beanMapping qname="inventory:User" xmlns:inventory="urn:inventory" languageSpecificType="java:vo.system.User"/>
</service>
a clientContext.xml is created for the test case:
<beans>
<bean id="userWebService" class="org.springframework.remoting.jaxrpc.JaxRpcPortProx yFactoryBean">
<property name="serviceFactoryClass">
<value>org.apache.axis.client.ServiceFactory</value>
</property>
<property name="wsdlDocumentUrl">
<value>http://localhost:8080/inventory/axis/UserService?wsdl</value>
</property>
<property name="namespaceUri">
<value>http://localhost:8080/inventory/axis/UserService</value>
</property>
<property name="serviceName">
<value>UserServiceEndpointService</value>
</property>
<property name="serviceInterface">
<value>logicBean.UserService</value>
</property>
<property name="portName">
<value>UserServiceEndpoint</value>
</property>
<property name="servicePostProcessors">
<list>
<bean class="test.client.BeanMappingServicePostProcessor"/>
</list>
</property>
</bean>
</beans>
The test case is:
public class UserWsTest {
private final ListableBeanFactory beanFactory;
public UserWsTest(ListableBeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
public void invokeService(int nrOfCalls) {
StopWatch stopWatch = new StopWatch(nrOfCalls + " UserService call(s)");
Map userServices = this.beanFactory.getBeansOfType(UserService.class) ;
for (Iterator it = userServices.keySet().iterator(); it.hasNext();) {
String beanName = (String) it.next();
UserService userService = (UserService) userServices.get(beanName);
System.out.println("Calling UserService '" + beanName + "' ");
stopWatch.start(beanName);
User input = new User();
input.setId("kei");
input.setPwd("888");
User dbu = userService.auth(input);
stopWatch.stop();
System.out.println("got:" + dbu.getName());
}
System.out.println(stopWatch.prettyPrint());
}
public static void main(String[] args) {
try {
ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext("bin/test/client/clientContext.xml");
UserWsTest client = new UserWsTest(beanFactory);
client.invokeService(1);
} catch (Exception e) {
System.err.println(e.toString());
e.printStackTrace();
}
}
}
But when I run the test case, it always show:
[java] org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userWebService' defined in file [D:\mySrc\inventory.src\bin\test\client\clientCont ext.xml]: Initialization of bean failed; nested exception is javax.xml.rpc.ServiceException: Error processing WSDL document:
[java] java.io.IOException: Type {http://logicBean}UserService is referenced but not defined.
[java] org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'userWebService' defined in file [D:\mySrc\inventory.src\bin\test\client\clientCont ext.xml]: Initialization of bean failed; nested exception is javax.xml.rpc.ServiceException: Error processing WSDL document:
[java] java.io.IOException: Type {http://logicBean}UserService is referenced but not defined.
[java] javax.xml.rpc.ServiceException: Error processing WSDL document:
[java] java.io.IOException: Type {http://logicBean}UserService is referenced but not defined.
[java] at org.apache.axis.client.Service.initService(Service .java:249)
[java] at org.apache.axis.client.Service.<init>(Service.java:164)
[java] at org.apache.axis.client.ServiceFactory.createServic e(ServiceFactory.java:198)
[java] at org.springframework.remoting.jaxrpc.LocalJaxRpcSer viceFactory.createJaxRpcService(LocalJaxRpcService Factory.java:181)
[java] at org.springframework.remoting.jaxrpc.JaxRpcPortClie ntInterceptor.prepare(JaxRpcPortClientInterceptor. java:290)
[java] at org.springframework.remoting.jaxrpc.JaxRpcPortClie ntInterceptor.afterPropertiesSet(JaxRpcPortClientI nterceptor.java:268)
[java] at org.springframework.remoting.jaxrpc.JaxRpcPortProx yFactoryBean.afterPropertiesSet(JaxRpcPortProxyFac toryBean.java:55)
[java] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:937)
[java] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:334)
[java] at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:222)
[java] at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:146)
[java] at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:271)
[java] at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:310)
[java] at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationContext.java:82)
[java] at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationContext.java:67)
[java] at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationContext.java:58)
[java] at test.client.UserWsTest.main(UserWsTest.java:82)
I've no idea with the http://logicBean. It appears inside the auto-generated wsdl as:
...
<wsdl:types>
<schema targetNamespace="urn:inventory">
<import namespace="http://logicBean"/>
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
...
Any clue?