Eclipse builds Web service and tests with the AXIS2 plugin

Source: Internet
Author: User
Tags wsdl

When learning Web service, from the Internet to find the senior blog http://www.cnblogs.com/hexinlin/p/3358558.html, And according to the method of this article step by step: Write to publish Java class Hellodemo.java, build. arr file and publish the service to tomcat\webapps\axis2\web-inf\services\, and access http:// 127.0.0.1:8080/AXIS2/SERVICES/HELLODEMO?WSDL success ... But when line-to-text steps "C. Generate stubs", fill in the "Http://127.0.0.1:8080/axis2/services/HelloDemo" in the Axis Codgen Wizard Guide WSDL file location column? WSDL "error :" Specified wsdl is invalid!, please select a validated *.wsdl/*.xml file on previous page. "

Package Com.hxl.webservice.service;public class Hellodemo {public    string SayHello (String name) {        return "Hello "+name;    }        Public String Getresp () {        return "request is responding";    }}

The solution was not found at the moment, only to find a way: Using the original Hellodemo.java to generate a WSDL file hellodemo.wsdl the existence of local--d:\project\testwebser\src\hellodemo.wsdl.

Then use the hellodemo.wsdl file to generate the associated Java code. As follows:

Extensionmapper.java
Getresp.java
Getrespresponse.java
Hellodemocallbackhandler.java
Hellodemostub.java
Sayhello.java
Sayhelloresponse.java
Testmethods.java

In Hellodemostub.java "implements Hellodemo" error. This is because the Hellodemo class in Hellodemo.java is not an interface interface. Simply delete "Implements Hellodemo".

public class Hellodemostub extends Org.apache.axis2.client.Stub        implements Hellodemo{protected Org.apache.axis2.description.axisoperation[] _operations;

The next thing to do is to implement the RECEIVERESULTGETRESP and Receiveresultsayhello methods in Hellodemocallbackhandler to get what you want:

Package Com.hxl.webservice.stub;import Com.hxl.webservice.service.hellodemocallbackhandler;import Com.hxl.webservice.service.sayhelloresponse;import Com.hxl.webservice.service.getrespresponse;public Class Mycallback extends Hellodemocallbackhandler {    @Override public    void Receiveresultgetresp (getrespresponse Result) {        System.out.println (Result.getlocal_return ());    }    @Override public    void Receiveresultsayhello (sayhelloresponse result) {        System.out.println (Result.getlocal_ return ());}    }

And then write a method that sets the class of the call

Package Com.hxl.webservice.service;import Com.hxl.webservice.stub.*;import Java.rmi.remoteexception;import Org.apache.axis2.axisfault;public class Testmethods {public void Testgetresp () throws exception{hellodemostub stub = new Hellodemostub (); GETRESP gr = new Getresp (); System.out.println (Stub.getresp (GR). Get_return ());} public void Testsayhello () throws exception{hellodemostub stub  = new Hellodemostub (); SayHello sh = new SayHello (); Sh.setname ("Hxl"); System.out.println (Stub.sayhello (SH). Get_return ());}    public void Testgetayn () throws Exception {        hellodemostub stub = new Hellodemostub (); GETRESP gr = new Getresp (); Stub.startgetresp (GR, New Mycallback ()); SayHello sh = new SayHello (); Sh.setname ("darren!"); Stub.startsayhello (SH, New Mycallback ()); SYSTEM.OUT.PRINTLN ("Asynchronous Invocation"); System.in.read ();}}

Finally, write a test class with the Main method clnt:

Package Com.hxl.webservice.service;import Java.rmi.remoteexception;import Org.apache.axis2.axisfault;public class CLNT {/** * @param args * @throws Exception  */public static void Main (string[] args) throws Exception {Testmethods tm = new Testmethods ();//tm.testgetresp ();//tm.testsayhello (); Tm.testgetayn ();}}

To perform the printed result:

asynchronous invocation

Request is responding

Hello darren!

Eclipse builds Web service and tests with the AXIS2 plugin

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.