How to use AXIS to process complex type parameters and return values

xiaoxiao2021-03-06  77

1. How to monitor SOAP requests and response streams

The presenter we did is very simple, the method's parameters and return values ​​are simple type data, but in actual

It is often not so simple during the application. When using an object-oriented programming language, we will want the data type but

An object, such as we provide an interface to query city information, then we want the interface to the interface is a city

City information object, this information object encapsulates the needs of a city information, including the name, region

Zip code, area code, population. Area information, etc. If we make each content into a parameter, the parameters of this interface may be very much. Therefore, it is necessary to encapsulate objects.

The processing of complex type data is also very simple when using AXIS to write a Web service. AXIS requires complex

The writing of a miscellaneous object must comply with JavaBean's specifications, simply that the object's properties are passed

Getter / setter method is accessible. Take a look at the WSDL information output by the simple example below.

local. (We are ready to use JBuilderx to quickly develop).

CityInfo.java

Package com.yang;

Public class cityinfo {

// Regional City Name Private String CityName; // Area Code Private String Zone; // Administrative Region Private String District; // Population Private String Populace; // Area Private String Area;

Public String getarea () {Return Area;}

Public string getpopulace () {return populace;}

Public string getdistrict () {return disprices;

Public string getpost () {returno post;}

Public string getzone () {return zone;}

Public void setcityName (string cityname) {this.cityName = cityname;}

Public void setarea (string area) {this.area = area;

Public void setpopulace (string populace) {this.populace = populace;}

Public void setDistrict (string district) {this.district = ztrict;}

Public void setpost (string post) {this.post = post;}

Public void setzone (string zone) {this.zone = zone;

Public string getcityname () {return cityname;}}

DisposeQueryCity.java

Package com.yang;

Public class disposeQuerycity {

Private string mess = null;

Private cityfo cityInfo = null;

Public void setcityInfo (cityInfo cityInfo) {

THIS.CITYINFO = CITYINFO;

}

Public void setmess (string mess) {

THIS.MESS = Mess;}

Public cityInfo getcityInfo () {

Return CityInfo;

}

Public string getmess () {

Return Mess;

}

}

QueryCITY.JAVA

Package com.yang;

Public class querycity {

Public DisposeQueryCity getQueryCity (CityInfo CityInfo) {

CityInfo newcityInfo = new cityinfo ();

DisposeQueryCity DisposeQueryCity = new disposeQueryCity ();

IF (CityInfo.getPost () == null || cityinfo.getPost (). Equals ("")) {

DisposeQueryCITY.SetMess ("You have no corresponding city!");

DisposeQueryCITY.SetCityInfo (NULL);

}

Else {

IF (CityInfo.get (). Equals ("362400")) {

NewCITYINFO.SETCITYNAME ("Anxi County (Fengcheng Town)");

NewCITYINFO.Setarea ("2983 square kilometers");

NewCITYINFO.SETDISTRICT ("Fujian Province");

NewCITYINFO.SETZONE ("0595");

NewCITYINFO.SETPOPULACE ("1050,000 people");

DisposeQueryCITY.SetMess ("The city information of the zip code you entered is:");

DisposeQueryCITY.SetCityInfo (NewCITYINFO);

}

Else IF (CityInfo.get (). Equals ("350007")) {

NewCITYINFO.SETCITYNAME ("Cangshan District");

NewCITYINFO.Setarea ("139 square kilometers");

NewCITYINFO.SETDISTRICT ("Fujian Province");

NewCITYINFO.SETZONE ("0591");

NewCITYINFO.SETPOPULACE ("350,000 people");

DisposeQueryCITY.SetMess ("The city information of the zip code you entered is:");

DisposeQueryCITY.SetCityInfo (NewCITYINFO);

}

Else IF (Cityinfo.get (). Equals ("350001")) {

NewCITYINFO.SETCITYNAME ("Fuzhou");

NewCITYINFO.SETAREA ("12154 square kilometers");

NewCITYINFO.SETDISTRICT ("Fujian Province");

NewCITYINFO.SETZONE ("0591");

NewCITYINFO.SETPOPULACE ("589 million people");

}

Else IF (Cityinfo.get (). Equals ("361012")) {

NewCITYINFO.SETCITYNAME ("Xiamen");

NewCITYINFO.Setarea ("1638 square kilometers");

NewCITYINFO.SETDISTRICT ("Fujian Province");

NewCITYINFO.SETZONE ("0592"); NewCITYINFO.SETPOPULACE ("1.31 million people");

DisposeQueryCITY.SetMess ("The city information of the zip code you entered is:");

DisposeQueryCITY.SetCityInfo (NewCITYINFO);

}

}

Return DisposeQueryCity;

}

}

Newly built the Java files based on the ninth chapter.

Open axis [Apache Axis TookIt] in the Project Bar

In the Web Services Designer section, click Create Serviceàjava Service

Click New Java Service to modify Disply Name for CityService

Select Class or Interface Com.YANG.QueryCity

Compile project

Produced as follows QueryCITY.WSDL

CityInfo_helper.java

CityInfo.java

DisposeQueryCity_Helper.java

DisposeQueryCity.java

QueryCITY.JAVA

QueryCITYSERVICE.JAVA

QueryCITYSERVICELOCATOR.JAVA

QueryCITYSERVICEstcase.java

Querycitysoapbindingstub.java

Let's take a look at the change of querycity.wsdl.

The red part has obvious changes, and it can understand what changes can be understood more than before.

The two types of cityinfo and disposequerycity are defined here, which is the parameter type and return of our interface.

Type of value.

Open axis àmodule directoryàWeb-infàserver-conig.wsdd in the Project column

What changes have been seen before?

XMLns: java = "http://xml.apache.org/axis/wsddd/providers/java"

XMLns: handler = "http://xml.apache.org/axis/wsdd/providers/handler" xmlns = "http://xml.apache.org/axis/wsdd/">

>

TYPE = "java: org.apache.axis.handlers.jwshandler" regenerateElement = "false">

TYPE = "java: org.apache.axis.handlers.jwshandler" regenerateElement = "false">

TYPE = "java: org.apache.axis.handlers.http.urmapper" regenerateElement = "false" />

TYPE = "java: org.apache.axis.transport.local.localResponder" regenerateElement = "false" />

TYPE = "java: org.apache.axis.handlers.simpleauthenticationHandler" regenerateElement = "false" />

http://xml.apache.org/axis/wsdd/

Provider = "Java: RPC" style = "rpc" use = "encoded">

Provider = "java: rpc" style = "rpc" using = "encoded">

EncodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"

QNAME = "ns1: cityinfo"

LanguagespecificType = "java: com.yang.cityInfo"

Serializer = "org.apache.axis.encoding.ser.beanserializerfactory"

Deserializer = "Org.apache.axis.encoding.ser.beandeserializerfactory"

Name = "CityInfo" regenerateElement = "true" xmlns: ns1 = "http://yang.com" />

EncodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"

Qname = "ns2: disposequery" "

Languagespecifictype = "java: com.yang.disposequery" "

Serializer = "org.apache.axis.encoding.ser.beanserializerfactory"

Deserializer = "org.apache.axis.encoding.ser.beandeserializerfactory" name = "disposequerycity" regenerateElement = "true" xmlns: ns2 = "http://yang.com" />

Red and green are part of the change, the green part defines the parameters of the method and the return value.

Cityinfo_helper.java, cityifo.java, disposequerycity_helper.java, DisposeQuery ,.java

These Java files have added a number of methods such as GetTypedesc, GetSerializer, GetdeSerializer, and more.

Now you can write a small program to test, we are not cumbersome.

CityClient.java

Package com.yang.Generated;

Import java.rmi.remoteexception;

Public class cityclient {

Public static void main (string args []) throws receexception {

QueryCITYSOAPBINDINGSTUB BINDING = NULL;

Try {

Binding = (QueryCITYSOAPBINDINGSTUB)

New queryCITYSERVICELOCATOR (). getQueryCity ();

}

Catch (javax.xml.rpc.serviceException jre) {

System.out.println (JRE.TOString ());

}

DisposeQueryCity value = null;

CityInfo cityInfo = new cityInfo ();

Cityinfo.setPost ("361012");

Value = binding.getQueryCity (CityInfo);

IF (value.getCITYINFO () == null) {

System.out.println (Value.getMess ());

}

Else {

System.out.println (Value.getMess ());

System.out.println ("Region:" Value.getCityInfo (). GetCityName ());

System.out.println ("End:" Value.getCITYINFO (). Getarea ());

System.out.println ("Name:" Value.getCityInfo (). GetDistrict ());

System.out.println ("Area Number:" Value.getCITYInfo (). Getzone ());

System.out.println ("Export:" Value.getCITYINFO (). GetPopulace ());

}

}

}

Running Web Run Using "Web Services Server"

Run the CityClient in the Project column

Messages box output you information:

The city information corresponding to the input zip code is:

Region: Xiamen City

End: 1638 square kilometers

Name: Fujian Province

Area number: 0592

Humanity: 1.31 million

转载请注明原文地址:https://www.9cbs.com/read-98549.html

New Post(0)