PDA

View Full Version : trouble with exposing bean as web service with axis



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 &#123;

private UserService service;

public UserServiceEndpoint&#40;&#41; &#123;
super&#40;&#41;;
&#125;

protected void onInit&#40;&#41; &#123;
this.service = &#40;UserService&#41; getWebApplicationContext&#40;&#41;.getBean&#40;"userTarget"&#41;;
&#125;

public UserService getService&#40;&#41; &#123;
return service;
&#125;
public void setService&#40;UserService service&#41; &#123;
this.service = service;
&#125;

public User auth&#40;User u&#41; &#123;
return service.auth&#40;u&#41;;
&#125;
...
&#125;


the server-config.wsdd is added with:


<service name="UserService" provider="java&#58;RPC">
<parameter name="className" value="logicBean.support.UserServiceEndpoint"/>
<parameter name="allowMethods" value="*"/>
<beanMapping qname="inventory&#58;User" xmlns&#58;inventory="urn&#58;inventory" languageSpecificType="java&#58;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&#58;//localhost&#58;8080/inventory/axis/UserService?wsdl</value>
</property>
<property name="namespaceUri">
<value>http&#58;//localhost&#58;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 &#123;

private final ListableBeanFactory beanFactory;

public UserWsTest&#40;ListableBeanFactory beanFactory&#41; &#123;
this.beanFactory = beanFactory;
&#125;

public void invokeService&#40;int nrOfCalls&#41; &#123;
StopWatch stopWatch = new StopWatch&#40;nrOfCalls + " UserService call&#40;s&#41;"&#41;;
Map userServices = this.beanFactory.getBeansOfType&#40;UserService.class&#41; ;
for &#40;Iterator it = userServices.keySet&#40;&#41;.iterator&#40;&#41;; it.hasNext&#40;&#41;;&#41; &#123;
String beanName = &#40;String&#41; it.next&#40;&#41;;
UserService userService = &#40;UserService&#41; userServices.get&#40;beanName&#41;;
System.out.println&#40;"Calling UserService '" + beanName + "' "&#41;;
stopWatch.start&#40;beanName&#41;;

User input = new User&#40;&#41;;
input.setId&#40;"kei"&#41;;
input.setPwd&#40;"888"&#41;;
User dbu = userService.auth&#40;input&#41;;

stopWatch.stop&#40;&#41;;
System.out.println&#40;"got&#58;" + dbu.getName&#40;&#41;&#41;;
&#125;
System.out.println&#40;stopWatch.prettyPrint&#40;&#41;&#41;;
&#125;

public static void main&#40;String&#91;&#93; args&#41; &#123;
try &#123;
ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext&#40;"bin/test/client/clientContext.xml"&#41;;
UserWsTest client = new UserWsTest&#40;beanFactory&#41;;
client.invokeService&#40;1&#41;;
&#125; catch &#40;Exception e&#41; &#123;
System.err.println&#40;e.toString&#40;&#41;&#41;;
e.printStackTrace&#40;&#41;;
&#125;
&#125;
&#125;



But when I run the test case, it always show:


