Cordys BOP 4 Platform Development Practical Walkthrough--webservices Development (using MONGODB database)

Source: Internet
Author: User
Tags soap mongoclient

1. Create a new custom class "C_mongopackage" in the Ws-appserver package



2. Add a custom method Method,expanddocument and Finddocuments two methods.


3, the method sets two parameters, respectively is CollectionName and jsonstring.


4. Java code generated by the system


5, pop up the following "Generate Java Code on ws-appserver Models" window.


6, by the system production WebService


7, eject generate WebService Interface on ws-appserver models window.


Next, publish the Java code and webservice separately.


8, Upload MongoDB Java driver package to the platform on the system.


9, add Java program dependent jar package, mouse double-click "Xiaoywwsappserverpackage" package under Java file, pop "ws-appserver java Archive definiton" window, in "Dependencies "page, add the jar package via" + ". This jar package is selected from the Mogo-java-driver-2.12.4.jar file in Jarlib.


10, the system generated Java code upload SVN.


11. Synchronize the code into the Eclipse project.


12. In Eclipse, complete the following code

Package com.unicom.xiaoywwsappserverpackage;

Import Com.cordys.cpc.bsf.busobject.BusObjectConfig;

Import Com.cordys.cpc.bsf.busobject.BusObjectIterator;
Import Com.mongodb.BasicDBObject;
Import Com.mongodb.DB;
Import com.mongodb.DBCollection;
Import Com.mongodb.DBObject;
Import com.mongodb.MongoClient;
Import Com.mongodb.MongoClientURI;
Import Com.mongodb.util.JSON;


public class C_mongopackage extends C_mongopackagebase

{

......

Input parameters, CollectionName: Document name, JSONSTRING:MONGODB recognized JSON data format data string

public static void Expanddocument (String collectionname, String jsonstring)
{
DB db = null;


try {
Mongoclienturi uri = new Mongoclienturi ("Mongodb://username:[email protected]:27017/dbname");

Username: Database user name, password: password, dbname: database name


Mongoclient client = new Mongoclient (URI);

db = Client.getdb (dbname);

Dbcollection collection = Db.getcollection (CollectionName);

DBObject query = (basicdbobject) json.parse (jsonstring);

Collection.save (query);
} catch (Exception e) {
E.printstacktrace ();
} finally{
if (db!=null) {
try{
Db.requestdone ();
Db=null;
}catch (Exception e) {

E.printstacktrace ();

}
}
}

}

13, in Eclipse, through Team-> submitted to the platform, and then "Java-publish to Organization", compile the release code to use in the platform.

14. The test interface is as follows:


<soap:envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP:Body>
<expanddocument xmlns= "Http://schemas.cordys.com/XiaoywWSAppServerPackage" preservespace= "no" qaccess= "0" Qvalues= "" >
<collectionName>BusinessEntity</collectionName>
<jsonstring>{"ID": "2015040010", "Name": "Procurement Process", "Dept": "Management Department"}</jsonstring>
</ExpandDocument>
</SOAP:Body>
</SOAP:Envelope>

15. The database Insert results are as follows:



Cordys BOP 4 Platform Development Practical Walkthrough--webservices Development (using MONGODB database)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.