How to integrate of spring client with Axis WS

P

pramodr

Hi group,

I am quite new to webservices and in the process of learning and
evaluating spring-ws for my project. My question is that how to
invoke
an axis web service with spring-ws client ?

I have tried a spring-ws as follows to consume an axis ws.


Resource res = new
ClassPathResource("applicationContext.xml");


BeanFactory bf = new XmlBeanFactory(res);


WebServiceTemplate webServiceTemplate =
(WebServiceTemplate)bf.getBean("webServiceTemplate");


Source source = new StreamSource(new
StringReader(MESSAGE));
Result result = new StreamResult(System.out);


//this works.

webServiceTemplate.sendSourceAndReceiveToResult(
"http://localhost:8080/WS/
services/EmpService",
source, result);


//however this does not work.
Employee emp = new Employee();
emp.setEmpId("rrr");
emp.setEmpName("xxx");


Object o =
webServiceTemplate.marshalSendAndReceive(emp);


I need to send and receive POJOs. I think marshall/unmarshall is the
normal way. But since I use the above code, it throws me exception


org.springframework.ws.soap.client.SoapFaultClientException: No such
operation 'employee'.


So I think the request object (request payload) as they call it,
needs
to be passed instead of the pojo. But how do I do it?


Or is there a better way ?


Pasted below are the configurations. Any help in this regard is
highly
appreciated.


- Pramod


----------------
applicationContext.xml-----------------------------------------


<bean id="marshaller"
class="org.springframework.oxm.castor.CastorMarshaller">
</bean>


<bean id="unMarshaller"
class="org.springframework.oxm.castor.CastorMarshaller">
</bean>


<bean id="webServiceTemplate"
class="org.springframework.ws.client.core.WebServiceTemplate">
<property name="defaultUri" value="http://localhost:
8080/WS/services/
EmpService"></property>
<property name="marshaller" ref="marshaller"></
property>
<property name="unmarshaller" ref="unMarshaller"></
property>
</bean>
------------------------------------------------------


-----------------EmpService.wsdl------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://test" xmlns:intf="http://test" xmlns:wsdl="http://
schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://
schemas.xmlsoap.org/
wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="http://test">
<element name="getEmp">
<complexType/>
</element>
<element name="getEmpResponse">
<complexType/>
</element>
<element name="getEmp2">
<complexType>
<sequence>
<element name="emp" type="impl:Employee"/>
</sequence>
</complexType>
</element>
<complexType name="Employee">
<sequence>
<element name="empId" nillable="true" type="xsd:string"/>
<element name="empName" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="getEmp2Response">
<complexType/>
</element>
<element name="getEmp3">
<complexType>
<sequence>
<element name="emp" type="impl:Employee"/>
</sequence>
</complexType>
</element>
<element name="getEmp3Response">
<complexType>
<sequence>
<element name="getEmp3Return" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>


<wsdl:message name="getEmp3Response">
<wsdl:part element="impl:getEmp3Response" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmp2Response">
<wsdl:part element="impl:getEmp2Response" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmpResponse">
<wsdl:part element="impl:getEmpResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmpRequest">
<wsdl:part element="impl:getEmp" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmp3Request">
<wsdl:part element="impl:getEmp3" name="parameters"/>
</wsdl:message>
<wsdl:message name="getEmp2Request">
<wsdl:part element="impl:getEmp2" name="parameters"/>
</wsdl:message>
<wsdl:portType name="EmpService">
<wsdl:eek:peration name="getEmp">
<wsdl:input message="impl:getEmpRequest"
name="getEmpRequest"/