&#91;java&#93; org.springframework.beans.factory.BeanCreationExce ption&#58; Error creating bean with name 'userWebService' defined in file &#91;D&#58;\mySrc\inventory.src\bin\test\client\clientCont ext.xml&#93;&#58; Initialization of bean failed; nested exception is javax.xml.rpc.ServiceException&#58; Error processing WSDL document&#58;
&#91;java&#93; java.io.IOException&#58; Type &#123;http&#58;//logicBean&#125;UserService is referenced but not defined.
&#91;java&#93; org.springframework.beans.factory.BeanCreationExce ption&#58; Error creating bean with name 'userWebService' defined in file &#91;D&#58;\mySrc\inventory.src\bin\test\client\clientCont ext.xml&#93;&#58; Initialization of bean failed; nested exception is javax.xml.rpc.ServiceException&#58; Error processing WSDL document&#58;
&#91;java&#93; java.io.IOException&#58; Type &#123;http&#58;//logicBean&#125;UserService is referenced but not defined.
&#91;java&#93; javax.xml.rpc.ServiceException&#58; Error processing WSDL document&#58;
&#91;java&#93; java.io.IOException&#58; Type &#123;http&#58;//logicBean&#125;UserService is referenced but not defined.
&#91;java&#93; at org.apache.axis.client.Service.initService&#40;Service .java&#58;249&#41;
&#91;java&#93; at org.apache.axis.client.Service.<init>&#40;Service.java&#58;164&#41;
&#91;java&#93; at org.apache.axis.client.ServiceFactory.createServic e&#40;ServiceFactory.java&#58;198&#41;
&#91;java&#93; at org.springframework.remoting.jaxrpc.LocalJaxRpcSer viceFactory.createJaxRpcService&#40;LocalJaxRpcService Factory.java&#58;181&#41;
&#91;java&#93; at org.springframework.remoting.jaxrpc.JaxRpcPortClie ntInterceptor.prepare&#40;JaxRpcPortClientInterceptor. java&#58;290&#41;
&#91;java&#93; at org.springframework.remoting.jaxrpc.JaxRpcPortClie ntInterceptor.afterPropertiesSet&#40;JaxRpcPortClientI nterceptor.java&#58;268&#41;
&#91;java&#93; at org.springframework.remoting.jaxrpc.JaxRpcPortProx yFactoryBean.afterPropertiesSet&#40;JaxRpcPortProxyFac toryBean.java&#58;55&#41;
&#91;java&#93; at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods&#40;Abstr actAutowireCapableBeanFactory.java&#58;937&#41;
&#91;java&#93; at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean&#40;AbstractAuto wireCapableBeanFactory.java&#58;334&#41;
&#91;java&#93; at org.springframework.beans.factory.support.Abstract BeanFactory.getBean&#40;AbstractBeanFactory.java&#58;222&#41;
&#91;java&#93; at org.springframework.beans.factory.support.Abstract BeanFactory.getBean&#40;AbstractBeanFactory.java&#58;146&#41;
&#91;java&#93; at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons&#40;Defaul tListableBeanFactory.java&#58;271&#41;
&#91;java&#93; at org.springframework.context.support.AbstractApplic ationContext.refresh&#40;AbstractApplicationContext.ja va&#58;310&#41;
&#91;java&#93; at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;82&#41;
&#91;java&#93; at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;67&#41;
&#91;java&#93; at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;58&#41;
&#91;java&#93; at test.client.UserWsTest.main&#40;UserWsTest.java&#58;82&#41;


I've no idea with the http://logicBean. It appears inside the auto-generated wsdl as:


...
<wsdl&#58;types>
<schema targetNamespace="urn&#58;inventory">
<import namespace="http&#58;//logicBean"/>
<import namespace="http&#58;//schemas.xmlsoap.org/soap/encoding/"/>
...


Any clue?

dejanp
Jun 30th, 2005, 08:16 AM
Your wsdd looks wrong, there is no operation defined. How did you generate it?

Kei
Jul 1st, 2005, 10:02 PM
I modify the server-config.wsdd according to the jpetstore example:


<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http&#58;//xml.apache.org/axis/wsdd/" xmlns&#58;java="http&#58;//xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="sendMultiRefs" value="true"/>
<parameter name="disablePrettyXML" value="true"/>
<parameter name="adminPassword" value="admin"/>
<parameter name="attachments.Directory" value="c&#58;\tomcat\webapps\inventory\WEB-INF\attachments"/>
<parameter name="dotNetSoapEncFix" value="true"/>
<parameter name="enableNamespacePrefixOptimization" value="true"/>
<parameter name="sendXMLDeclaration" value="true"/>
<parameter name="sendXsiTypes" value="true"/>
<parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
<requestFlow>
<handler type="java&#58;org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="session"/>
</handler>
<handler type="java&#58;org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="request"/>
<parameter name="extension" value=".jwr"/>
</handler>
</requestFlow>
</globalConfiguration>
<handler name="LocalResponder" type="java&#58;org.apache.axis.transport.local.LocalResponde r"/>
<handler name="URLMapper" type="java&#58;org.apache.axis.handlers.http.URLMapper"/>
<handler name="Authenticate" type="java&#58;org.apache.axis.handlers.SimpleAuthentication Handler"/>
<service name="AdminService" provider="java&#58;MSG">
<parameter name="allowedMethods" value="AdminService"/>
<parameter name="enableRemoteAdmin" value="false"/>
<parameter name="className" value="org.apache.axis.utils.Admin"/>
<namespace>http&#58;//xml.apache.org/axis/wsdd/</namespace>
</service>
<service name="Version" provider="java&#58;RPC">
<parameter name="allowedMethods" value="getVersion"/>
<parameter name="className" value="org.apache.axis.Version"/>
</service>

<service name="UserService" provider="java&#58;RPC">
<parameter name="className" value="logicBean.support.UserServiceEndpoint"/>
<parameter name="allowMethods" value="*"/>
<beanMapping qname="inventory&#58;User" xmlns&#58;inventory="urn&#58;inventory" languageSpecificType="java&#58;vo.system.User"/>
</service>

<transport name="http">
<requestFlow>
<handler type="URLMapper"/>
<handler type="java&#58;org.apache.axis.handlers.http.HTTPAuthHandler"/>
</requestFlow>
<parameter name="qs&#58;list" value="org.apache.axis.transport.http.QSListHandler"/>
<parameter name="qs&#58;wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
<parameter name="qs.list" value="org.apache.axis.transport.http.QSListHandler"/>
<parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler"/>
<parameter name="qs&#58;method" value="org.apache.axis.transport.http.QSMethodHandler"/>
<parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
</transport>
<transport name="local">
<responseFlow>
<handler type="LocalResponder"/>
</responseFlow>
</transport>
</deployment>

