銆銆涓銆丄xis鐜鐨勫畨瑁?/strong>
銆銆1銆佸畨瑁呯幆澧?J2SE SDK錛孴omcat錛宔clipse銆?/p>
銆銆2銆佸埌 http://xml.apache.org 緗戠珯涓嬭澆Axis瀹夎鍖呫?/p>
銆銆3銆佸皢Axis鐩稿叧鍖呮枃浠舵斁鍦╓EB-INF\lib鐩綍涓嬶紝闇瑕佸彟澶栦笅杞絘ctivation.jar銆?/p>
銆銆Axis鏀寔涓夌web service鐨勯儴緗插拰寮鍙戯紝鍒嗗埆涓猴細(xì)
銆銆1銆丏ynamic Invocation Interface 錛圖II錛?/p>
銆銆2銆丏ynamic Proxy鏂瑰紡
銆銆3銆丼tubs鏂瑰紡
銆銆鍓嶄袱縐嶆柟寮忔垜灝變笉浠嬬粛浜嗭紝鍚屼簨鍛婅瘔鎴戜粬浠嚜宸遍兘涓嶄嬌鐢ㄥ墠涓ょ鏂瑰紡錛屼粬浠緩璁垜浠嬌鐢⊿tubs鏂瑰紡錛屽洜姝ゆ垜灝變富瑕佸氨浠嬬粛涓涓嬬涓夌鏂瑰紡銆傛敞鎰忥紝鎴戣嚜宸辯殑Java婧愪唬鐮佹槸鏀懼湪D錛歕workspace\test\鐩綍涓嬶紝Axis鐩稿叧鍖呮枃浠舵斁鍦―錛歕workspace\test\WEB-INF鐩綍涓嬨?/p>
銆銆浜屻佺紪鍐檞sdd鍙戝竷web鏈嶅姟錛岀紪鍐檚tub client璁塊棶web鏈嶅姟
銆銆1銆佺紪鍐欐湇鍔$紼嬪簭server錛孲ayHello.java錛岀紪璇憇erver.SayHello.java
package server;
public class SayHello
{
public String getName(String name)
{
return "hello "+name;
}
}
銆銆2銆佺紪鍐檞sdd鏂囦歡
銆銆deploy.wsdd鏂囦歡鍐呭濡備笅錛?/p>
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="SayHello" provider="java:RPC">
<parameter name="className" value="server.SayHello.getName"/>
<parameter name="allowedMethods" value="*"/>
</service>
</deployment>
銆銆3銆佸彂甯冩湇鍔★細(xì)
銆銆緙栬緫涓涓猟eploy.bat錛孉xis_Lib涓篴xis.jar璺緞銆傚唴瀹瑰涓嬶紙娉ㄦ剰鐩綍鍚嶄腑涓嶈鍖呭惈絀烘牸錛夛細(xì)
set Axis_Lib=D:\workspace\test\WEB-INF\lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
set Axis_Servlet=http://localhost:8080/test/servlet/AxisServlet
%Java_Cmd% org.apache.axis.client.AdminClient -l%Axis_Servlet% deploy.wsdd
銆銆鎵ц榪欎釜鎵瑰鐞嗘枃浠訛紝鎵ц榪欎釜鎵瑰鐞嗕箣鍓嶏紝tomcat蹇呴』鍚姩璧鋒潵銆傚鏋滃鐞嗘垚鍔熺殑璇濓紝鐒跺悗灝哻lass鏂囦歡鎷瘋礉鍒癮xis鐨刟xis"WEB-INF"classes鐩綍涓紝鐒跺悗璁塊棶http://localhost:8080/test/services 灝變細(xì)鏄劇ず鏈嶅姟鍒楄〃銆?/p>
銆銆4銆佺敓鎴愬鎴風(fēng)client stub鏂囦歡
銆銆鍦ㄦ祻瑙堝櫒涓婅闂湇鍔″櫒绔殑鏈嶅姟錛屽彲浠ヤ笅杞藉埌WSDL鏂囦歡錛岄氳繃Axis鐨勭浉鍏沖伐鍏鳳紝鍙互鑷姩浠嶹SDL鏂囦歡涓敓鎴怶eb Service鐨勫鎴風(fēng)浠g爜銆?/p>
銆銆緙栧啓涓涓猈SDL2Java.bat鏂囦歡錛屽叾鍐呭濡備笅錛?/p>
set Axis_Lib=D:\workspace\test\WEB-INF\lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
set Output_Path=D:\workspace\test\src
set Package=server.SayHello
%Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o%Output_Path% -p%Package% SayHello.wsdl
銆銆鎵ц榪欎釜鎵瑰鐞嗘枃浠跺氨鍙互鐢熸垚client stub.
銆銆鐢熸垚鐨剆tub client鏂囦歡鍒楄〃涓猴細(xì)SayHello.java錛孲ayHelloService.java錛孲ayHelloServiceLocator.java錛孲ayHelloSoapBindingStub.java .
銆銆5銆佺紪鍐欏鎴風(fēng)紼嬪簭錛岀紪璇戝茍鎵ц
銆銆涓嬮潰鏄竴孌礿unit嫻嬭瘯瀹㈡埛绔唬鐮併?/p>
import java.net.URL;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class TestWSClient extends TestCase {
public TestWSClient(String string) {
super(string);
}
public void testSayHelloClient() throws Exception {
SayHelloService service = new SayHelloServiceLocator();
SayHello_PortType client = service.getSayHello() ;
String retValue = client.getName("jack");
assertEquals("hello jack", retValue);
}
}
涓夈丼OAP鐩戞帶
SOAP Monitor allows for the monitoring of SOAP requests and responses via
a web browser with Java plug-in 1.3 or higher. For a more comprehensive
explanation of its usage, read Using the
SOAP Monitor in the User's Guide.
By default, the SOAP Monitor is not enabled. The basic steps for enabling
it are compiling the SOAP Monitor java applet, deploying the SOAP Monitor
web service and adding request and response flow definitions for each monitored
web service. In more detail:
- Go to $AXIS_HOME/webapps/axis (or %AXIS_HOME%"webapps"axis)
and compile SOAPMonitorApplet.java.
On Windows
javac -classpath %AXIS_HOME%"lib"axis.jar SOAPMonitorApplet.java
On Unix
javac -classpath $AXIS_HOME/lib/axis.jar SOAPMonitorApplet.java
Copy all resulting class files (i.e. SOAPMonitorApplet*.class) to the root
directory of the web application using the SOAP Monitor
(e.g. .../tomcat/webapps/axis) 榪欎竴姝xis鍋氬ソ浜嗭紝涓嶉渶瑕乧opy浜嗐?/li>
- Deploy the SOAPMonitorService web service with the admin client and the
deploy-monitor.wsdd file (shown below).
Go to the directory deploy-monitor.wsdd is located and execute
the command below. The command assume that /axis is the intended
web application and it is available on port 8080.
On Windows
java -cp %AXISCLASSPATH%
org.apache.axis.client.AdminClient
-lhttp://localhost:8080/axis/services/AdminService deploy-monitor.wsdd
On UNIX
java -cp $AXISCLASSPATH
org.apache.axis.client.AdminClient
-lhttp://localhost:8080/axis/services/AdminService deploy-monitor.wsdd
SOAPMonitorService Deployment Descriptor (deploy-monitor.wsdd)
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler name="soapmonitor"
type="java:org.apache.axis.handlers.SOAPMonitorHandler">
<parameter name="wsdlURL"
value="/axis/SOAPMonitorService-impl.wsdl"/>
<parameter name="namespace"
value="http://tempuri.org/wsdl/2001/12/SOAPMonitorService-impl.wsdl"/>
<parameter name="serviceName" value="SOAPMonitorService"/>
<parameter name="portName" value="Demo"/>
</handler>
<service name="SOAPMonitorService" provider="java:RPC">
<parameter name="allowedMethods" value="publishMessage"/>
<parameter name="className"
value="org.apache.axis.monitor.SOAPMonitorService"/>
<parameter name="scope" value="Application"/>
</service>
</deployment>
- For each service that is to be monitored, add request and response flow definitions
to the service's deployment descriptor and deploy (or redeploy) the service. The
requestFlow and
responseFlow definitions follow the start tag of the
<service> element. If a service is already deployed, undeploy it and deploy
it with the modified deployment descriptor. An example is shown below:
...
<service name="xmltoday-delayed-quotes" provider="java:RPC">
<requestFlow>
<handler type="soapmonitor"/>
</requestFlow>
<responseFlow>
<handler type="soapmonitor"/>
</responseFlow>
...
- With a web browser, go to http[s]://host[:port][/webapp]/SOAPMonitor
(e.g. http://localhost:8080/axis/SOAPMonitor) substituting the correct values
for your web application. This will show the SOAP Monitor applet for viewing service
requests and responses. Any requests to services that have been configured
and deployed correctly should show up in the applet.榪涜涓婇潰鐨勬祴璇曠殑鏃跺欙紝灝卞彲浠ョ湅鍒皉equest鍜宺esponse鐨勫唴瀹廣?/li>
鍥涖佽嚜瀹氫箟綾誨瀷
濡傛灉榪斿洖綾誨瀷涓轟竴涓嚜瀹氫箟綾誨瀷錛?/strong>
import test.Person;
public class SayHello {
public Person getName(String name, int age) {
return new Person(name,age);
}
}
public class Person{
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
閭d箞鍦ㄥ彂甯冪殑鏃跺欙紝灝遍渶瑕佸湪鍙戝竷鏂囦歡涓寚鏄庯細(xì)
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="SayHello" provider="java:RPC">
<requestFlow>
<handler type="soapmonitor"/>
</requestFlow>
<responseFlow>
<handler type="soapmonitor"/>
</responseFlow>
<parameter name="className" value="SayHello"/>
<parameter name="allowedMethods" value="*"/>
</service>
<beanMapping qname="myNS:Person" xmlns:myNS="urn:SayHello" languageSpecificType="java:Person"/>
</deployment>
鐒跺悗灝哖erson綾諱篃copy鍒板簲鐢ㄧ殑classes鏂囦歡涓嬮潰錛岀劧鍚庡皢wsdl鏂囦歡涓嬭澆涓嬫潵錛岃漿鍖栨垚java鏂囦歡錛岃繖鏍瘋皟鐢ㄧ殑鏃跺欏氨鍙互鐩存帴寰楀埌Person瀵硅薄浜嗭細(xì)
public void testSayHelloClient() throws Exception {
SayHelloService service = new SayHelloServiceLocator();
SayHello_PortType client = service.getSayHello() ;
test.Person person = client.getName("jack", 10);
assertEquals("jack", person.getName());
assertEquals(10, person.getAge());
}
浜斻丠andlers and Chains
Now let's start to explore some of the more powerful features of the Axis
engine. Let's say you want to track how many times your service has been
called. We've included a sample handler in the samples/log directory to
do just this. To use a handler class like this, you first need to deploy
the Handler itself, and then use the name that you give it in deploying
a service. Here's a sample deploy.wsdd file (this is example 4 in samples/userguide):
1 <deployment xmlns="http://xml.apache.org/axis/wsdd/"
2
3 xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
4
5 <!-- define the logging handler configuration -->
6 <handler name="track" type="java:samples.userguide.example4.LogHandler">
7 <parameter name="filename" value="MyService.log"/>
8 </handler>
9 <!-- define the service, using the log handler we just defined -->
10 <service name="LogTestService"provider="java:RPC">
11 <requestFlow>
12 <handler type="track"/>
13 </requestFlow>
14 <parameter name="className" value="samples.userguide.example4.Service"/>
15 <parameter name="allowedMethods" value="*"/>
16 </service>
17 </deployment>
The first section defines a Handler called "track" that is implemented
by the class samples.userguide.example4.LogHandler. We give this Handler
an option to let it know which file to write its messages into.
Then we define a service, LogTestService, which is an RPC service just
like we saw above in our first example. The difference is the <requestFlow>
element inside the <service> - this indicates a set of Handlers that
should be invoked when the service is invoked, before the provider. By
inserting a reference to "track", we ensure that the message will be logged
each time this service is invoked.

]]>