<wsdl:eek:utput message="impl:getEmpResponse"
name="getEmpResponse"/>
</wsdl:eek:peration>
<wsdl:eek:peration name="getEmp2">
<wsdl:input message="impl:getEmp2Request"
name="getEmp2Request"/>
<wsdl:eek:utput message="impl:getEmp2Response"
name="getEmp2Response"/>
</wsdl:eek:peration>
<wsdl:eek:peration name="getEmp3">
<wsdl:input message="impl:getEmp3Request"
name="getEmp3Request"/>
<wsdl:eek:utput message="impl:getEmp3Response"
name="getEmp3Response"/>
</wsdl:eek:peration>
</wsdl:portType>
<wsdl:binding name="EmpServiceSoapBinding" type="impl:EmpService">
<wsdlsoap:binding style="document" transport="http://
schemas.xmlsoap.org/soap/http"/>
<wsdl:eek:peration name="getEmp">
<wsdlsoap:eek:peration soapAction=""/>
<wsdl:input name="getEmpRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:eek:utput name="getEmpResponse">
<wsdlsoap:body use="literal"/>
</wsdl:eek:utput>
</wsdl:eek:peration>
<wsdl:eek:peration name="getEmp2">
<wsdlsoap:eek:peration soapAction=""/>
<wsdl:input name="getEmp2Request">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:eek:utput name="getEmp2Response">
<wsdlsoap:body use="literal"/>
</wsdl:eek:utput>
</wsdl:eek:peration>
<wsdl:eek:peration name="getEmp3">
<wsdlsoap:eek:peration soapAction=""/>
<wsdl:input name="getEmp3Request">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:eek:utput name="getEmp3Response">
<wsdlsoap:body use="literal"/>
</wsdl:eek:utput>
</wsdl:eek:peration>
</wsdl:binding>

<wsdl:service name="EmpServiceService">
<wsdl:port binding="impl:EmpServiceSoapBinding"
name="EmpService">
<wsdlsoap:address location="http://localhost:8080/WS/
services/
EmpService"/>
</wsdl:port>
</wsdl:service>


</wsdl:definitions>
 
P

pramodr

Hi group,

I am quite new to webservices and in the process of learning and
evaluating spring-ws for my project. My question is that how to
invoke
an axis web service with spring-ws client ?

I have tried a spring-ws as follows to consume an axis ws.

                        Resource res = new
ClassPathResource("applicationContext.xml");

                        BeanFactory bf = new XmlBeanFactory(res);

                        WebServiceTemplate webServiceTemplate =
(WebServiceTemplate)bf.getBean("webServiceTemplate");

                        Source source = new StreamSource(new
StringReader(MESSAGE));
                        Result result = new StreamResult(System.out);

                        //this works.

webServiceTemplate.sendSourceAndReceiveToResult(
                                        "http://localhost:8080/WS/
services/EmpService",
                                        source, result);

                        //however this does not work.
                        Employee emp = new Employee();
                        emp.setEmpId("rrr");
                        emp.setEmpName("xxx");

                        Object o =
webServiceTemplate.marshalSendAndReceive(emp);

I need to send and receive POJOs. I think marshall/unmarshall is the
normal way. But since I use the above code, it throws me exception

org.springframework.ws.soap.client.SoapFaultClientException: No such
operation 'employee'.

So I think the request object (request payload) as they call it,
needs
to be passed instead of the pojo. But how do I do it?

Or is there a better way ?

Pasted below are the configurations. Any help in this regard is
highly
appreciated.

- Pramod

----------------
applicationContext.xml-----------------------------------------

        <bean id="marshaller"
class="org.springframework.oxm.castor.CastorMarshaller">
        </bean>

        <bean id="unMarshaller"
class="org.springframework.oxm.castor.CastorMarshaller">
        </bean>

        <bean id="webServiceTemplate"
class="org.springframework.ws.client.core.WebServiceTemplate">
                <property name="defaultUri" value="http://localhost:
8080/WS/services/
EmpService"></property>
                <property name="marshaller" ref="marshaller"></
property>
                <property name="unmarshaller" ref="unMarshaller"></
property>
        </bean>
------------------------------------------------------