and the resulting wsdl is :


http&#58;//localhost&#58;8080/inventory/axis/UserService?wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl&#58;definitions
targetNamespace="http&#58;//localhost&#58;8080/inventory/services/UserService"
xmlns&#58;apachesoap="http&#58;//xml.apache.org/xml-soap"
xmlns&#58;impl="http&#58;//localhost&#58;8080/inventory/services/UserService"
xmlns&#58;intf="http&#58;//localhost&#58;8080/inventory/services/UserService"
xmlns&#58;soapenc="http&#58;//schemas.xmlsoap.org/soap/encoding/"
xmlns&#58;tns1="http&#58;//localhost&#58;8080/inventory/axis/UserService"
xmlns&#58;tns2="urn&#58;inventory"
xmlns&#58;wsdl="http&#58;//schemas.xmlsoap.org/wsdl/"
xmlns&#58;wsdlsoap="http&#58;//schemas.xmlsoap.org/wsdl/soap/"
xmlns&#58;xsd="http&#58;//www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version&#58; 1.2
Built on May 03, 2005 &#40;02&#58;20&#58;24 EDT&#41;-->
<wsdl&#58;types>
<schema targetNamespace="urn&#58;inventory" xmlns="http&#58;//www.w3.org/2001/XMLSchema">
<import namespace="http&#58;//localhost&#58;8080/inventory/axis/UserService"/>
<import namespace="http&#58;//schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="User">
<sequence>
<element name="id" nillable="true" type="xsd&#58;string"/>
<element name="name" nillable="true" type="xsd&#58;string"/>
<element name="pwd" nillable="true" type="xsd&#58;string"/>
<element name="rolesCode" nillable="true" type="xsd&#58;int"/>
<element name="status" nillable="true" type="xsd&#58;string"/>
</sequence>
</complexType>
</schema>
</wsdl&#58;types>

<wsdl&#58;message name="getServiceRequest">

</wsdl&#58;message>

<wsdl&#58;message name="getServiceResponse">

<wsdl&#58;part name="getServiceReturn" type="tns1&#58;UserService"/>

</wsdl&#58;message>

<wsdl&#58;message name="updatePwdRequest">

<wsdl&#58;part name="in0" type="tns2&#58;User"/>

<wsdl&#58;part name="in1" type="xsd&#58;string"/>

</wsdl&#58;message>

<wsdl&#58;message name="authRequest">

<wsdl&#58;part name="in0" type="tns2&#58;User"/>

</wsdl&#58;message>

<wsdl&#58;message name="isActiveRequest">

<wsdl&#58;part name="in0" type="xsd&#58;string"/>

</wsdl&#58;message>

<wsdl&#58;message name="setServiceRequest">

<wsdl&#58;part name="in0" type="xsd&#58;anyType"/>

</wsdl&#58;message>

<wsdl&#58;message name="setServiceResponse">

</wsdl&#58;message>

<wsdl&#58;message name="isActiveResponse">

<wsdl&#58;part name="isActiveReturn" type="xsd&#58;boolean"/>

</wsdl&#58;message>

<wsdl&#58;message name="authResponse">

<wsdl&#58;part name="authReturn" type="tns2&#58;User"/>

</wsdl&#58;message>

<wsdl&#58;message name="updatePwdResponse">

<wsdl&#58;part name="updatePwdReturn" type="tns2&#58;User"/>

</wsdl&#58;message>

<wsdl&#58;portType name="UserServiceEndpoint">

<wsdl&#58;operation name="setService" parameterOrder="in0">

<wsdl&#58;input message="impl&#58;setServiceRequest" name="setServiceRequest"/>

<wsdl&#58;output message="impl&#58;setServiceResponse" name="setServiceResponse"/>

</wsdl&#58;operation>

<wsdl&#58;operation name="auth" parameterOrder="in0">

<wsdl&#58;input message="impl&#58;authRequest" name="authRequest"/>

<wsdl&#58;output message="impl&#58;authResponse" name="authResponse"/>

</wsdl&#58;operation>

<wsdl&#58;operation name="updatePwd" parameterOrder="in0 in1">

<wsdl&#58;input message="impl&#58;updatePwdRequest" name="updatePwdRequest"/>

<wsdl&#58;output message="impl&#58;updatePwdResponse" name="updatePwdResponse"/>

</wsdl&#58;operation>

<wsdl&#58;operation name="isActive" parameterOrder="in0">

<wsdl&#58;input message="impl&#58;isActiveRequest" name="isActiveRequest"/>

