CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2009
    Posts
    24

    Smile Sample WebService using XFire

    Hi ,
    I am trying to build a Sample web service using Xfire and spring which will return some string(Test Service).

    ClaimContactDataService.java
    Code:
    public class ClaimContactDataService  extends BusinessService  implements  IClaimContactDataService {
    
    	
    public String getClaimContacts() throws BusinessServiceException   {
    		// TODO Auto-generated method stub
    		return "Test Service";
    	} 
    }
    IClaimContactDataService.java
    Code:
    public interface IClaimContactDataService extends IBusinessService {
    
    	String getClaimContacts() throws BusinessServiceException;
    }
    To generate wsdl: It is generating.

    Src/Integration-client-ab.xml

    Code:
    <bean id="claimContactDataBusinessServiceClient"	class="org.codehaus.xfire.spring.remoting.XFireClientFactoryBean"
    	p:lookupServiceOnStartup="false"
    	p:serviceClass="com.....integration.ab.business.service.IClaimContactData"
    	p:outHandlers-ref="clientAuthenticationHandler"
    	p:wsdlDocumentUrl-ref="claimContactDataWsdlUrl" />
    
    <bean id="claimContactDataWsdlUrl"
    	class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
    	p:targetClass="com.....integration.ab.properties.BusinessServiceClientProperties"
    	p:targetMethod="getClaimContactDataWsdlUrl" />

    Integration-service.xml
    Code:
    <bean id="claimContactDataBusinessService"
    	class="com…….claim.dao.service.ClaimContactDataService"/>
    
    services-servlet.xml
    <bean id="claimContactDataWebService"
    		class="org.codehaus.xfire.spring.remoting.XFireExporter"
    		p:serviceFactory-ref="xfire.serviceFactory" p:xfire-ref="xfire"
    		p:serviceBean-ref="claimContactDataBusinessService"		
    		p:serviceClass="com.....integration.ab.business.claim.dao.service.IClaimContactDataService"/>
    
    
    <context:property-placeholder
    		location="classpath:jdbc.properties,				  classpath:com/.../integration/common/properties/mail.properties" />
    
    	<import resource="/Integration-service.xml" />
    	<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />


    WEDL File:
    ------------

    Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    - <wsdl:definitions targetNamespace="http://service.dao.claim.business.ab.integration.....com" xmlns:tns="http://service.dao.claim.business.ab.integration.....com" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://request.domain.ab.integration.....com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns3="http://exception.common.integration.....com" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:ns2="http://response.domain.ab.integration.....com" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    - <wsdl:types>
    - <xsd:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://request.domain.ab.integration.....com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    - <xsd:complexType name="ClaimContactRequest">
    - <xsd:sequence>
      <xsd:element minOccurs="0" name="contacts" nillable="true" type="xsd:string" /> 
      </xsd:sequence>
      </xsd:complexType>
      </xsd:schema>
    - <xsd:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://service.dao.claim.business.ab.integration.....com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    - <xsd:element name="getClaimContacts">
    - <xsd:complexType>
    - <xsd:sequence>
      <xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="ns1:ClaimContactRequest" /> 
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
    - <xsd:element name="getClaimContactsResponse">
    - <xsd:complexType>
    - <xsd:sequence>
      <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="ns2:ClaimContactResponse" /> 
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      <xsd:element name="BusinessServiceException" type="ns3:BusinessServiceException" /> 
      </xsd:schema>
    - <xsd:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://response.domain.ab.integration.....com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    - <xsd:complexType name="ClaimContactResponse">
    - <xsd:sequence>
      <xsd:element minOccurs="0" name="contacts" nillable="true" type="xsd:string" /> 
      </xsd:sequence>
      </xsd:complexType>
      </xsd:schema>
    - <xsd:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://exception.common.integration.....com" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:complexType name="BusinessServiceException" /> 
      </xsd:schema>
      </wsdl:types>
    - <wsdl:message name="BusinessServiceException">
      <wsdl:part name="BusinessServiceException" element="tns:BusinessServiceException" /> 
      </wsdl:message>
    - <wsdl:message name="getClaimContactsResponse">
      <wsdl:part name="parameters" element="tns:getClaimContactsResponse" /> 
      </wsdl:message>
    - <wsdl:message name="getClaimContactsRequest">
      <wsdl:part name="parameters" element="tns:getClaimContacts" /> 
      </wsdl:message>
    - <wsdl:portType name="IClaimContactDataServicePortType">
    - <wsdl:operation name="getClaimContacts">
      <wsdl:input name="getClaimContactsRequest" message="tns:getClaimContactsRequest" /> 
      <wsdl:output name="getClaimContactsResponse" message="tns:getClaimContactsResponse" /> 
      <wsdl:fault name="BusinessServiceException" message="tns:BusinessServiceException" /> 
      </wsdl:operation>
      </wsdl:portType>
    - <wsdl:binding name="IClaimContactDataServiceHttpBinding" type="tns:IClaimContactDataServicePortType">
      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> 
    - <wsdl:operation name="getClaimContacts">
      <wsdlsoap:operation soapAction="" /> 
    - <wsdl:input name="getClaimContactsRequest">
      <wsdlsoap:body use="literal" /> 
      </wsdl:input>
    - <wsdl:output name="getClaimContactsResponse">
      <wsdlsoap:body use="literal" /> 
      </wsdl:output>
    - <wsdl:fault name="BusinessServiceException">
      <wsdlsoap:fault name="BusinessServiceException" use="literal" /> 
      </wsdl:fault>
      </wsdl:operation>
      </wsdl:binding>
    - <wsdl:service name="IClaimContactDataService">
    - <wsdl:port name="IClaimContactDataServiceHttpPort" binding="tns:IClaimContactDataServiceHttpBinding">
      <wsdlsoap:address location="http://localhost:8280/Integration/services/claimContactDataService" /> 
      </wsdl:port>
      </wsdl:service>
      </wsdl:definitions>
    Client.java
    ---------
    Code:
    public class Client {
    
    	public static void main(String[] args) {
    		Service srvcModel = new ObjectServiceFactory()
    				.create(IClaimContactDataService.class);
    		XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
    				.newInstance().getXFire());
    
    		String claimURL = "http://localhost:8280/.../claimContactDataService";
    
    		try {
    			IClaimContactDataService srvc = (IClaimContactDataService) factory
    					.create(srvcModel, claimURL);
    			
    			  String response = srvc.getClaimContacts();
    		        System.out.println("Response: " + response);
    		        
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    }
    When I try to call webservice using client I am getting following error, Please help.


    Code:
                 
    
       org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Fault: java.lang.NullPointerException
    org.codehaus.xfire.fault.XFireFault: Fault: java.lang.NullPointerException
    	at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
    	at org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)
    	at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)
    	at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
    	at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    	at org.codehaus.xfire.client.Client.onReceive(Client.java:406)
    	at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
    	at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
    	at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
    	at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    	at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
    	at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
    	at org.codehaus.xfire.client.Client.invoke(Client.java:336)
    	at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
    	at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
    	at $Proxy0.getClaimContacts(Unknown Source)
    	at com...integration.ab.business.claim.dao.service.Client.main(Client.java:25)

  2. #2
    Join Date
    Sep 2009
    Posts
    24

    Re: Sample WebService using XFire

    I am through with above null pointer exception.

    But I am facing another error , can any one give inputs ?


    Thanks in advance...........

    Error:

    Code:
    org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: AOP configuration seems to be invalid: tried calling method [public abstract void com.....integration.ab.business.service.IClaimContactDataService.getClaimContacts() throws com......integration.common.exception.BusinessServiceException] on target [org.codehaus.xfire.spring.remoting.XFireExporter@94b0ca]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class
    org.codehaus.xfire.fault.XFireFault: AOP configuration seems to be invalid: tried calling method [public abstract void com.....integration.ab.business.service.IClaimContactDataService.getClaimContacts() throws com......integration.common.exception.BusinessServiceException] on target [org.codehaus.xfire.spring.remoting.XFireExporter@94b0ca]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class
    	at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
    	at org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)
    	at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)
    	at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
    	at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    	at org.codehaus.xfire.client.Client.onReceive(Client.java:406)
    	at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
    	at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
    	at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
    	at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    	at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
    	at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
    	at org.codehaus.xfire.client.Client.invoke(Client.java:336)
    	at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
    	at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
    	at $Proxy0.getClaimContacts(Unknown Source)
    	at com......integration.ab.business.service.Client3.main(Client3.java:27)

  3. #3
    Join Date
    Apr 2007
    Posts
    425

    Re: Sample WebService using XFire

    I haven't muched played with Xfire web services and spring, but by the sounds of it, it looks like Xfire didn't return you a proxy to what you think you were getting, so you're trying to cast and invoke on the wrong type?

    Spring AOP has a few different ways of 'weaving' (that's the term to decorate code with AOP). You might have better luck reading the spring documentation on how that works, or posting on the Spring forums specifically.

    http://static.springsource.org/sprin...rence/aop.html
    ------
    If you are satisfied with the responses, add to the user's rep!

  4. #4
    Join Date
    Sep 2009
    Posts
    24

    Re: Sample WebService using XFire

    Deliverance: Your are great your inputs made to think In right direction, actually I cofigured wrongly. I rectified my issue.

    ------------

    Now I want to design a client for a webservice which is designed In .net.

    WSDL: .net webservice WSDL url looks like
    ------

    Code:
    Code:
    http://abc.net/Service.svc?wsdl
    Can any one give tips how to design client using Java, Spring and Xfire to call a .net webservice?

    Thanks,
    Dev.

  5. #5
    Join Date
    Apr 2007
    Posts
    425

    Re: Sample WebService using XFire

    Yes.

    http://xfire.codehaus.org/Client+and...tion+from+WSDL


    If you build using maven, I'm sure they also have generate-sources goals. You'll have to make sure the .NET wsdl is hosted and accessible, and there's not really much else. the guide is simple, and the tools are very similar if you ever choose to switch to say Project Metro (JAX-WS, JAX-B, WSIT, etc), Apache Axis, Apache CXF, etc.
    ------
    If you are satisfied with the responses, add to the user's rep!

  6. #6
    Join Date
    Sep 2009
    Posts
    24

    Re: Sample WebService using XFire

    I am using Xfire-all.1.2.6.jar,


    Ant taks:
    Code:
    <target name="gen-client" description="generates client">
    		<taskdef name="wsgen"
    			classname="org.codehaus.xfire.gen.WsdlGenTask"
    			classpathref="build.classpath" />
    
    		<wsgen outputDirectory="${basedir}/target/generated-source"
    			wsdl="http://a/b/Service.svc?wsdl"
    			package="com….business.service" overwrite="true" />
    
    	</target>
    When I ran above take I am getting;
    Code:
    gen-client:
    
    BUILD FAILED
    \workspace_ws\Integ\build.xml:456: java.lang.UnsupportedClassVersionError: org/codehaus/xfire/gen/WsdlGenTask (Unsupported major.minor version 49.0)
    Do I need to change classname(org.codehaus.xfire.gen.WsdlGenTask)? Here any input for me?

    -Dev
    Last edited by java_dev; November 18th, 2009 at 09:51 AM. Reason: formatting

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured