Deployment of SOAP services

xiaoxiao2021-03-06  45

Deployment of SOAP services 1. Environment configuration:

(1) Download required resources: Apache soap 2.3 http://apache.linuxForum.Net/dist/ws/soap/Version-2.3.1/soap-bin-2.3.1.zip

(2) Install Apache SOAP: Unzip the SOAP-2.3.1.zip downloaded back to C: / SOAP-2_3_1. Copy the two files under C: / SOAP-2_3_1 / LIB to% Tomcat_Home / Common / Lib; copy the soap.war under C: / SOAP-2_3_1 / WebApps to% Tomcat_Home% / WebApps; Several JAR files (mail.jar, Activation.jar, Xerces.jar) are copied to% tomcat_home% / common / lib under. Set the ClassPath variable: Add the above four JAR file paths to the classpath variable.

% Tomcat_Home% / Common / lib / xerceptimpl.jar% Tomcat_Home% / Common / lib / mail.jar% Tomcat_Home% / common / lib / activation.jar% Tomcat_Home% / common / lib / xml-apis.jar% Tomcat_Home% / CommON / lib / soap.jar Test Client Configuration: 1. Open web browser, access http: // localhost: 8080 / soap / servlet / rpcrouter, if prompted: "Sorry, I don't speak Via HTTP GET- You have to use http post to talk to me, the first step test. 2. Command line test: Enter the command in the command line> Java org.apache.soap.server.serviceManagerClient http: // localhost: 8080 / soap / servlet / rpcrouter List If the output is just "Deployed Services:", no other Any output information, otherwise check if the ClassPath configuration is correct

ClassPath Setup examples are as follows:

% Java_home;% java_home% / lib / dt.jar;% catalina_home% / common / lib / xercesimpl.jar;% catalina_home% / common / lib / mail.jar;% catalina_home% / Common / lib / activation.jar;% catalina_home% / common / lib / xml-apis.jar;% catalina_home% / common / lib / soap.jar; c: /jdom-1.0/build/jdom.jar

2. SOAP server programming:

The simplest part of SOAP is used to implement business functions.

Examples are as follows:

Package xxx;

Import xxx;

Public class helloworldservice {

Public Vector getvector () throws exception {

-------------------

Vector v = new vector ();

---------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------------

Return v;}

}

3. Soap file, that is, the writing of XML files to be deployed:

This is the most disgusting one, combined with the following example

<<< - Deployment Service Name

The name of the deployment is consistent with the method name in the server program.

==================================================== sequencer

XMLns: x = "URN: HelloWorldService" QNAME = "x: java.util.hashmap"

javatype = "java.util.hashmap"

Java2XmlclassName = "org.apache.soap.encoding.soapenc.mapserializer"

Xml2javaclassName = "org.apache.soap.encoding.soapenc.mapserializer" />

This paragraph is used to specify a sequencer for a special data structure, such as the Map sequencer is MapSerializer, and the vector is VECTORSERIALIZER. This step is very important. If you are not set properly, the client may not get the return value.

4. Soap client program:

Package xxx;

Import xxx;

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;

// Declare the path to the SOAP service loader

URL URL = New URL (Endpoint);

/ / Register a sequencer of a special data type, which is consistent with the deployed XML file

SOAPMAPPINGREGISTRY SMR = new soapmappingregistry (); // beanserializer beanser = new beanserializer ();

MapSerializer Mapser = new mapserializer ();

// VectorSerializer Vecser = new vectorserializer ();

SMR.MAPTYPES (constants.ns_uri_soap_enc, new qname (NEW QNAME)

"URN: HelloWorldService", "java.util.hashmap", java.util.hashmap.class,

Mapser, Mapser);

// build the soap rpc request message using the call object

// Use Call to create a client application information

Call call = new call ();

Call.SetsoapMappingRegistry (SMR);

Call.SetTargetObjecturi ("URN: HelloWorldService);

Call.SetMethodName ("GetVector");

Call.setencodingstyleuri (constants.ns_uri_soap_enc);

// send the soap rpc request message using invoke () Method

// Submit an application using the invoke () method, return response

Response response

Try {

Resp = Call.Invoke (URL, ");

} catch (soapexception e) {

System.err.println ("CAUGHT SOAPEXCEPTION (" E.GetFaultcode ()

"):" E.getMessage ());

Return;

}

// Check The Response.

if (Resp.GeneratedFault ()) {// error occurred

// If an error occurs, use the following method to get an error message

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

// If the corresponding information is successfully received, use the following method to get

Parameter Result = Resp.getReturnValue ();

Vector = (Vector) Result.getValue ();

}

}

}

5. Deployment method of service,

Put the server-side program and deployment files in Tomcat-5.0.28 / Common / Classes, if there is a package, the server-side program is placed in the corresponding package.

Start command prompt cmd

CD / d c: /tomcat-5.0.28/common/classes

C: / Tomcat-5.0.28/Common/Classes

Java org.apache.soap.server.serviceManagerClient http: // localhost: 8080 / soap / servlet / rpcrouter Deploy HelloWorld.xml can also write these commands to a * .cmd file

Finally, perform your client program, complete

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

New Post(0)