<wsdl&#58;output message="impl&#58;isActiveResponse" name="isActiveResponse"/>

</wsdl&#58;operation>

<wsdl&#58;operation name="getService">

<wsdl&#58;input message="impl&#58;getServiceRequest" name="getServiceRequest"/>

<wsdl&#58;output message="impl&#58;getServiceResponse" name="getServiceResponse"/>

</wsdl&#58;operation>

</wsdl&#58;portType>

<wsdl&#58;binding name="UserServiceSoapBinding" type="impl&#58;UserServiceEndpoint">

<wsdlsoap&#58;binding style="rpc" transport="http&#58;//schemas.xmlsoap.org/soap/http"/>

<wsdl&#58;operation name="setService">

<wsdlsoap&#58;operation soapAction=""/>

<wsdl&#58;input name="setServiceRequest">

<wsdlsoap&#58;body encodingStyle="http&#58;//schemas.xmlsoap.org/soap/encoding/" namespace="http&#58;//support.logicBean" use="encoded"/>

</wsdl&#58;input>

<wsdl&#58;output name="setServiceResponse">

<wsdlsoap&#58;body encodingStyle="http&#58;//schemas.xmlsoap.org/soap/encoding/" namespace="http&#58;//localhost&#58;8080/inventory/services/UserService" use="encoded"/>

</wsdl&#58;output>

</wsdl&#58;operation>

<wsdl&#58;operation name="auth">

<wsdlsoap&#58;operation soapAction=""/>

<wsdl&#58;input name="authRequest">

<wsdlsoap&#58;body encodingStyle="http&#58;//schemas.xmlsoap.org/soap/encoding/" namespace="http&#58;//support.logicBean" use="encoded"/>

</wsdl&#58;input>

<wsdl&#58;output name="authResponse">

<wsdlsoap&#58;body encodingStyle="http&#58;//schemas.xmlsoap.org/soap/encoding/" namespace="http&#58;//localhost&#58;8080/inventory/services/UserService" use="encoded"/>

</wsdl&#58;output>

</wsdl&#58;operation>

<wsdl&#58;operation name="updatePwd">

<wsdlsoap&#58;operation soapAction=""/>

<wsdl&#58;input name="updatePwdRequest">

<wsdlsoap&#58;body encodingStyle="http&#58;//schemas.xmlsoap.org/soap/encoding/" namespace="http&#58;//support.logicBean" use="encoded"/>

</wsdl&#58;input>

<wsdl&#58;output name="updatePwdResponse">

<wsdlsoap&#58;body encodingStyle="http&#58;//schemas.xmlsoap.org/soap/encoding/" namespace="http&#58;//localhost&#58;8080/inventory/services/UserService" use="encoded"/>

</wsdl&#58;output>

</wsdl&#58;operation>

<wsdl&#58;operation name="isActive">

<wsdlsoap&#58;operation soapAction=""/>

<wsdl&#58;input name="isActiveRequest">

<wsdlsoap&#58;body encodingStyle="http&#58;//schemas.xmlsoap.org/soap/encoding/" namespace="http&#58;//support.logicBean" use="encoded"/>

</wsdl&#58;input>

<wsdl&#58;output name="isActiveResponse">

<wsdlsoap&#58;body encodingStyle="http&#58;//schemas.xmlsoap.org/soap/encoding/" namespace="http&#58;//localhost&#58;8080/inventory/services/UserService" use="encoded"/>

</wsdl&#58;output>

</wsdl&#58;operation>

<wsdl&#58;operation name="getService">

<wsdlsoap&#58;operation soapAction=""/>

<wsdl&#58;input name="getServiceRequest">

<wsdlsoap&#58;body encodingStyle="http&#58;//schemas.xmlsoap.org/soap/encoding/" namespace="http&#58;//support.logicBean" use="encoded"/>

</wsdl&#58;input>

<wsdl&#58;output name="getServiceResponse">

<wsdlsoap&#58;body encodingStyle="http&#58;//schemas.xmlsoap.org/soap/encoding/" namespace="http&#58;//localhost&#58;8080/inventory/services/UserService" use="encoded"/>

</wsdl&#58;output>

</wsdl&#58;operation>

</wsdl&#58;binding>

<wsdl&#58;service name="UserServiceEndpointService">

<wsdl&#58;port binding="impl&#58;UserServiceSoapBinding" name="UserService">

<wsdlsoap&#58;address location="http&#58;//localhost&#58;8080/inventory/services/UserService"/>

</wsdl&#58;port>

</wsdl&#58;service>

</wsdl&#58;definitions>


I have to add all the operations provided by the bean into the wsdd?

dejanp
Jul 4th, 2005, 07:13 AM
Wsdd should be generated from wsdl and not written per hand. Wsdl can be generated from your java files using Java2Wsdl command line tool or ant task.