Tags

, , ,

Today I ‘ll will explain how to develop JAVA Concurrent Program on JDeveloper and I’ll show you to make an simple program, you can check it out on your local PC.

JAVA Concurrent Program

Requirements:

1- JDeveloper I will prefer to develop JAVA Concurrent on JDeveloper 10.1.3.3.0

libraries

2- SSH Tools such as Putty , FillaZilla …

You may decide to dump that into $JAVA_TOP/xxpc/oracle/apps/xxpc/sftp

You need to connect the application server that’s why to add your classes where you decided the path. Path should be like xxpc.oracle.apps.xxpc.(your_folder_name).

3- Linux know-how to built-in SHELL SCRİPT

To need some shell Scripts I will show how to write it, how to get return code on JAVA.

I’ll show how to execute on Java to Sh?

4- To need Two Application Server for Secure Data Transfer

What’s my purpose to sample Project?

I will improve Secure File Transfer(SFTP) on application server to another one. This process will start from JAVA Concurrent on Oracle E-Business Suite

Lets check it the Sample SFTP Project

Architecture on the picture

Architect

Below this method provides how to Connect the Database with JAVA Concurrent

Main Class

public class SftpReadFromLocal implements JavaConcurrentProgram {

//write your (ALL LOGIC) methods

//below method to bridge with your Concurrent Prog.

public void runProgram(CpContext cpcontext) {
_cpcontext = cpcontext;
_cpcontext.getRespId();
_cpcontext.getReqDetails().getRequestId();

System.out.println(“***********General Information********”);
ShowSystemInformation();
System.getProperty(“line.separator”);
System.out.println(“Request Id : ” +
_cpcontext.getReqDetails().getRequestId());
try {
System.out.println(“DB User Name : ” +
getConnection().getMetaData().getUserName());
} catch (SQLException e) {
System.out.println(“DB User Name didin’t find”);
// TODO
}
try {
System.out.println(“URL : ” +
getConnection().getMetaData().getURL());
} catch (SQLException e) {
// TODO
}
System.out.println(“***********End of the General Information********”);
put();
cpcontext.getReqCompletion().setCompletion(COMPLETE_STATUS,
COMPLETE_MESSAGE);
cpcontext.releaseJDBCConnection();
}
}
Connection Method:
protected Connection getConnection() {
Connection conn = null;
try {
conn = _cpcontext.getJDBCConnection();
} catch (Exception e) {;
}
return conn;
}

Following this Connection you get to have all information such as;

public void ShowSystemInformation() {
System.out.println(“The current working directory when the properties were initialized :” +
System.getProperty(“user.dir”));
System.out.println(“The home directory of the current user :” +
System.getProperty(“user.home”));
System.out.println(“The username of the current user :” +
System.getProperty(“user.name”));
System.out.println(“The default time zone :” +
System.getProperty(“user.timezone”));
System.out.println(“EBS Application Server User Name Information: ” +
System.getProperty(“user.name”));
}

NOTE :
If you need to take an parameter You should just write in your method,

ParameterList lPara = _cpcontext.getParameterList();
String L_invoice_num = lPara.nextParameter().getValue();
SQL_FILE = SQL_FILE.replace(“XXXXX”, L_invoice_num);

If you are new in JAVA to learn usage ArrayList Its very useful

private ArrayList<Param> param_list = new ArrayList<Param>();

class Param {
public String REQUEST_ID;
public String FILE_NAME;
public String INVOICEDATE;
public String HOST_NAME;
public String PORT;
public String FTP_USER;
public String USER_PASSWORD;
public String REMOTE_FOLDER;
public String LOCAL_FOLDER;
}

Check the below code It show you how to add ARRAYLIST then you can use this list every method. It’s simple and vital.

public void selectRecordsFromTable() throws SQLException{

COMPLETE_STATUS = 0; //0-1-2 Three Option 0 non-color,1 yellow 2 Red
COMPLETE_MESSAGE = “”;
Connection con = getConnection();
PreparedStatement preparedStatement = null;
String selectSQL = SQL_FILE;
try {
con = getConnection();
preparedStatement = con.prepareStatement(selectSQL);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
Param param = new Param();
param.REQUEST_ID = rs.getString(1);
param.FILE_NAME = rs.getString(2);
param.INVOICEDATE = rs.getString(3);
// System.out.println(“REQUEST_ID : ” + param.REQUEST_ID);
System.out.println(“FILE_NAME : ” + param.FILE_NAME);
// System.out.println(“INVOICEDATE : ” + param.INVOICEDATE);
System.out.println(“—“);
param_list.add(param);
}

System.out.println(“**************************”);
preparedStatement = con.prepareStatement(SQL_FILE_DIRECTORY);
ResultSet rs2 = preparedStatement.executeQuery();
while (rs2.next()) {
Param param = new Param();
param.HOST_NAME = rs2.getString(1);
param.FTP_USER = rs2.getString(2);
param.USER_PASSWORD = rs2.getString(3);
param.PORT = rs2.getString(4);
param.LOCAL_FOLDER = rs2.getString(5);
param.REMOTE_FOLDER = rs2.getString(6);
System.out.println(“—“);
param_listPath.add(param);
//execShellScript(); // ShellScript should be executed!
erpParameters();

readTextFromBackup();
}
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
if (preparedStatement != null) {
preparedStatement.close();
}
if (con != null) {
con.close();
}
}
;
}

How to execute Shell Script on JAVA

protected int DMZ_exitVal(String a, String b, String c,
String d) throws InterruptedException {
Process p = null;
FileInputStream fis = null;
BufferedReader inStream = null;
try {
p =
Runtime.getRuntime().exec(“sh ” + d + “/shell_script_parametreli.sh ” + a +
“@” + b + ” ” + c);
System.getProperty(“user.name”);
} catch (IOException e) {
e.printStackTrace();
// TODO
}
int exitVal = p.waitFor();
System.out.println(“Sftp transfered value : (exitVal=” +
exitVal + “) ==>proof”);
if (startProcessList.size()!=0 && exitVal == 0) {
try {
System.out.println(“Sftp Succees, Check it out BACKUP_DMZ folder. (exitVal=” +
exitVal + “) ==>proof”);
Runtime.getRuntime().exec(“sh ” + d +
“/scripts/sentbackup.sh”);
} catch (IOException e) {
;
}
}
return exitVal;
}

Let Check how to write Shell Script and how to get returnCode

#!/bin/sh
URL=$1
DIR=$2
OUT=$?

TITLE=”System Information for $HOSTNAME”
RIGHT_NOW=$(date +”%x %r %Z”)
echo “OK, starting now…”
echo “user = $URL”
echo “Remote directory = $DIR”
sftp $URL $DIR <<EOF
pwd
cd $DIR
lcd /atalay/sentDMZ
mput *.txt
pwd
if [ $OUT -eq 0 ];
then
echo “sftp OK”
lcd /atalay/sentDMZ
pwd

…..

At the bottom example $OUT if it is 0 It means yes this process success ;othervise you will get another error code like 255,127 …