Sample java REST API client class for Oracle EBS Concurrent program
package oracle.apps.fnd.cp.request;
import java.io.File;
import
java.io.FileInputStream;
import
java.io.FileOutputStream;
import
java.io.FileWriter;
import
java.io.IOException;
import
java.io.PrintWriter;
import
java.io.StringWriter;
import
java.security.NoSuchProviderException;
import
java.sql.Connection;
import
java.sql.PreparedStatement;
import
java.sql.ResultSet;
import
java.sql.SQLException;
import
java.text.SimpleDateFormat;
import java.util.Date;
import
oracle.apps.fnd.util.ParameterList;
import
oracle.jdbc.OracleCallableStatement;
public class JavaConcRestAPIClient implements
JavaConcurrentProgram {
String pDate;
public JavaConcRestAPIClient() {
}
public void runProgram(CpContext pCpContext) {
// get the JDBC connection object
Connection mJConn = pCpContext.getJDBCConnection();
// get parameter list object from CpContext
ParameterList lPara = pCpContext.getParameterList();
// get ReqCompletion object from CpContext
ReqCompletion lRC = pCpContext.getReqCompletion();
// get OutFile object from CpContext
OutFile lOF = pCpContext.getOutFile();
// get LogFile object from CpContext
LogFile lLF = pCpContext.getLogFile();
// value and use it as the application short name in the
query
while (lPara.hasMoreElements()) {
NameValueType aNVT = lPara.nextParameter();
if
(aNVT.getName().equals("pdate"))
pDate = aNVT.getValue();
}
lOF.writeln("+--------------------------------------+");
lOF.writeln("My Concurrent Program REST API Client");
lOF.writeln("+---------------------------------------+");
lOF.writeln("");
try {
lOF.writeln("+---------------------------------------+");
lOF.writeln("Calling API ");
lOF.writeln("+----------------------------------------+");
lOF.writeln("");
try {
URL url;
url = new
URL("http://dummy.restapiexample.com/api/v1/employees");
lOF.writeln("URL : " + url);
HttpURLConnection con;
con = (HttpURLConnection)
url.openConnection();
con.setRequestMethod("GET");
int status = con.getResponseCode();
BufferedReader in = new
BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while((inputLine = in.readLine()) !=
null) {
content.append(inputLine);
System.out.println(inputLine);
}
in.close();
con.disconnect();
System.out.println("Response
status: " + status);
System.out.println(content.toString());
lOF.writeln("Content : " +
content.toString());
lOF.writeln("");
lOF.writeln("+--------------------------------------+");
lOF.writeln("My Concurrent Program REST
API Complete");
lOF.writeln("+--------------------------------------+");
lRC.setCompletion(ReqCompletion.NORMAL,
"Request
Completed Normal");
} catch (ProtocolException e) {
lOF.writeln("Please check the log
for error details)");
lRC.setCompletion(ReqCompletion.ERROR,
e.toString());
} catch (IOException e) {
lOF.writeln("Please check the log
for error details)");
lRC.setCompletion(ReqCompletion.ERROR,
e.toString());
} /*catch (MalformedURLException e) {
lOF.writeln("Please check the log
for error details)");
lRC.setCompletion(ReqCompletion.ERROR,
e.toString());
}*/
finally {
pCpContext.releaseJDBCConnection();
}
}
}
0 Comments