Making the Service

This chapter describes the Service for Server which is used at the XPLATFORM application.
The XPLATFORM program uses the function of transaction() when the data input at the Form is sent. The function of Transaction() transforms Variable and Dataset that are input to XML Format and send to JSP Service of Server. 
The result value for JSP Service can be checked through the arguments of ErrorCode, ErrorMsg at the Callback function which is registered at calling transaction().
Service for Server can be prepared not only with JSP but also with the languages like Java Servlet, ASP, ASP.NET, PHP, etc. In this example, the method to manage the data which receives the input at the Form by using USP is described.
The prepared JSP Service can’t be tested through the web browser because Variable and Dataset are used as parameter and through the web browser, this parameter can’t be sent to the server.

In this example, XML Format Data which is delivered to JSP can be analyzed by using other Parsers not by using XPLATFORM library (XPLATFORM X-API). But with XPLATFORM X-API, the program can be prepared more easily because the unnecessary analysis work is not need to be implemented.

Using any kinds of languages and servers are ok for making XML Data used at XPLATFORM if the XML regulations are observed.

the Example of the server composition used in general

The preparation language for Service: Java series(Java Servlet, JSP), ASP series(ASP, ASP.NET)

Web server : Apache, web server included in WAS

Database : Oracle, MS SQLServer, Sybase, DB2

WAS(Web Application Server) : WebLogic, WebSphere, JEUS, Tomcat, Resin

When the Server request service is prepared, UX-Studio is not used but the general web editors (eclipse, Visual Studio .NET, Notepad …) are used.

In this example, the execution at Tomcat by using JSP is implemented.

Description of Services

In order to execute the XPLATFORM application for demo, the following three services for Server are required:

Service for the initial data generation– initdata.jsp

// 1.Library import (including XPLATFORM X-API)
// 2.Definition of Mime Type 
// 3.Generation of basic object for XPLATFORM (PlatformData) 
try {
	// 5.Data handling
	// 6.ErrorCode and ErrorMsg handling (success message)
} Catch (error) {
	// 6.ErrorCode and ErrorMsg handling (fail message)
}
// 7.sending the result data to the Client
<!-- 1.library import -->
<%@ page import="java.io.*" %>
<%@ page import="com.tobesoft.xplatform.data.*" %>
<%@ page import="com.tobesoft.xplatform.tx.*" %>

<!-- 2. mime type define -->
<%@ page contentType="text/xml; charset=UTF-8" %>

<%
/** 3.XPLATFORM Basic Object creation **/
PlatformData pdata = new PlatformData();

/** ErrorCode, ErrorMsg creation **/
int nErrorCode = 0;
String strErrorMsg = "START";

