PDA

View Full Version : consuming webservices


pshah
Nov 12th, 2007, 05:34 PM
Hello,
I am trying to consume a webservice using the spring IOC. I am new to webservices. I created a simple webservice using IBM Rational Application developer and have successfully deployed it to the build in Websphere 6.1 server. I have been looking at spring books on how to "consume" by service, and I have accordingly come up with this in my context file:


<bean id="currencyWebService" class="org.springframework.remoting.jaxrpc.JaxRpcPortProx yFactoryBean">
<property name="wsdlDocumentUrl">
<value>http://localhost:9081/DemoWebService/services/DemoWebService/wsdl/DemoWebService.wsdl</value></property>
<property name="namespaceUri"><value>"http://cfudemo"</value></property>
<property name="serviceName"><value>"DemoWebServiceService"</value></property>
<property name="portName"><value>"DemoWebService"</value></property>
<property name="serviceInterface"><value>cfudemo.DemoWebServiceService</value></property>
</bean>

The books that I have read are a little ambiguous on the details. I am assuming the "service interface" is just a java interface for the webservice. Will the spring framework automatically "implement" the interface and generage proxy classes? I used the following interface inside my project:



public interface DemoWebService extends java.rmi.Remote {
public java.lang.Object[] supportedCurrencies() throws java.rmi.RemoteException;
public double convertToDollar(double euro) throws java.rmi.RemoteException;
public double convertToEuro(double dollar) throws java.rmi.RemoteException;
}

I am stuck at the following error:
11/12/07 17:10:58:631 EST] 00000016 ServiceLogger I com.ibm.ws.ffdc.IncidentStreamImpl initialize FFDC0009I: FFDC opened incident stream file D:\IBM\SDP70\runtimes\base_v61\profiles\AppSrv02\l ogs\ffdc\server1_76f076f0_07.11.12_17.10.58_0.txt
[11/12/07 17:10:58:647 EST] 00000016 ServiceLogger I com.ibm.ws.ffdc.IncidentStreamImpl resetIncidentStream FFDC0010I: FFDC closed incident stream file D:\IBM\SDP70\runtimes\base_v61\profiles\AppSrv02\l ogs\ffdc\server1_76f076f0_07.11.12_17.10.58_0.txt
[11/12/07 17:10:58:663 EST] 00000016 DefaultListab I org.apache.commons.logging.impl.Jdk14Logger info Destroying singletons in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [UrlMappings,viewResolver,CaseSelectController,curr encyWebService]; root of BeanFactory hierarchy}
[11/12/07 17:10:58:678 EST] 00000016 ContextLoader E org.apache.commons.logging.impl.Jdk14Logger error Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'currencyWebService' defined in ServletContext resource [/WEB-INF/MainDispatcher-servlet.xml]: Initialization of bean failed; nested exception is javax.xml.rpc.ServiceException: WSWS5017E: An error occurred while reading the WSDL definition that is located at URI: http://localhost:9081/DemoWebService/services/DemoWebService/wsdl/DemoWebService.wsdl
javax.xml.rpc.ServiceException: WSWS5017E: An error occurred while reading the WSDL definition that is located at URI: http://localhost:9081/DemoWebService/services/DemoWebService/wsdl/DemoWebService.wsdl
at com.ibm.ws.webservices.multiprotocol.AgnosticServi ceFactory.getDefinitionFromURL(AgnosticServiceFact ory.java:515)
at com.ibm.ws.webservices.multiprotocol.AgnosticServi ceFactory.createService(AgnosticServiceFactory.jav a:162)
at org.springframework.remoting.jaxrpc.LocalJaxRpcSer viceFactory.createService(LocalJaxRpcServiceFactor y.java:267)
at org.springframework.remoting.jaxrpc.LocalJaxRpcSer viceFactory.createJaxRpcService(LocalJaxRpcService Factory.java:203)
at org.springframework.remoting.jaxrpc.JaxRpcPortClie ntInterceptor.prepare(JaxRpcPortClientInterceptor. java:310)
at org.springframework.remoting.jaxrpc.JaxRpcPortClie ntInterceptor.afterPropertiesSet(JaxRpcPortClientI nterceptor.java:284)
at org.springframework.remoting.jaxrpc.JaxRpcPortProx yFactoryBean.afterPropertiesSet(JaxRpcPortProxyFac toryBean.java:56)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1091)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:3

The interesting part is that I can view the WSDL fine from my broswer. I would appreciate some direction on how to go about consuming a simple webservice with spring IOC.

Thanks,

jonnio
Nov 12th, 2007, 10:03 PM
You will usually be better off generating some client stubs using spring-ws, axis, or other web service framework. This allows you to wrap the service in a DAO layer to better control and also have code that you can test outside of the runtime environment.

pshah
Nov 14th, 2007, 09:41 AM
Thanks for the reply. I was actually thinking along the same lines, but I was annoyed that I couldn't get it to work the "spring way" because the rest of my project uses the spring IOC concepts. However, IBM rational application developer does a good job creating stub methods.