Use AXIS to implement DSMP SyncORDERRELATION service interface [turn BON

xiaoxiao2021-03-05  25

SyncOrderRelation is one of the service interfaces that SP must be implemented in the DSMP specification. The interface of the DSMP specification uses WebService as a communication method, and the specification specifies the binding style of SOAP1.2's Document and Litral's encoding method.

AXIS is an Apache's SOAP (Simple Object Access Protocol). It is currently using a relatively wide WebService implementation, and a few a few of the good implementation of Document / Literal support.

Here I will demonstrate the Demo of the SyncOrderRelation interface using Apache's AXIS toolkit. The specific definition of SyncORDERRELATION already exists in DSMP, which cannot be used to develop a defined manner in the code in the code. It is developed by WSDL generation code.

1. WSDL definition of SyncOrderRelation

SyncOrderRelation is part of DSMP, I now just extract it from DSMP to form a separate file: syncorderRelation.wsdl, the specific content is as follows:

XMLns: ws = "http://www.monternet.com/dsmp/wsdl/" xmlns: soap = "http://schemas.xmlsoap.org/wsdl/soap/" XMLns: XSD = "http: // www .w3.org / 2001 / xmlschema "xmlns: wsdl =" http://schemas.xmlsoap.ort/wsdl/ "

XMLns = "http://schemas.xmlsoap.org/wsdl/" XMLns: sopenc = "http://schemas.xmlsoap.org/soap/encoding/" XMLns: dsmp = "http://www.monternet.com / dsmp / schema / "targetnamespace =" http://www.monternet.com/dsmp/wsdl/ ">

Targetnamespace = http://www.monternet.com/dsmp/schemas/ xmlns: soap-env = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: sopenc = "http: //schemas.xmlsoap .org / soap / encoding / "xmlns: xsi =" http://www.w3.org/2001/xmlschema-instance "XMLns: xsd =" http://www.w3.org/2001/xmlschema "XMLns = "http://www.w3.org/2001/xmlschema"

ElementFormDefault = "unqualified" AttributeFormDefault = "unqualified">

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

Namespace = "http://www.monternet.com/dsmp/schemas/ />

EncodingStyle = "http://schemas.xmlsoap.org/soap/encoding" namespace = "http://www.monternet.com/dsmp/schemas/ />

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

Namespace = "http://www.monternet.com/dsmp/schemas/ />

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

Namespace = "http://www.monternet.com/dsmp/schemas/ />

The definition of Service is related to specific implementation environments, just replacing LOCATION as the URI of your environment in your environment.

2. Preparation for developing operational environments

My development environment is:

OS: RedHat 9.0 (kernel 2.4.20)

Webserver: Tomcat 4.1.30

Java: J2SDK1.5.0

Axis1.1

I will install Tomcat and Axis in the user's Home directory environment variable is:

Tomcat_home = $ home / jakarta-tomcat-4.1.30

Axis_home = $ home / axis-1_1

After installing Tomcat and AXIS, you need to integrate AXIS with tomcat. This step is very simple, you will complete the AXIS_HOME / WebApps to $ Tomcat_home / WebApps, then start Tomcat to verify, in me After IE Open http://10.1.3.107:9001/AXIS, you can see the verification result. After the verification is successful, you have to prepare the ClassPath for development, I am related to AXIS ClassPath is placed in a separate environment variable.

Axisclasspath = $ AXIS_HOME / LIB / AXIS. JAR: $ AXIS_HOME / LIB /COMMONS-DISCOVERY.JAR: $ AXIS_HOME / LIB /COMMONS-LOGGING.JAR: $ AXIS_HOME / LIB /JAXRPC.JAR: $ Daxis_Lib/saaj.jar: $ AXIS_HOME / LIB /LOG4J-1.2.8.JAR: $ AXIS_HOME / lib / xml-apis.jar: $ AXIS_HOME / LIB /XERCESIMPL.JAR: $ AXIS_HOS_HOU / LIB /WSDL4J.JAR; Export AxisclassPath

3. Generate code

The environment is finally organized, and it is now possible to start coding. It is actually not available.

a. First use WSDL2JAVA from SyncOrderRelation to generate code

transfer

Java -cp $ AXISCLASSPATH org.apache.axis.wsdl.wsdl2java -s syncorderRelation

WSDL2JAVA has created a basic code for us, and a COM directory in the development directory, this is the directory where the code exists. We only need to add it in ./com/monternet/www/dsmpl.java Add

Our business handles the code.

b. Adding TransactionID support

Let's take a look at MaportBindingImp1.java:

/ **

* MaportBindingImpl.java

*

* This file Was auto-generated from WSDL

* by the apache axis wsdl2java emitter.

* /

Package com.monternet.www.dsmp.wsdl;

Public class maportbindingImpl imports com.monternet.www.dsmp.wsdl.maport

{

Public com.monternet.www.dsmp.schemas.syncorderReranceResPTYPE

SyncorderRelation (com.monternet.www.dsmp.schemas.syncorderReranceReqType

SyncorderReranceInput)

Throws Java.rmi.RemoteException

{

Return NULL;

}

}

The SyncOrderRelation function is where we will add functional features. But before adding a function, I have to add the support of the TransactionId SOAP Header required by DSMP, and AXIS does not do this for us. So we have to add a generation of TRANSACTIONID. The code added is as follows

Package com.monternet.www.dsmp.wsdl;

Import org.apache.axis.message. *;

Import org.apache.axis. *;

Public class maportbindingImpl imports com.monternet.www.dsmp.wsdl.maport

{

Public com.monternet.www.dsmp.schemas.syncorderReranceResptypeSyncorderRelation (com.monternet.www.dsmp.schemas.syncorderReLanceReqType)

SyncorderReranceInput)

Throws Java.rmi.RemoteException

{

String TransactionId = GetTransactionId ();

// Business related code

SetTransactionId (TransactionID);

Return NULL;

}

Public string getTransactionId () throws Axisfault

{

MessageContext CTX = Org.apache.Axis.MessageContext.getCurrentContext ();

SOAPENVELOPE ENV = ctx.getRequestMessage (). Getsoapenvelope ();

SoapHeadeRelement soapHeadeRelement =

Env.getheaderbyName ("http://www.monternet.com/dsmp/schemas/",

"TransactionID");

Return (String) soapHeadelement.getObjectValue ();

}

Public void setTransactionId (String Transid) Throws Axisfault

{

MessageContext CTX = Org.apache.Axis.MessageContext.getCurrentContext ();

SOAPENVELOPE ENV = ctx.getResponseMessage (). Getsorapenvelope ();

SOAPHEADERELEMENT HeadeRelement =

New soapHeadelelement ("http://www.monternet.com/dsmp/schemas/",

"TransactionID", Transid;

Env.addheader (HeadeRelement);

}

}

In the above, I added two functions, GetTransactionId acquired RequestMessage from MersSageContext, and set TRANSACTIONID to ResponseMessage to add TransactionID.

c. Write a business code

Since this is just a demo, there is no specific business implementation, just return 9001 (system busy) response, the code is as follows:

Public com.monternet.www.dsmp.schemas.syncorderReranceResPTYPE

SyncorderRelation (com.monternet.www.dsmp.schemas.syncorderReranceReqType

SyncorderReranceInput)

Throws Java.rmi.RemoteException

{

String TransactionId = GetTransactionId ();

Response.setVersion (SyncOrderReranceInput.getVersion ());

Response.SETMSGTYPE (New String ("SyncorderReranceResp");

Response.sethret (New Biginteger ("9001"));

SetTransactionId (TransactionID);

Return Response;}

4. Compile and release

First create a build directory in the development directory, as follows

Mkdir Build

Compile the Java code after soft:

Javac-cp $ AXISCLASSPATH: ./ build -d build ./com/monternet/www/dsmp/schemas/*.java

Javac-cp $ AXISCLASSPATH: ./ build -d build ./com/monternet/www/dsmp/wsdl/*.java

After successful compilation, it will be released.

Release is divided into two steps:

Copy the code from build / down to $ TOMCAT_HOME / WebApps / Axis / Web-INF / CLASSES and then call AXIS published commands

Java -cp $ apisclasspath org.apache.axis.client.adminClient -h 10.1.3.107 -p 9001./com/MonterNet/www/dsmp/wsdl/deploy.wsdd

If everything goes well, you can properly handle the DSMP's order relationship synchronization package.

5. This is just a simple implementation method of a Java version. If C / C used can use AXIS's C version, you can simply implement the webservice.

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

New Post(0)