Spring Webservicetemplate calls axis1.4 published WebService

Source: Internet
Author: User
Tags soap soapui wsdl

Objective:

Recently in the development of the need to call the other side of the WebService service, according to the existing technology, it should be a very simple thing, just need to get the WSDL file, generate the client code can, but, The WebService service was released in 06 with axis1.4 generation, the WSDL file can only be used zxis1.4 production client code, and Axis's jar package and program deployment environment WebSphere8.5 conflict, causing the program to fail to start. Spring's webservicetemplate can be used in the was environment, so write how spring writes the client code manually and invokes the axis1.4 server.

Solution:

Regardless of what tool is generated by the WebService client, it is eventually assembled into a SOAP protocol-compliant XML file sent to the server, which receives the XML file returned by the server and parses it into the object we need. Although spring cannot generate client JavaBean objects from the WSDL file of axis1.4, we can manually write these JavaBean according to the rules of how the JavaBean object that spring produced itself assembles the SOAP protocol XML file, namely: according to the SOAP protocol XM L file Backwards deduces the JavaBean object that assembles this XML file.

    1. Get the XML file to be sent to the server based on the WSDL,

This is based on the WSDL syntax and the SOAP protocol specification, which can be parsed by itself, but it is time consuming, so it is recommended that a tool: SoapUI, you can generate an XML file to be sent to the server based on the WSDL file and the XML file returned by the corresponding server (just a small function of the tool). The SOAPUI version used in this article is 5.2.1

Instance of the requested XML file:

1 <Soapenv:envelopexmlns:xsd= "Http://www.w3.org/2001/XMLSchema"xmlns:soapenv= "http://schemas.xmlsoap.org/soap/envelope/" >2    <Soapenv:header/>3    <Soapenv:body>4       <SayHelloSoapenv:encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/">5          <messageXsi:type= "Xsd:string">?</message>6       </SayHello>7    </Soapenv:body>8 </Soapenv:envelope>

Answer XML File instance:

1 <Soapenv:envelopexmlns:xsd= "Http://www.w3.org/2001/XMLSchema"xmlns:soapenv= "http://schemas.xmlsoap.org/soap/envelope/">2    <Soapenv:header/>3    <Soapenv:body>4       <SayhelloresponseSoapenv:encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/">5          <SayhelloreturnXsi:type= "Xsd:string">?</Sayhelloreturn>6       </Sayhelloresponse>7    </Soapenv:body>8 </Soapenv:envelope>

2. Write JavaBean based on XML

Correspondence: The tag inside the body tag in the request message is the description of the service-side method,

SayHello-to-server method name----JavaBean----@XmlRootElement name value

The SayHello is the parameter of the method, and the type of the parameter is defined later

Message--Method parameter---javabean field--@XmlElement name value

Request JavaBean Instance

1 ImportJavax.xml.bind.annotation.XmlAccessType;2 ImportJavax.xml.bind.annotation.XmlAccessorType;3 Importjavax.xml.bind.annotation.XmlElement;4 Importjavax.xml.bind.annotation.XmlRootElement;5 6 @XmlAccessorType (Xmlaccesstype.field)7@XmlRootElement (name = "SayHello")8  Public classSayhellorequest {9 Ten@XmlElement (name = "Message") One     PrivateString message; A  -      PublicString getMessage () { -         returnmessage; the     } -  -      Public voidsetmessage (String message) { -          This. Message =message; +     } -}

Answering JavaBean instances

1 ImportJavax.xml.bind.annotation.XmlAccessType;2 ImportJavax.xml.bind.annotation.XmlAccessorType;3 Importjavax.xml.bind.annotation.XmlElement;4 Importjavax.xml.bind.annotation.XmlRootElement;5 6 @XmlAccessorType (Xmlaccesstype.field)7@XmlRootElement (name = "Sayhelloresponse")8  Public classSayhelloresponse {9 Ten@XmlElement (name = "Sayhelloreturn") One     PrivateString Sayhelloreturn; A  -      PublicString Getsayhelloreturn () { -         returnSayhelloreturn; the     } -  -      Public voidSetsayhelloreturn (String sayhelloreturn) { -          This. Sayhelloreturn =Sayhelloreturn; +     } -}

3. Spring Webservicetemplate Call

Spring's webservicetemplate uses this here not to do the elaboration, needs to configure the Webservicetemplate bean and parses the XML file the Marshaller Bean

1 ImportJavax.annotation.Resource;2 3  Public classWstest {4 5 @Resource6     Privatewebservicetemplate webservicetemplate;7 8      Publicsayhelloresponse SayHello (sayhellorequest request) {9         TenString url = "Http://www.xxxx.com/xxx"; One  A          return(sayhelloresponse) webservicetemplate.marshalsendandreceive (URL, request); -     } -  the}

Spring Webservicetemplate calls axis1.4 published WebService

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.