-----------------EmpService.wsdl------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://test" xmlns:intf="http://test" xmlns:wsdl="http://
schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://
schemas.xmlsoap.org/
wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" targetNamespace="http://test">
   <element name="getEmp">
    <complexType/>
   </element>
   <element name="getEmpResponse">
    <complexType/>
   </element>
   <element name="getEmp2">
    <complexType>
     <sequence>
      <element name="emp" type="impl:Employee"/>
     </sequence>
    </complexType>
   </element>
   <complexType name="Employee">
    <sequence>
     <element name="empId" nillable="true" type="xsd:string"/>
     <element name="empName" nillable="true" type="xsd:string"/>
    </sequence>
   </complexType>
   <element name="getEmp2Response">
    <complexType/>
   </element>
   <element name="getEmp3">
    <complexType>
     <sequence>
      <element name="emp" type="impl:Employee"/>
     </sequence>
    </complexType>
   </element>
   <element name="getEmp3Response">
    <complexType>
     <sequence>
      <element name="getEmp3Return" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>

   <wsdl:message name="getEmp3Response">
      <wsdl:part element="impl:getEmp3Response" name="parameters"/>
   </wsdl:message>
   <wsdl:message name="getEmp2Response">
      <wsdl:part element="impl:getEmp2Response" name="parameters"/>
   </wsdl:message>
   <wsdl:message name="getEmpResponse">
      <wsdl:part element="impl:getEmpResponse" name="parameters"/>
   </wsdl:message>
   <wsdl:message name="getEmpRequest">
      <wsdl:part element="impl:getEmp" name="parameters"/>
   </wsdl:message>
   <wsdl:message name="getEmp3Request">
      <wsdl:part element="impl:getEmp3" name="parameters"/>
  </wsdl:message>
   <wsdl:message name="getEmp2Request">
      <wsdl:part element="impl:getEmp2" name="parameters"/>
   </wsdl:message>
   <wsdl:portType name="EmpService">
      <wsdl:eek:peration name="getEmp">
         <wsdl:input message="impl:getEmpRequest"
name="getEmpRequest"/

         <wsdl:eek:utput message="impl:getEmpResponse"
name="getEmpResponse"/>
      </wsdl:eek:peration>
      <wsdl:eek:peration name="getEmp2">
         <wsdl:input message="impl:getEmp2Request"
name="getEmp2Request"/>
         <wsdl:eek:utput message="impl:getEmp2Response"
name="getEmp2Response"/>
      </wsdl:eek:peration>
      <wsdl:eek:peration name="getEmp3">
         <wsdl:input message="impl:getEmp3Request"
name="getEmp3Request"/>
         <wsdl:eek:utput message="impl:getEmp3Response"
name="getEmp3Response"/>
      </wsdl:eek:peration>
   </wsdl:portType>
   <wsdl:binding name="EmpServiceSoapBinding" type="impl:EmpService">
      <wsdlsoap:binding style="document" transport="http://
schemas.xmlsoap.org/soap/http"/>
      <wsdl:eek:peration name="getEmp">
         <wsdlsoap:eek:peration soapAction=""/>
         <wsdl:input name="getEmpRequest">
            <wsdlsoap:body use="literal"/>
         </wsdl:input>
         <wsdl:eek:utput name="getEmpResponse">
           <wsdlsoap:body use="literal"/>
        </wsdl:eek:utput>
      </wsdl:eek:peration>
      <wsdl:eek:peration name="getEmp2">
         <wsdlsoap:eek:peration soapAction=""/>
         <wsdl:input name="getEmp2Request">
            <wsdlsoap:body use="literal"/>
         </wsdl:input>
         <wsdl:eek:utput name="getEmp2Response">
            <wsdlsoap:body use="literal"/>
         </wsdl:eek:utput>
      </wsdl:eek:peration>
      <wsdl:eek:peration name="getEmp3">
         <wsdlsoap:eek:peration soapAction=""/>
         <wsdl:input name="getEmp3Request">
            <wsdlsoap:body use="literal"/>
         </wsdl:input>
         <wsdl:eek:utput name="getEmp3Response">
            <wsdlsoap:body use="literal"/>
         </wsdl:eek:utput>
      </wsdl:eek:peration>
   </wsdl:binding>

   <wsdl:service name="EmpServiceService">
      <wsdl:port binding="impl:EmpServiceSoapBinding"
name="EmpService">
         <wsdlsoap:address location="http://localhost:8080/WS/
services/
EmpService"/>
      </wsdl:port>
   </wsdl:service>

</wsdl:definitions>

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

(I have posted this in webservice community group, but since the
activity there is very minimal, I am cross posting here - sorry for
that)



FYI I Use Tomcat 5.0 jre 1.4
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top