Apache SOAP2.3 - Run HelloWorld Service
Sending station: BBS Shuimu Tsinghua Station (MON OCT 20 17:11:14 2003)
Install Apache SOAP
Download required resources:
Apache soap 2.3 http://apache.linuxforum.net/dist/ws/soap/Version-2.3.1/soa
P-bin-2.3.1.zip
Mail.jar from javamail http://java.sun.com/products/javamail
Activation.jar from javabeans activation framework http://java.sun.com/prod
UCTS / Beans / Glasgow / Jaf.html
A jaxp compatible, namespace-aware XML Parser Such As Apache Xerces (V1.1.2
Or Later http://xml.apache.org/xerces-j
Tomcat 4.1.x http://jakarta.apache.org/tomcat
Install Tomcat:
There are many articles introduced online, and details will not be described here.
Install Apache SOAP:
Unzip the SOAP-2.3.1.zip from the download back to C: / SOAP-2_3_1. Two of C: / SOAP-2_3_1 / LIB
Document copy to% tomcat_home% / common / lib; put C: / SOAP-2_3_1 / WebApps soap.war
Copy to% tomcat_home% / WebApps; put other few JAR files (mail.jar, Activation.jar, X
Ercept.jar) Copy it below% Tomcat_Home% / Common / Lib.
Set the ClassPath variable:
Add the above four JAR file paths to the ClassPath variable
% Tomcat_Home% / Common / Lib / SOAP.jar
% Tomcat_Home% / Common / Lib / Mail.jar
% Tomcat_Home% / Common / Lib / Activation.jar
% Tomcat_Home% / Common / lib / Xerces.jar
PS: My approach is to synthesize these four JAR files a soap-all.jar file, and do not path to CLAS
Spa in spath, so you can save.
Test client configuration:
1. Open web browser, visit http://127.0.0.1:8080/soap/servlet/rpcrouter, if
Tip: "Sorry, I don't speak Via http get- you have to use http post to tal
K to Me ", the first test passed.
2. Command line test: Enter the following command on the command line
> java org.apache.soap.server.serviceManagerClient http://127.0.0.1:808
0 / soap / servlet / rpcrouter List
If the output is just "Deployed Services:", no other output information is obtained, otherwise check
ClassPath configuration is correct
Run HelloWorldService service
HelloWorldService.java
_________________________________
Public Class HelloWorldService
{
String getMessage ()
{
Return "Hello World!";
}
}
________________________________ created a deployment descriptor:
The deployment descriptor is actually an XML file. When the SOAP request is sent to org.apache.soap.server.htt
When the P.rpcrouterServlet, the RPCRouterServlet uses the deployment descriptor to decide where to route the request. under
The command line tool registration service with Apache SOAP will be described.
HelloWorld.xml
---------------------------------
XML Version = "1.0"?>
isd: provider>
ISD: Service>
---------------------------------
Register:
Enter the command line (note to the directory where the HelloWorldService.xml file is located)
> Java org.apache.soap.server.serviceManagerClient http://127.0.0.1:8080/so
AP / servlet / rpcrouter Deploy HelloWorld.xml
If there is no error message, the registration is successful, you can use the following commands to view the registered service
> Java org.apache.soap.server.serviceManagerClient http://127.0.0.1:8080/so
AP / servlet / rpcrouter List
A prompt "deployed services: URN: HelloWorldService"
Logout service:
> Java org.apache.soap.server.serviceManagerClient http://127.0.0.1:8080/so
AP / servlet / rpcrouter Undelpoy "URN: HelloWorldService"
You can also query service properties:
> Java org.apache.soap.server.serviceManagerClient http://127.0.0.1:8080/so
AP / servlet / rpcrouter Query "URN: HelloWorldService"
HelloWorld service client
HelloWorldClient.java
_______________________
Import org.apache.soap.constants;
Import java.net.URL;
Import org.apache.soap.fault;
Import org.apache.soap.rpc.call;
Import org.apache.soap.rpc.response;
Import org.apache.soap.rpc.parameter;
Public class helloworldclient {
Static string default_endpoint = "http: // localhost: 8080 / soap / servlet / rpcrouter";
Public static void main (string args []) throws exception {
String endpoint = default_endpoint;
// Process Arguments
IF (args.length == 1)
Endpoint = args [0];
Else IF (args.length> 1)
System.out.Println ("Java HelloWorldClient [endpoint]");
// build the soap rpc request message using the call object
Call call = new call ();
Call.SetTargetObjecturi ("URN: HelloWorldService);
Call.SetMethodName ("getMessage");
Call.setencodingstyleuri (constants.ns_uri_soap_enc);
// Create a URL Object, Which Repesents the endpoint
URL URL = New URL (Endpoint);
// send the soap rpc request message using invoke () Method
Response Resp = CALL.INVOKE (URL, ");
// Check The Response.
if (Resp.GeneratedFault ()) {// error Occured
Fault fault = resp.getfault ();
System.out.println ("The Following Error Occured);
System.out.println ("Fault Code =" Fault.getFault ());
System.out.println ("Fault String =" Fault.getFaultString ());
} Else {// Completed SuccessFully
Parameter Result = Resp.getReturnValue ();
System.out.println (Result.getValue ());
}
}
}
-----------------------------------------------
Run service:
First pack the helloWorldService.class to the JAR file to put it until the% Tomcat_Home% / Common / LIB or
Put the helloWorldService.class directly to the% Tomcat_Home% / Common / Classes
Register the service according to the method described above, then run the HelloWorldClient, the screen output "HelloWorld!"