try {
	/** 4. receive client request **/
	// not need to receive

	/** 5. handle data : save data to file **/
	/** 5.1 create Dataset and input basic data to the Dataset **/
	DataSet ds = new DataSet("dsPerson");
	ds.addColumn("pid",DataTypes.INT);
	ds.addColumn("person_name",DataTypes.STRING, 8);
	ds.addColumn("home_telno", DataTypes.STRING, 8);
	ds.addColumn("home_address", DataTypes.STRING, 16);
	ds.addColumn("company", DataTypes.STRING, 8);
	ds.addColumn("company_telno", DataTypes.STRING, 8);
	ds.addColumn("company_fax", DataTypes.STRING, 8);
	ds.addColumn("company_address", DataTypes.STRING, 8);
	ds.addColumn("email", DataTypes.STRING, 8);
	ds.addColumn("mobile", DataTypes.STRING, 8);
	ds.addColumn("jikgub", DataTypes.STRING, 8);
	ds.addColumn("dept", DataTypes.STRING, 8);
	ds.addColumn("remark", DataTypes.STRING, 8);

	int row = 0;
	int i = 0;
	String[] names = new String[2];
	String[] tel1 = new String[2];
	String[] tel2 = new String[2];
	String[] tel3 = new String[2];
	String[] tel4 = new String[2];
	String[] address = new String[2];
	String[] company = new String[2];
	String[] email = new String[2];

	names[0] = "Steven";
	names[1] = "Charls";
	email[0] = "Steven@hp.com";
	email[1] = "Charls@dell.com";
	address[0] = "NewYork City";
	address[1] = "Manhattan City";
	company[0] = "HP";
	company[1] = "Dell";
	homepage[1] = "www.dell.com";
	tel1[0] = "02-123-4567";
	tel1[1] = "02-321-7654";
	tel2[0] = "02-987-6543";
	tel2[1] = "02-789-3456";
	tel3[0] = "02-456-7890";
	tel3[1] = "02-654-0987";
	tel4[0] = "010-1234-7890";
	tel4[1] = "010-4321-0987";

	for (i = 0; i < 2; i++)
	{
		row = ds.newRow(); 
		ds.set(row,"pid",i);
		ds.set(row,"person_name",names[i]);
		ds.set(row,"home_telno",tel1[i]);
		ds.set(row,"home_address",address[i]);
		ds.set(row,"company",company[i]);
		ds.set(row,"company_telno",tel2[i]);
		ds.set(row,"company_fax",tel3[i]);
		ds.set(row,"company_address",address[i]);
		ds.set(row,"email",email[i]);
		ds.set(row,"mobile",tel4[i]);
		ds.set(row,"jikgub","0" + (i + 1));
		ds.set(row,"dept","0" + (i + 1));
		ds.set(row,"remark",i);
	}

	pdata.addDataSet(ds);

	/** 5.2 save Dataset to a file **/
	String targetFilename = "./saveFile.bin";
	OutputStream target = new FileOutputStream(targetFilename);
	PlatformResponse res = new PlatformResponse(target, 
	PlatformType.CONTENT_TYPE_BINARY);
	res.setData(pdata);
	res.sendData();
	target.close(); 
	System.out.println("after file write.."); 

	/** 6.1 set the ErrorCode and ErrorMsg about success**/
	nErrorCode = 0;
	strErrorMsg = "SUCC";

} catch (Throwable th) {
	/** 6.2 set the ErrorCode and ErrorMsg about fail **/
	nErrorCode = -1;
	strErrorMsg = th.getMessage();
}

/** 6.3 save the ErrorCode and ErrorMsg for sending Client **/
PlatformData senddata = new PlatformData();
VariableList varList = senddata.getVariableList();
varList.add("ErrorCode", nErrorCode);
varList.add("ErrorMsg", strErrorMsg);

/** 7. send the result data to Client **/
HttpPlatformResponse res = new HttpPlatformResponse(response, 
PlatformType.CONTENT_TYPE_XML,"UTF-8");
res.setData(senddata);
res.sendData();
%>

Java Library import

In order to prepare JSP service, import basic library for java.
Observe the Format which XPLATFORM uses when XML Data is generated.
For XML Format Data, Parser which is commercialized like “xerces” can be used or it is ok to use the user’s direct implementation. 
But with the library (XPLATFORM X-API) for XPLATFORM java which makes its own object for XPLATFORM and uses, the data can be extracted easily by using the function of the object without parsing XML Data Format separately.
The cord which imports XPLATFORM X-API and the basic object for java is as follows:.
<!-- 1.library import -->
<%@ page import="java.io.*" %>
<%@ page import="com.tobesoft.xplatform.data.*" %>
<%@ page import="com.tobesoft.xplatform.tx.*" %>

XPLATFORM XAPI Installation

XPLATFORM library(XPLATFORM XAPI) is composed with the file of xplatform-xapi-1.0.jar, commons-logging-1.1.1.jar and is provided at the purchase of XPLATFORM or will be provided through the technical support site of TOBESOFT Ltd. (http://www.miplatform.co.kr).


The only objects used at the connected library are as follows:

Definition of mime type

Define mime type for the XML generation

<!-- 2. mime type define -->
<%@ page contentType="text/xml; charset=UTF-8" %>

Generating the Basic Object for XPLATFORM (PlatformData)

Declare the basic object for XPLATFORM to handle data.
PlatformData which is the basic object is the one that can contain all the data (Datasets and Variables) which are used at the XPLATFORM application all together.
The codes that declare PlatformData are as follows:
/** 3.XPLATFORM Basic Object creation **/
PlatformData pdata = new PlatformData();

Generating Dataset and then Saving to the File

Generate Dataset, input the information about column. Generate two rows and then input columns to each row.
Register the generated DataSet to PlatformData in order to make i/o convenient.
By using the PlatformData object, save it to the ./saveFile.bin”file.

The codes that generate Dataset and save to File are as follows:

/** 5. handle data : save data to file **/
/** 5.1 create Dataset and input basic data to the Dataset **/
DataSet ds = new DataSet("dsPerson");
ds.addColumn("pid",DataTypes.INT);
ds.addColumn("person_name",DataTypes.STRING, 8);
ds.addColumn("home_telno", DataTypes.STRING, 8);
ds.addColumn("home_address", DataTypes.STRING, 16);
ds.addColumn("company", DataTypes.STRING, 8);
ds.addColumn("company_telno", DataTypes.STRING, 8);
ds.addColumn("company_fax", DataTypes.STRING, 8);
ds.addColumn("company_address", DataTypes.STRING, 8);
ds.addColumn("email", DataTypes.STRING, 8);
ds.addColumn("mobile", DataTypes.STRING, 8);
ds.addColumn("jikgub", DataTypes.STRING, 8);
ds.addColumn("dept", DataTypes.STRING, 8);
ds.addColumn("remark", DataTypes.STRING, 8);

int row = 0;
int i = 0;
String[] names = new String[2];
String[] tel1 = new String[2];
String[] tel2 = new String[2];
String[] tel3 = new String[2];
String[] tel4 = new String[2];
String[] address = new String[2];
String[] company = new String[2];
String[] email = new String[2];

names[0] = "Steven";
names[1] = "Charls";
email[0] = "Steven@hp.com";
email[1] = "Charls@dell.com";
address[0] = "NewYork City";
address[1] = "Manhattan City";
company[0] = "HP";
company[1] = "Dell";
tel1[0] = "02-123-4567";
tel1[1] = "02-321-7654";
tel2[0] = "02-987-6543";
tel2[1] = "02-789-3456";
tel3[0] = "02-456-7890";
tel3[1] = "02-654-0987";
tel4[0] = "010-1234-7890";
tel4[1] = "010-4321-0987";

for (i = 0; i < 2; i++)
{
	row = ds.newRow(); 
	ds.set(row,"pid",i);
	ds.set(row,"person_name",names[i]);
	ds.set(row,"home_telno",tel1[i]);
	ds.set(row,"home_address",address[i]);
	ds.set(row,"company",company[i]);
	ds.set(row,"company_telno",tel2[i]);
	ds.set(row,"company_fax",tel3[i]);
	ds.set(row,"company_address",address[i]);
	ds.set(row,"email",email[i]);
	ds.set(row,"mobile",tel4[i]);
	ds.set(row,"jikgub","0" + (i + 1));
	ds.set(row,"dept","0" + (i + 1));
	ds.set(row,"remark",i);
}

pdata.addDataSet(ds);

/** 5.2 save Dataset to a file **/
String targetFilename = "./saveFile.bin";
OutputStream target = new FileOutputStream(targetFilename);
PlatformResponse res = new PlatformResponse(target, 
PlatformType.CONTENT_TYPE_BINARY);
res.setData(pdata);
res.sendData();
target.close();

Handling ErrorCode and ErrorMsg

With the above process, the handling of the basic data is implemented.
But since there is a possibility for the exceptional situations, when there is an error, the followings are recommended for handling the error part:
/** 6.1 ErrorCode, ErrorMsg creation **/
int nErrorCode = 0;
String strErrorMsg = "START";
try {
	/** 5. handle data : save data to file **/
	/** 6.2 set the ErrorCode and ErrorMsg about success**/
	nErrorCode = 0;
	strErrorMsg = "SUCC";
} catch (Throwable th) {
	/** 6.3 set the ErrorCode and ErrorMsg about fail **/
	nErrorCode = -1;
	strErrorMsg = th.getMessage();
}
/** 6.4 save the ErrorCode and ErrorMsg for sending Client **/
PlatformData senddata = new PlatformData();
VariableList varList = senddata.getVariableList();
varList.add("ErrorCode", nErrorCode);
varList.add("ErrorMsg", strErrorMsg);

Sending the result value to Client

The PlatformData object is used to deliver to the client whether the initial value is saved at the file normally or not. At this time, ErrorCode and ErrorMsg which were previously saved are delivered to the Client.

Since VariableList is a member of PlatformData, the result value for the JSP performance is in the object of PlatformData. Now, try to implement the part which extracts and sends the data of PlatformData from XML Format which is recognized by XPLATFORM. In order to make the function to send data implemented easily, the codes that make the PlatformResponse object for the XPLATFORM library and output data from PlatformData are as follows:

/** 7. Send the result data to Client **/
HttpPlatformResponse res = new HttpPlatformResponse(response, PlatformType.CONTENT_TYPE_XML,"UTF-8");
res.setData(senddata);
res.sendData();

Query Service – search.jsp

// 1.Library import (including XPLATFORM X-API)
// 2.Definition of Mime Type 
// 3.Generation of the basic object for XPLATFORM (PlatformData) 
try {
	// 5.Data handling
	// 6.Handling of ErrorCode and ErrorMsg (success message)
} Catch (error) {
	// 6.Handling of ErrorCode and ErrorMsg (failure message)
}
7.sending the result Data to the Client
<!-- 1.library import -->
<%@ page import="java.io.*" %>
<%@ page import="com.tobesoft.xplatform.data.*" %>
<%@ page import="com.tobesoft.xplatform.tx.*" %>
 
<!-- 2. mime type define -->
<%@ page contentType="text/xml; charset=UTF-8" %>
<%
/** 3.XPLATFORM Basic Object creation **/
PlatformData readdata = new PlatformData();
 
/** 6.1 ErrorCode, ErrorMsg creation **/
int nErrorCode = 0;
String strErrorMsg = "START";
 
try {
	/** 4. receive client request **/
	// not need to receive
 
	/** 5. handle data : load data from file **/
	/** 5.1 load data from file **/
	String sourceFilename = "./saveFile.bin";;
	InputStream source = new FileInputStream(sourceFilename);
 
	PlatformRequest req = new PlatformRequest(source, PlatformType.CONTENT_TYPE_BINARY);
	req.receiveData();
	source.close();
 
	/** 5.1 copy data from loaded data to Dataset **/
	readdata = req.getData();
 
	/** 6.2 set the ErrorCode and ErrorMsg about success**/
	nErrorCode = 0;
	strErrorMsg = "SUCC";
 
} catch (Throwable th) {
	/** 6.3 set the ErrorCode and ErrorMsg about fail **/
	nErrorCode = -1;
	strErrorMsg = th.getMessage();
}
 
/** 6.4 save the ErrorCode and ErrorMsg for sending Client **/
VariableList varList = readdata.getVariableList();
varList.add("ErrorCode", nErrorCode);
varList.add("ErrorMsg", strErrorMsg);

/** 7. send the result data to Client **/
HttpPlatformResponse res = new HttpPlatformResponse(response, PlatformType.CONTENT_TYPE_XML,"UTF-8");
res.setData(readdata);
res.sendData();
%>

Java Library import

It is the same as that in “Java Library import”.

Definition of mime type

It is the same as that in “Definition of mime type”.

Generating the basic object for XPLATFORM (PlatformData)

It is the same as that in “Generating the Basic Object for XPLATFORM (PlatformData)

Generating Dataset by reading the contents of the File Dataset

Read the contents of the file, “./saveFile.bin” and save them at the PlatformData object. In this PlatformData object, Dataset is placed.

The codes that read the File and place them on PlatformData are as follows:

/** 5. handle data : load data from file **/
/** 5.1 load data from file **/
String sourceFilename = "./saveFile.bin";
InputStream source = new FileInputStream(sourceFilename);

PlatformRequest req = new PlatformRequest(source, 
PlatformType.CONTENT_TYPE_BINARY);
req.receiveData();
source.close();

/** 5.2 copy data from loaded data to Dataset **/
pdata = req.getData();

Handling of Errorcode and ErrorMsg

It is the same as that in “Handling ErrorCode and ErrorMsg”.

Sending the result value to the Client

The contents of the JSP code are the same as those in “Sending the result value to Client”. 
But their meanings are different. The PlatformData object used at “Sending the result value to Client” includes only ErrorCode and ErrorMsg but PlatformData in this chapter contains the Dataset of the card list used by the Client.
This Dataset is contained automatically during the execution of the code in “Handling of Errorcode and ErrorMsg”.

Save Service – save_list.jsp

// 1.Library import (XPLATFORM X-API포함)
// 2.Definition of Mime Type 
// 3.Generation of the basic object for XPLATFORM (PlatformData) 
try {
	// 4.Receiving the Client’s requirements
	// 5.Data Handling
	// 6.Handling of ErrorCode and ErrorMsg (success message)
} Catch (error) {
	// 6.Handling of ErrorCode and ErrorMsg (failure message)
}
7.Sending the result data to the Client
<!-- 1.library import -->
<%@ page import="java.io.*" %>
<%@ page import="com.tobesoft.xplatform.data.*" %>
<%@ page import="com.tobesoft.xplatform.tx.*" %>

<!-- 2. mime type define -->
<%@ page contentType="text/xml; charset=UTF-8" %>

<%
/** 3.XPLATFORM Basic Object creation **/
PlatformData pdata = new PlatformData();

/** 6.1 ErrorCode, ErrorMsg creation **/
int nErrorCode = 0;
String strErrorMsg = "START";

try {
	/** 4. receive client request **/
	// create HttpPlatformRequest for receive data from client
	HttpPlatformRequest req = new HttpPlatformRequest(request);
	req.receiveData();
	/** 5. handle data : load data from file **/
	/** 5.1 load data from http object **/ 
	pdata = req.getData();

	/** get Dataset from received data **/
	DataSet ds = pdata.getDataSet("dsPerson");

	/** save data to file with init data **/
	String targetFilename = "./saveFile.bin";
	OutputStream target = new FileOutputStream(targetFilename);
	PlatformResponse res = new PlatformResponse(target, 
		PlatformType.CONTENT_TYPE_BINARY);
	res.setData(pdata);
	res.sendData();
	target.close(); 

	/** 6.2 set the ErrorCode and ErrorMsg about success **/
	nErrorCode = 0;
	strErrorMsg = "person list saved complete : row count("+ds.getRowCount()+")";

} catch (Throwable th) {
	/** 6.3 set the ErrorCode and ErrorMsg about fail **/
	nErrorCode = -1;
	strErrorMsg = th.getMessage();
	System.out.println("ERROR:"+strErrorMsg); 
}
/** 6.4 save the ErrorCode and ErrorMsg for sending Client **/
PlatformData senddata = new PlatformData();
VariableList varList = senddata.getVariableList();
varList.add("ErrorCode", nErrorCode);
varList.add("ErrorMsg", strErrorMsg);
/** 7. send the result data to Client **/
HttpPlatformResponse res = new HttpPlatformResponse(response, PlatformType.CONTENT_TYPE_XML,"UTF-8");
res.setData(senddata);
res.sendData();
%>

Java Library import

It is the same as the contents of “Java Library import

Definition of mime type

It is the same as the contents of “Definition of mime type”.

Generating the basic object for XPLATFORM (PlatformData)

It is the same as the contents of “Generating the Basic Object for XPLATFORM (PlatformData)”.

Receiving the Request from the Client

In “Service for the initial data generation– initdata.jsp”and “Query Service – search.jsp”, receiving the request from the client is not necessary because the applicable JSP Service doesn’t receive the parameter from the client separately. Or when the applicable JSP Service is called, the work that the client wants can be done.

But in this chapter, Dataset must be received from the client as a parameter. The code that received the requirements from the client is as follows:

/** 4. receive client request **/
// create HttpPlatformRequest for receive data from client
HttpPlatformRequest req = new HttpPlatformRequest(request);
req.receiveData();

Extracting Data to the Client’s Request and Saving at the File

In order to handle the information from the Client, the applicable information must be transformed to PlatformData. Extract Dataset from PlatformData. Here, get the required information from the extracted Dataset. It is used to get the number of the saved Row and its example is shown at the next chapter. 
Save the generated PlatformData at the file of “./saveFile.bin”.

The codes that extract PlatformData from the Client’s Request and save at the file are as follows:

/** 5. handle data : load data from file **/
/** 5.1 load data from http object **/ 
pdata = req.getData();

/** get Dataset from received data **/
DataSet ds = pdata.getDataSet("dsPerson");

/** save data to file with init data **/
String targetFilename = "./saveFile.bin";
OutputStream target = new FileOutputStream(targetFilename);
PlatformResponse res = new PlatformResponse(target, 
PlatformType.CONTENT_TYPE_BINARY);
res.setData(pdata);
res.sendData();
target.close();

Handling of Errorcode and ErrorMsg

It is the same as the contents in “Handling ErrorCode and ErrorMsg”. Only the difference is in the part that contains the number of the card list saved at strErrorMsg in case of the success.

Sending the result value to the Client

It is the same as the contents in “Sending the result value to Client